Module: Garage::Representer::ClassMethods
- Defined in:
- lib/garage/representer.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
- #accessible(*args) ⇒ Object
- #collection(name, options = {}) ⇒ Object
- #inherited(child) ⇒ Object
- #link(rel, options = {}, &block) ⇒ Object
-
#metadata ⇒ Object
represents the representer’s schema in JSON format.
- #oauth_scope(scope) ⇒ Object
- #param(*keys) ⇒ Object
- #params ⇒ Object
- #property(name, options = {}) ⇒ Object
Instance Attribute Details
#representer_attrs ⇒ Object
84 85 86 |
# File 'lib/garage/representer.rb', line 84 def representer_attrs @representer_attrs ||= [] end |
Instance Method Details
#accessible(*args) ⇒ Object
108 109 110 111 112 |
# File 'lib/garage/representer.rb', line 108 def accessible(*args) ->(resource, responder){ responder.controller.allow_access?(*args) } end |
#collection(name, options = {}) ⇒ Object
96 97 98 |
# File 'lib/garage/representer.rb', line 96 def collection(name, ={}) representer_attrs << Collection.new(name, ) end |
#inherited(child) ⇒ Object
79 80 81 82 |
# File 'lib/garage/representer.rb', line 79 def inherited(child) super child.representer_attrs = self.representer_attrs.clone end |
#link(rel, options = {}, &block) ⇒ Object
92 93 94 |
# File 'lib/garage/representer.rb', line 92 def link(rel, ={}, &block) representer_attrs << Link.new(rel, , block) end |
#metadata ⇒ Object
represents the representer’s schema in JSON format
115 116 117 118 119 |
# File 'lib/garage/representer.rb', line 115 def {:definitions => representer_attrs.grep(Definition).map {|definition| definition.name}, :links => representer_attrs.grep(Link).map {|link| link.[:as] ? {link.rel => {'as' => link.[:as]}} : link.rel} } end |
#oauth_scope(scope) ⇒ Object
100 101 102 103 104 105 106 |
# 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) ⇒ Object
121 122 123 |
# File 'lib/garage/representer.rb', line 121 def param(*keys) keys.each {|key| params << key } end |
#params ⇒ Object
125 126 127 |
# File 'lib/garage/representer.rb', line 125 def params @params ||= [] end |
#property(name, options = {}) ⇒ Object
88 89 90 |
# File 'lib/garage/representer.rb', line 88 def property(name, ={}) representer_attrs << Definition.new(name, ) end |