Class: FlattenRecord::Meta::Node
- Inherits:
-
Object
- Object
- FlattenRecord::Meta::Node
- Defined in:
- lib/flatten_record/meta/node.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#target_model ⇒ Object
readonly
Returns the value of attribute target_model.
Instance Method Summary collapse
-
#initialize(parent, target_model, model) ⇒ Node
constructor
A new instance of Node.
- #prefix ⇒ Object
- #traverse_by(attr, value) ⇒ Object
Constructor Details
#initialize(parent, target_model, model) ⇒ Node
Returns a new instance of Node.
6 7 8 9 10 11 |
# File 'lib/flatten_record/meta/node.rb', line 6 def initialize(parent, target_model, model) @parent = parent @target_model = target_model.is_a?(ActiveRecord::Base) ? target_model : target_model.to_s.camelize.constantize @model = model end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
4 5 6 |
# File 'lib/flatten_record/meta/node.rb', line 4 def children @children end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
4 5 6 |
# File 'lib/flatten_record/meta/node.rb', line 4 def model @model end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
4 5 6 |
# File 'lib/flatten_record/meta/node.rb', line 4 def parent @parent end |
#target_model ⇒ Object (readonly)
Returns the value of attribute target_model.
4 5 6 |
# File 'lib/flatten_record/meta/node.rb', line 4 def target_model @target_model end |
Instance Method Details
#prefix ⇒ Object
27 28 29 30 31 32 |
# File 'lib/flatten_record/meta/node.rb', line 27 def prefix return @custom_prefix unless @custom_prefix.nil? return "" if is_parent_root? "#{target_model_name}_" end |
#traverse_by(attr, value) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/flatten_record/meta/node.rb', line 13 def traverse_by(attr, value) attr_value = instance_variable_get("@#{attr}") if !value.respond_to?(:to_s) || !attr_value.respond_to?(:to_s) raise "traverse error: to_s method required for comparison" end if value.to_s == attr_value.to_s return self else return nil end end |