Class: Onoma::Reflection
- Inherits:
-
Object
- Object
- Onoma::Reflection
- Defined in:
- lib/onoma/reflection.rb
Instance Attribute Summary collapse
-
#active_record ⇒ Object
(also: #model)
readonly
Returns the value of attribute active_record.
-
#class_name ⇒ Object
readonly
Returns the value of attribute class_name.
-
#foreign_key ⇒ Object
readonly
Returns the value of attribute foreign_key.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#nomenclature ⇒ Object
readonly
Returns the value of attribute nomenclature.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Instance Method Summary collapse
-
#==(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.
- #all(*args) ⇒ Object
-
#initialize(active_record, name, options = {}) ⇒ Reflection
constructor
name: things class_name: Thing klass: Onoma::Thing.
- #macro ⇒ Object
Constructor Details
#initialize(active_record, name, options = {}) ⇒ Reflection
name: things class_name: Thing klass: Onoma::Thing
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/onoma/reflection.rb', line 8 def initialize(active_record, name, = {}) @options = @name = name.to_s @active_record = active_record @class_name = [:class_name] || name.to_s.classify @foreign_key = ([:foreign_key] || name).to_s @scope = [:scope] @nomenclature = class_name.tableize @klass = "Onoma::#{@class_name}".constantize end |
Instance Attribute Details
#active_record ⇒ Object (readonly) Also known as: model
Returns the value of attribute active_record.
3 4 5 |
# File 'lib/onoma/reflection.rb', line 3 def active_record @active_record end |
#class_name ⇒ Object (readonly)
Returns the value of attribute class_name.
3 4 5 |
# File 'lib/onoma/reflection.rb', line 3 def class_name @class_name end |
#foreign_key ⇒ Object (readonly)
Returns the value of attribute foreign_key.
3 4 5 |
# File 'lib/onoma/reflection.rb', line 3 def foreign_key @foreign_key end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
3 4 5 |
# File 'lib/onoma/reflection.rb', line 3 def klass @klass end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/onoma/reflection.rb', line 3 def name @name end |
#nomenclature ⇒ Object (readonly)
Returns the value of attribute nomenclature.
3 4 5 |
# File 'lib/onoma/reflection.rb', line 3 def nomenclature @nomenclature end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/onoma/reflection.rb', line 3 def @options end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
3 4 5 |
# File 'lib/onoma/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/onoma/reflection.rb', line 28 def ==(other_aggregation) other_aggregation.is_a?(self.class) && name == other_aggregation.name && !other_aggregation..nil? && active_record == other_aggregation.active_record end |
#all(*args) ⇒ Object
35 36 37 |
# File 'lib/onoma/reflection.rb', line 35 def all(*args) @klass ? @klass.all(*args) : [] end |
#macro ⇒ Object
21 22 23 |
# File 'lib/onoma/reflection.rb', line 21 def macro :belongs_to end |