Class: Nomen::Reflection

Inherits:
Object
  • Object
show all
Defined in:
lib/nomen/reflection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(active_record, name, options = {}) ⇒ Reflection

name: things class_name: Thing klass: Nomen::Thing


8
9
10
11
12
13
14
15
16
17
# File 'lib/nomen/reflection.rb', line 8

def initialize(active_record, name, options = {})
  @options = options
  @name = name.to_s
  @active_record = active_record
  @class_name = options[:class_name] || name.to_s.classify
  @foreign_key = (options[:foreign_key] || name).to_s
  @scope = options[:scope]
  @nomenclature = class_name.tableize
  @klass = "Nomen::#{@class_name}".constantize
end

Instance Attribute Details

#active_recordObject (readonly) Also known as: model

Returns the value of attribute active_record


3
4
5
# File 'lib/nomen/reflection.rb', line 3

def active_record
  @active_record
end

#class_nameObject (readonly)

Returns the value of attribute class_name


3
4
5
# File 'lib/nomen/reflection.rb', line 3

def class_name
  @class_name
end

#foreign_keyObject (readonly)

Returns the value of attribute foreign_key


3
4
5
# File 'lib/nomen/reflection.rb', line 3

def foreign_key
  @foreign_key
end

#klassObject (readonly)

Returns the value of attribute klass


3
4
5
# File 'lib/nomen/reflection.rb', line 3

def klass
  @klass
end

#nameObject (readonly)

Returns the value of attribute name


3
4
5
# File 'lib/nomen/reflection.rb', line 3

def name
  @name
end

#nomenclatureObject (readonly)

Returns the value of attribute nomenclature


3
4
5
# File 'lib/nomen/reflection.rb', line 3

def nomenclature
  @nomenclature
end

#optionsObject (readonly)

Returns the value of attribute options


3
4
5
# File 'lib/nomen/reflection.rb', line 3

def options
  @options
end

#scopeObject (readonly)

Returns the value of attribute scope


3
4
5
# File 'lib/nomen/reflection.rb', line 3

def scope
  @scope
end

Instance Method Details

#==(other_aggregation) ⇒ Object

Returns true if self and other_aggregation have the same name attribute, active_record attribute, and other_aggregation has an options hash assigned to it.


28
29
30
31
32
33
# File 'lib/nomen/reflection.rb', line 28

def ==(other_aggregation)
  other_aggregation.is_a?(self.class) &&
    name == other_aggregation.name &&
    !other_aggregation.options.nil? &&
    active_record == other_aggregation.active_record
end

#all(*args) ⇒ Object


35
36
37
# File 'lib/nomen/reflection.rb', line 35

def all(*args)
  @klass ? @klass.all(*args) : []
end

#macroObject


21
22
23
# File 'lib/nomen/reflection.rb', line 21

def macro
  :belongs_to
end