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

Instance Method Details



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(options = {})
  root = options.fetch(:root, true)

  {}.tap do |resource|
    resource_keys(options).inject(resource) do |buffer, key|
      buffer.merge!(key.to_resource(self))
    end

    if (links = build_links).any? && !options[: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(options)
  summarize?(options) ? self.class.summarized_keys + [Href.new] : self.class.keys
end

#summarize?(options) ⇒ Boolean

Returns:



27
28
29
# File 'lib/rest_model/response.rb', line 27

def summarize?(options)
  options[:summarize] and self.class.summarized_keys.any?
end