Method: ActiveModel::Serializer#initialize

Defined in:
lib/active_model/serializer.rb

#initialize(object, options = {}) ⇒ Serializer

scope_name is set as :current_user by default in the controller. If the instance does not have a method named scope_name, it defines the method so that it calls the scope.



119
120
121
122
123
124
125
126
127
128
# File 'lib/active_model/serializer.rb', line 119

def initialize(object, options = {})
  self.object = object
  self.instance_options = options
  self.root = instance_options[:root]
  self.scope = instance_options[:scope]

  return if !(scope_name = instance_options[:scope_name]) || respond_to?(scope_name)

  define_singleton_method scope_name, -> { scope }
end