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 |
# File 'lib/flatten_record/meta/node.rb', line 6 def initialize(parent, target_model, model) @parent = parent @target_model = target_model.to_s.underscore @model = model.to_s.underscore 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
34 35 36 37 38 39 |
# File 'lib/flatten_record/meta/node.rb', line 34 def prefix return custom_prefix unless custom_prefix.nil? return "" if is_parent_root? "#{target_model_name}_" end |
#traverse_by(attr, value) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/flatten_record/meta/node.rb', line 20 def traverse_by(attr, value) attr_value = send("#{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.downcase == attr_value.to_s.downcase return self else return nil end end |