Module: RestModel::Response
- Extended by:
- ActiveSupport::Concern
- Included in:
- RestModel, Embeddable, Property
- Defined in:
- lib/rest_model/response.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #build_links ⇒ Object
- #resource(options = {}) ⇒ Object
- #resource_keys(options) ⇒ Object
- #summarize?(options) ⇒ Boolean
Instance Method Details
#build_links ⇒ Object
20 21 22 |
# File 'lib/rest_model/response.rb', line 20 def build_links self.class.relations.map {|key| key.to_relation(self)}.reject(&:nil?) end |
#resource(options = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/rest_model/response.rb', line 5 def resource( = {}) root = .fetch(:root, true) {}.tap do |resource| resource_keys().inject(resource) do |buffer, key| buffer.merge!(key.to_resource(self)) end if root and self.class.relations.any? and ![:summarize] links = build_links resource.merge!({link: links}) if links.any? end end end |
#resource_keys(options) ⇒ Object
24 25 26 |
# File 'lib/rest_model/response.rb', line 24 def resource_keys() summarize?() ? self.class.summarized_keys + [Href.new] : self.class.keys end |
#summarize?(options) ⇒ Boolean
28 29 30 |
# File 'lib/rest_model/response.rb', line 28 def summarize?() [:summarize] and self.class.summarized_keys.any? end |