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
19 20 21 |
# File 'lib/rest_model/response.rb', line 19 def build_links self.class.relations.map {|key| key.to_relation(self)}.compact end |
#resource(options = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# 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 (links = build_links).any? && ![:summarize] resource.merge!(link: links) end end end |
#resource_keys(options) ⇒ Object
23 24 25 |
# File 'lib/rest_model/response.rb', line 23 def resource_keys() summarize?() ? self.class.summarized_keys + [Href.new] : self.class.keys end |
#summarize?(options) ⇒ Boolean
27 28 29 |
# File 'lib/rest_model/response.rb', line 27 def summarize?() [:summarize] and self.class.summarized_keys.any? end |