Class: BasicAssumption::DefaultAssumption::OwnerAttributes

Inherits:
Object
  • Object
show all
Defined in:
lib/basic_assumption/default_assumption/owner_attributes.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner_method_or_context, controller) ⇒ OwnerAttributes

Returns a new instance of OwnerAttributes.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/basic_assumption/default_assumption/owner_attributes.rb', line 6

def initialize(owner_method_or_context, controller)
  @controller = controller

  if owner_method_or_context.kind_of? Hash
    @owner_method  = owner_method_or_context[:object]
    @owner_context = owner_method_or_context
  else
    @owner_method  = owner_method_or_context
    @owner_context = {}
  end
end

Instance Attribute Details

#controllerObject (readonly)

Returns the value of attribute controller.



4
5
6
# File 'lib/basic_assumption/default_assumption/owner_attributes.rb', line 4

def controller
  @controller
end

#owner_contextObject (readonly)

Returns the value of attribute owner_context.



4
5
6
# File 'lib/basic_assumption/default_assumption/owner_attributes.rb', line 4

def owner_context
  @owner_context
end

#owner_methodObject (readonly)

Returns the value of attribute owner_method.



4
5
6
# File 'lib/basic_assumption/default_assumption/owner_attributes.rb', line 4

def owner_method
  @owner_method
end

Instance Method Details

#attributesObject



18
19
20
# File 'lib/basic_assumption/default_assumption/owner_attributes.rb', line 18

def attributes
  {column_name => owner_object.id}
end

#column_nameObject



30
31
32
# File 'lib/basic_assumption/default_assumption/owner_attributes.rb', line 30

def column_name
  owner_context[:column_name] || :"#{owner_object.class.name.downcase}_id"
end

#owner_objectObject



22
23
24
25
26
27
28
# File 'lib/basic_assumption/default_assumption/owner_attributes.rb', line 22

def owner_object
  if owner_method.respond_to? :call
    controller.instance_eval(&owner_method)
  else
    controller.send(owner_method)
  end
end