Class: ActionTracker::CollectionProxy

Inherits:
Object
  • Object
show all
Includes:
Pagination, Enumerable
Defined in:
lib/action_tracker/utils/collection_proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Pagination

#first_page?, #last_page?, #per_page, #size

Constructor Details

#initialize(response, model_name) ⇒ CollectionProxy

Returns a new instance of CollectionProxy.



10
11
12
13
# File 'lib/action_tracker/utils/collection_proxy.rb', line 10

def initialize(response, model_name)
  @response = response
  @model_name = model_name
end

Instance Attribute Details

#model_nameObject (readonly)

Returns the value of attribute model_name.



8
9
10
# File 'lib/action_tracker/utils/collection_proxy.rb', line 8

def model_name
  @model_name
end

Instance Method Details

#codeObject



15
16
17
# File 'lib/action_tracker/utils/collection_proxy.rb', line 15

def code
  @response.code
end

#eachObject



19
20
21
22
23
# File 'lib/action_tracker/utils/collection_proxy.rb', line 19

def each
  raw_data.each do |record|
    yield record_klass.new(record)
  end
end

#entry_name(options = {}) ⇒ Object



29
30
31
# File 'lib/action_tracker/utils/collection_proxy.rb', line 29

def entry_name(options = {})
  model_name.singular.pluralize(options[:count])
end

#raw_dataObject



25
26
27
# File 'lib/action_tracker/utils/collection_proxy.rb', line 25

def raw_data
  @response.dig(model_name.plural) || @response.dig('data')
end