Class: EvilSeed::Configuration::Root

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

Overview

Configuration for dumping some root model and its associations

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, dont_nullify, *constraints) ⇒ Root

Returns a new instance of Root.

Parameters:

  • model (String)

    Name of the model class to dump

  • constraints (String, Hash)

    Everything you can feed into where to limit number of records



13
14
15
16
17
18
19
20
21
# File 'lib/evil_seed/configuration/root.rb', line 13

def initialize(model, dont_nullify, *constraints)
  @model = model
  @constraints = constraints
  @exclusions = []
  @inclusions = []
  @association_limits = {}
  @deep_limit = nil
  @dont_nullify = dont_nullify
end

Instance Attribute Details

#association_limitsObject (readonly)

Returns the value of attribute association_limits.



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

def association_limits
  @association_limits
end

#constraintsObject (readonly)

Returns the value of attribute constraints.



7
8
9
# File 'lib/evil_seed/configuration/root.rb', line 7

def constraints
  @constraints
end

#deep_limitObject (readonly)

Returns the value of attribute deep_limit.



8
9
10
# File 'lib/evil_seed/configuration/root.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/configuration/root.rb', line 8

def dont_nullify
  @dont_nullify
end

#exclusionsObject (readonly)

Returns the value of attribute exclusions.



9
10
11
# File 'lib/evil_seed/configuration/root.rb', line 9

def exclusions
  @exclusions
end

#inclusionsObject (readonly)

Returns the value of attribute inclusions.



9
10
11
# File 'lib/evil_seed/configuration/root.rb', line 9

def inclusions
  @inclusions
end

#modelObject (readonly)

Returns the value of attribute model.



7
8
9
# File 'lib/evil_seed/configuration/root.rb', line 7

def model
  @model
end

#total_limitObject (readonly)

Returns the value of attribute total_limit.



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

def total_limit
  @total_limit
end

Instance Method Details

#do_not_nullify(nullify_flag) ⇒ Object



52
53
54
# File 'lib/evil_seed/configuration/root.rb', line 52

def do_not_nullify(nullify_flag)
  @dont_nullify = nullify_flag
end

#exclude(*association_patterns) ⇒ Object

Exclude some of associations from the dump

Parameters:

  • association_patterns

    Array<String, Regex> Patterns to exclude associated models from dump



25
26
27
# File 'lib/evil_seed/configuration/root.rb', line 25

def exclude(*association_patterns)
  @exclusions += association_patterns
end

#excluded?(association_path) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/evil_seed/configuration/root.rb', line 56

def excluded?(association_path)
  exclusions.any? { |exclusion| association_path.match(exclusion) } #.match(association_path) }
end

#include(*association_patterns) ⇒ Object

Include some excluded associations back to the dump

Parameters:

  • association_patterns

    Array<String, Regex> Patterns to exclude associated models from dump



31
32
33
# File 'lib/evil_seed/configuration/root.rb', line 31

def include(*association_patterns)
  @inclusions += association_patterns
end

#included?(association_path) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/evil_seed/configuration/root.rb', line 60

def included?(association_path)
  inclusions.any? { |inclusion| association_path.match(inclusion) } #.match(association_path) }
end

#limit_associations_size(limit, association_pattern = nil) ⇒ Object

Limit number of records in all (if pattern is not provided) or given associations to include into dump

Parameters:

  • limit (Integer)

    Maximum number of records in associations to include into dump

  • association_pattern (String, Regex) (defaults to: nil)

    Pattern to limit number of records for certain associated models



38
39
40
41
42
43
44
# File 'lib/evil_seed/configuration/root.rb', line 38

def limit_associations_size(limit, association_pattern = nil)
  if association_pattern
    @association_limits[association_pattern] = limit
  else
    @total_limit = limit
  end
end

#limit_deep(limit) ⇒ Object

Limit deepenes of associations to include into dump

Parameters:

  • limit (Integer)

    Maximum level to recursively dive into associations



48
49
50
# File 'lib/evil_seed/configuration/root.rb', line 48

def limit_deep(limit)
  @deep_limit = limit
end