Class: EvilSeed::RootDumper

Inherits:
Object
  • Object
show all
Defined in:
lib/evil_seed/root_dumper.rb

Overview

This module collects dumps generation for root and all it’s dependencies

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root, dumper) ⇒ RootDumper

Returns a new instance of RootDumper.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/evil_seed/root_dumper.rb', line 12

def initialize(root, dumper)
  @root   = root
  @dumper = dumper
  @to_load_map = {}
  @total_limit = root.total_limit
  @deep_limit = root.deep_limit
  @dont_nullify = root.dont_nullify
  @association_limits = root.association_limits.dup

  @model_class = root.model.constantize
end

Instance Attribute Details

#association_limitsObject (readonly)

Returns the value of attribute association_limits.



8
9
10
# File 'lib/evil_seed/root_dumper.rb', line 8

def association_limits
  @association_limits
end

#deep_limitObject (readonly)

Returns the value of attribute deep_limit.



8
9
10
# File 'lib/evil_seed/root_dumper.rb', line 8

def deep_limit
  @deep_limit
end

#dont_nullifyObject (readonly)

Returns the value of attribute dont_nullify.



8
9
10
# File 'lib/evil_seed/root_dumper.rb', line 8

def dont_nullify
  @dont_nullify
end

#dumperObject (readonly)

Returns the value of attribute dumper.



8
9
10
# File 'lib/evil_seed/root_dumper.rb', line 8

def dumper
  @dumper
end

#model_classObject (readonly)

Returns the value of attribute model_class.



8
9
10
# File 'lib/evil_seed/root_dumper.rb', line 8

def model_class
  @model_class
end

#rootObject (readonly)

Returns the value of attribute root.



8
9
10
# File 'lib/evil_seed/root_dumper.rb', line 8

def root
  @root
end

#total_limitObject (readonly)

Returns the value of attribute total_limit.



8
9
10
# File 'lib/evil_seed/root_dumper.rb', line 8

def total_limit
  @total_limit
end

Instance Method Details

#callObject

Generate dump and write it into io

Parameters:

  • output (IO)

    Stream to write SQL dump into



26
27
28
29
30
31
32
# File 'lib/evil_seed/root_dumper.rb', line 26

def call
  association_path = model_class.model_name.singular
  relation = model_class.all
  relation = relation.unscoped if configuration.unscoped
  relation = relation.where(*root.constraints) if root.constraints.any? # without arguments returns not a relation
  RelationDumper.new(relation, self, association_path).call
end

#check_limits!(association_path) ⇒ Boolean

Returns true if limits are NOT reached and false otherwise.

Returns:

  • (Boolean)

    true if limits are NOT reached and false otherwise



35
36
37
# File 'lib/evil_seed/root_dumper.rb', line 35

def check_limits!(association_path)
  check_total_limit! && check_association_limits!(association_path)
end