class FlattenRecord::Meta::Node
Attributes
children[R]
model[R]
parent[R]
target_model[R]
Public Class Methods
new(parent, target_model, model)
click to toggle source
# 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
Public Instance Methods
prefix()
click to toggle source
# 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)
click to toggle source
# 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
Protected Instance Methods
_key()
click to toggle source
# File lib/flatten_record/meta/node.rb, line 56 def _key @_key end
build(definition)
click to toggle source
# File lib/flatten_record/meta/node.rb, line 42 def build(definition) definition.validates_with(target_model, model) @_key = definition[:_key] @custom_prefix = definition[:definition][:prefix] @custom_prefix = @custom_prefix.to_s unless @custom_prefix.nil? raise definition.error_message unless definition.valid? self end
custom_prefix()
click to toggle source
# File lib/flatten_record/meta/node.rb, line 52 def custom_prefix @custom_prefix end
inspect()
click to toggle source
# File lib/flatten_record/meta/node.rb, line 69 def inspect # this prevents irb/console to inspect # circular references on big tree caused problem on #inspect end
target_columns()
click to toggle source
# File lib/flatten_record/meta/node.rb, line 65 def target_columns target_model.columns end
target_model_name()
click to toggle source
target helpers
# File lib/flatten_record/meta/node.rb, line 61 def target_model_name @target_model end
Private Instance Methods
is_parent_root?()
click to toggle source
# File lib/flatten_record/meta/node.rb, line 75 def is_parent_root? parent.present? && parent.instance_of?(RootNode) end