module Garage::Representer::ClassMethods
Attributes
representer_attrs[W]
Public Instance Methods
accessible(*args)
click to toggle source
# File lib/garage/representer.rb, line 108 def accessible(*args) ->(resource, responder){ responder.controller.allow_access?(*args) } end
collection(name, options={})
click to toggle source
# File lib/garage/representer.rb, line 96 def collection(name, options={}) representer_attrs << Collection.new(name, options) end
inherited(child)
click to toggle source
Calls superclass method
# File lib/garage/representer.rb, line 79 def inherited(child) super child.representer_attrs = self.representer_attrs.clone end
link(rel, options={}, &block)
click to toggle source
# File lib/garage/representer.rb, line 92 def link(rel, options={}, &block) representer_attrs << Link.new(rel, options, block) end
metadata()
click to toggle source
represents the representer's schema in JSON format
# File lib/garage/representer.rb, line 115 def metadata {:definitions => representer_attrs.grep(Definition).map {|definition| definition.name}, :links => representer_attrs.grep(Link).map {|link| link.options[:as] ? {link.rel => {'as' => link.options[:as]}} : link.rel} } end
oauth_scope(scope)
click to toggle source
# File lib/garage/representer.rb, line 100 def oauth_scope(scope) ->(resource, responder){ # FIXME: this only works with User resource for now # partial representation will not render request scope-specific fields for better caching !resource.partial? && responder.controller.requested_by?(resource) && responder.controller.has_scope?(scope) } end
param(*keys)
click to toggle source
# File lib/garage/representer.rb, line 121 def param(*keys) keys.each {|key| params << key } end
params()
click to toggle source
# File lib/garage/representer.rb, line 125 def params @params ||= [] end
property(name, options={})
click to toggle source
# File lib/garage/representer.rb, line 88 def property(name, options={}) representer_attrs << Definition.new(name, options) end
representer_attrs()
click to toggle source
# File lib/garage/representer.rb, line 84 def representer_attrs @representer_attrs ||= [] end