Method: Fastaccess::Fastaccess.update_content

Defined in:
lib/fastaccess/fastaccess.rb

.update_content(obj, options = {}) ⇒ Object

manually update content in redis for a given object.

Parameters:

  • obj (Object)

    any Object, preferably a decendent of an actual Rails Model.

  • options (Hash) (defaults to: {})

    a simple hash

Options Hash (options):

  • :on (Symbol)

    a certain registered method.

  • :arguments (Array)

    an array of arguments passed to the :on method or, if :on is not present, every method registered with fastaccess on the pertaining class.



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/fastaccess/fastaccess.rb', line 151

def self.update_content(obj, options={})
  class_name = obj.is_a?(Class) ? obj : obj.class
  methods = if method = options[:on]
    if registered? class_name, method
      [method]
    else
      []
    end
  else
    fastaccess_on[class_name]
  end
  methods.each do |method|
    callable = obj.method( alias_for(method) )
    content = if options[:arguments]
                callable.call(*options[:arguments])
              else
                callable.call
              end
    self.set("#{method}_#{id_for(obj)}", content)
  end
end