Class: CSVStepImporter::Node
Direct Known Subclasses
Chunk, File, Model::DAO, Model::Importer, Model::Model, Model::Reflector, Row
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#env ⇒ Object
Returns the value of attribute env.
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
- #add_children(children, prepend: false) ⇒ Object
- #create_or_update ⇒ Object
-
#initialize(parent: nil, children: [], env: nil) ⇒ Node
constructor
A new instance of Node.
- #validate_children ⇒ Object
Methods inherited from Base
#assign_attributes, #inspect, #persisted?, #save, #save!, #to_s, #update
Constructor Details
#initialize(parent: nil, children: [], env: nil) ⇒ Node
Returns a new instance of Node.
15 16 17 18 19 20 21 |
# File 'lib/csv_step_importer/node.rb', line 15 def initialize(parent: nil, children: [], env: nil) super() self.env = env self.parent = parent self.children = children end |
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
5 6 7 |
# File 'lib/csv_step_importer/node.rb', line 5 def children @children end |
#env ⇒ Object
Returns the value of attribute env.
8 9 10 |
# File 'lib/csv_step_importer/node.rb', line 8 def env @env end |
#parent ⇒ Object
Returns the value of attribute parent.
6 7 8 |
# File 'lib/csv_step_importer/node.rb', line 6 def parent @parent end |
Instance Method Details
#add_children(children, prepend: false) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/csv_step_importer/node.rb', line 33 def add_children(children, prepend: false) children = Array(children) unless children.is_a?(Enumerable) children = children.collect do |child, sub_children| next child unless child.is_a?(Class) child.new parent: self, children: sub_children end.compact @children = prepend ? children + @children : @children + children end |
#create_or_update ⇒ Object
44 45 46 |
# File 'lib/csv_step_importer/node.rb', line 44 def create_or_update children.empty? || children.all?(&:save) end |
#validate_children ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/csv_step_importer/node.rb', line 48 def validate_children return unless errors.empty? children.each do |child| next if child.valid? child.errors.each do |key, | errors[key] << end end end |