Class: Humanoid::Associations::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/humanoid/associations/options.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Options

Create the new Options object, which provides convenience methods for accessing values out of an options Hash.



8
9
10
# File 'lib/humanoid/associations/options.rb', line 8

def initialize(attributes = {})
  @attributes = attributes
end

Instance Method Details

#extensionObject

Returns the extension if it exists, nil if not.



13
14
15
# File 'lib/humanoid/associations/options.rb', line 13

def extension
  @attributes[:extend]
end

#extension?Boolean

Returns true is the options have extensions.

Returns:



18
19
20
# File 'lib/humanoid/associations/options.rb', line 18

def extension?
  !extension.nil?
end

#foreign_keyObject

Return the foreign key based off the association name.



23
24
25
# File 'lib/humanoid/associations/options.rb', line 23

def foreign_key
  name.to_s.foreign_key
end

#inverse_ofObject

Returns the name of the inverse_of association



28
29
30
# File 'lib/humanoid/associations/options.rb', line 28

def inverse_of
  @attributes[:inverse_of]
end

#klassObject

Return a Class for the options. If a class_name was provided, then the constantized class_name will be returned. If not, a constant based on the association name will be returned.



35
36
37
38
# File 'lib/humanoid/associations/options.rb', line 35

def klass
  class_name = @attributes[:class_name]
  class_name ? class_name.constantize : name.to_s.classify.constantize
end

#nameObject

Returns the association name of the options.



41
42
43
# File 'lib/humanoid/associations/options.rb', line 41

def name
  @attributes[:name].to_s
end

#parent_keyObject

Returns the parent foreign key association name.



46
47
48
# File 'lib/humanoid/associations/options.rb', line 46

def parent_key
  @attributes[:parent_key]
end

#polymorphicObject

Returns whether or not this association is polymorphic.



51
52
53
# File 'lib/humanoid/associations/options.rb', line 51

def polymorphic
  @attributes[:polymorphic] == true
end