class ActionTracker::CollectionProxy

Attributes

model_name[R]

Public Class Methods

new(response, model_name) click to toggle source
# File lib/action_tracker/utils/collection_proxy.rb, line 10
def initialize(response, model_name)
  @response = response
  @model_name = model_name
end

Public Instance Methods

code() click to toggle source
# File lib/action_tracker/utils/collection_proxy.rb, line 15
def code
  @response.code
end
each() { |record_klass| ... } click to toggle source
# 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 = {}) click to toggle source
# File lib/action_tracker/utils/collection_proxy.rb, line 29
def entry_name(options = {})
  model_name.singular.pluralize(options[:count])
end
raw_data() click to toggle source
# File lib/action_tracker/utils/collection_proxy.rb, line 25
def raw_data
  @response.dig(model_name.plural) || @response.dig('data')
end

Private Instance Methods

meta() click to toggle source
# File lib/action_tracker/utils/collection_proxy.rb, line 35
def meta
  OpenStruct.new(@response.dig('meta'))
end
record_klass() click to toggle source
# File lib/action_tracker/utils/collection_proxy.rb, line 39
def record_klass
  model_name.instance_variable_get(:@klass)
end