Module: Transcriber::Resource::Response

Extended by:
ActiveSupport::Concern
Included in:
Transcriber::Resource, Embeddable, Property
Defined in:
lib/transcriber/resource/response.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details



20
21
22
# File 'lib/transcriber/resource/response.rb', line 20

def link
  self.class.relations.map {|key| key.to_relation(self)}
end

#resource(options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/transcriber/resource/response.rb', line 6

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 root and self.class.relations.any? and !options[:summarize]
      resource.merge!({link: link})
    end
  end
end

#resource_keys(options) ⇒ Object



24
25
26
27
# File 'lib/transcriber/resource/response.rb', line 24

def resource_keys(options)
  summarize?(options) ? self.class.summarized_keys + [Resource::Href.new]
                      : self.class.keys
end

#summarize?(options) ⇒ Boolean

Returns:



29
30
31
# File 'lib/transcriber/resource/response.rb', line 29

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