Class: ActiveCachedResource::Collection

Inherits:
ActiveResource::Collection show all
Defined in:
lib/active_cached_resource/collection.rb

Instance Attribute Summary

Attributes inherited from ActiveResource::Collection

#from, #path_params, #prefix_options, #query_params, #resource_class

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ActiveResource::Collection

#call, #each, #first_or_create, #first_or_initialize, #initialize, none, #parse_response, #requested?, #where

Constructor Details

This class inherits a constructor from ActiveResource::Collection

Class Method Details

.persisted_attribute(*args) ⇒ void

This method returns an undefined value.

This method dynamically creates accessor methods for the specified attributes and adds them to a list of virtual persisted attributes to keep track of attributes that should be persisted to cache.

Parameters:

  • args (Array<Symbol>)

    A list of attribute names to be persisted.



11
12
13
14
# File 'lib/active_cached_resource/collection.rb', line 11

def self.persisted_attribute(*args)
  attr_accessor(*args)
  self.virtual_persisted_attributes += args
end

Instance Method Details

#reloadObject

Reload the collection by re-fetching the resources from the API.



25
26
27
28
# File 'lib/active_cached_resource/collection.rb', line 25

def reload
  query_params[Constants::RELOAD_PARAM] = true
  super
end

#virtual_persistable_attributesObject



16
17
18
19
20
# File 'lib/active_cached_resource/collection.rb', line 16

def virtual_persistable_attributes
  self.class.virtual_persisted_attributes.each_with_object({}) do |attribute, hash|
    hash[attribute] = public_send(attribute)
  end
end