Class: EvilSeed::Configuration::Root
- Inherits:
-
Object
- Object
- EvilSeed::Configuration::Root
- Defined in:
- lib/evil_seed/configuration/root.rb
Overview
Configuration for dumping some root model and its associations
Instance Attribute Summary collapse
-
#association_limits ⇒ Object
readonly
Returns the value of attribute association_limits.
-
#constraints ⇒ Object
readonly
Returns the value of attribute constraints.
-
#deep_limit ⇒ Object
readonly
Returns the value of attribute deep_limit.
-
#dont_nullify ⇒ Object
readonly
Returns the value of attribute dont_nullify.
-
#exclusions ⇒ Object
readonly
Returns the value of attribute exclusions.
-
#inclusions ⇒ Object
readonly
Returns the value of attribute inclusions.
-
#limit(limit = nil) ⇒ Object
readonly
Returns the value of attribute limit.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#order(order = nil) ⇒ Object
readonly
Returns the value of attribute order.
-
#total_limit ⇒ Object
readonly
Returns the value of attribute total_limit.
Instance Method Summary collapse
- #do_not_nullify(nullify_flag) ⇒ Object
-
#exclude(*association_patterns) ⇒ Object
Exclude some of associations from the dump.
- #exclude_has_relations ⇒ Object
- #exclude_optional_belongs_to ⇒ Object
- #excluded?(association_path) ⇒ Boolean
- #excluded_has_relations? ⇒ Boolean
- #excluded_optional_belongs_to? ⇒ Boolean
-
#include(*association_patterns, &block) ⇒ Object
Include some excluded associations back to the dump.
- #included?(association_path) ⇒ Boolean
-
#initialize(model, dont_nullify, *constraints) ⇒ Root
constructor
A new instance of Root.
-
#limit_associations_size(limit, *association_patterns) ⇒ Object
Limit number of records in all (if pattern is not provided) or given associations to include into dump.
-
#limit_deep(limit) ⇒ Object
Limit deepenes of associations to include into dump.
Constructor Details
#initialize(model, dont_nullify, *constraints) ⇒ Root
Returns a new instance of Root.
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_limits ⇒ Object (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 |
#constraints ⇒ Object (readonly)
Returns the value of attribute constraints.
7 8 9 |
# File 'lib/evil_seed/configuration/root.rb', line 7 def constraints @constraints end |
#deep_limit ⇒ Object (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_nullify ⇒ Object (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 |
#exclusions ⇒ Object (readonly)
Returns the value of attribute exclusions.
9 10 11 |
# File 'lib/evil_seed/configuration/root.rb', line 9 def exclusions @exclusions end |
#inclusions ⇒ Object (readonly)
Returns the value of attribute inclusions.
9 10 11 |
# File 'lib/evil_seed/configuration/root.rb', line 9 def inclusions @inclusions end |
#limit(limit = nil) ⇒ Object (readonly)
Returns the value of attribute limit.
7 8 9 |
# File 'lib/evil_seed/configuration/root.rb', line 7 def limit @limit end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
7 8 9 |
# File 'lib/evil_seed/configuration/root.rb', line 7 def model @model end |
#order(order = nil) ⇒ Object (readonly)
Returns the value of attribute order.
7 8 9 |
# File 'lib/evil_seed/configuration/root.rb', line 7 def order @order end |
#total_limit ⇒ Object (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
98 99 100 |
# File 'lib/evil_seed/configuration/root.rb', line 98 def do_not_nullify(nullify_flag) @dont_nullify = nullify_flag end |
#exclude(*association_patterns) ⇒ Object
Exclude some of associations from the dump
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/evil_seed/configuration/root.rb', line 25 def exclude(*association_patterns) association_patterns.each do |pattern| case pattern when String, Regexp @exclusions << pattern else path_prefix = model.constantize.model_name.singular @exclusions += compile_patterns(pattern, prefix: path_prefix).map { |p| Regexp.new(/\A#{p}\z/) } end end end |
#exclude_has_relations ⇒ Object
53 54 55 |
# File 'lib/evil_seed/configuration/root.rb', line 53 def exclude_has_relations @excluded_has_relations = :exclude_has_relations end |
#exclude_optional_belongs_to ⇒ Object
57 58 59 |
# File 'lib/evil_seed/configuration/root.rb', line 57 def exclude_optional_belongs_to @excluded_optional_belongs_to = :exclude_optional_belongs_to end |
#excluded?(association_path) ⇒ Boolean
102 103 104 |
# File 'lib/evil_seed/configuration/root.rb', line 102 def excluded?(association_path) exclusions.find { |exclusion| association_path.match(exclusion) } #.match(association_path) } end |
#excluded_has_relations? ⇒ Boolean
110 111 112 |
# File 'lib/evil_seed/configuration/root.rb', line 110 def excluded_has_relations? @excluded_has_relations end |
#excluded_optional_belongs_to? ⇒ Boolean
114 115 116 |
# File 'lib/evil_seed/configuration/root.rb', line 114 def excluded_optional_belongs_to? @excluded_optional_belongs_to end |
#include(*association_patterns, &block) ⇒ Object
Include some excluded associations back to the dump
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/evil_seed/configuration/root.rb', line 39 def include(*association_patterns, &block) association_patterns.each do |pattern| case pattern when String, Regexp @inclusions[pattern] = block else path_prefix = model.constantize.model_name.singular compile_patterns(pattern, prefix: path_prefix).map do |p| @inclusions[Regexp.new(/\A#{p}\z/)] = block end end end end |
#included?(association_path) ⇒ Boolean
106 107 108 |
# File 'lib/evil_seed/configuration/root.rb', line 106 def included?(association_path) inclusions.find { |inclusion, _block| association_path.match(inclusion) } end |
#limit_associations_size(limit, *association_patterns) ⇒ Object
Limit number of records in all (if pattern is not provided) or given associations to include into dump
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/evil_seed/configuration/root.rb', line 76 def limit_associations_size(limit, *association_patterns) return @total_limit = limit if association_patterns.empty? association_patterns.each do |pattern| case pattern when String, Regexp @association_limits[pattern] = limit else path_prefix = model.constantize.model_name.singular compile_patterns(pattern, prefix: path_prefix, partial: false).map do |p| @association_limits[Regexp.new(/\A#{p}\z/)] = limit end end end end |
#limit_deep(limit) ⇒ Object
Limit deepenes of associations to include into dump
94 95 96 |
# File 'lib/evil_seed/configuration/root.rb', line 94 def limit_deep(limit) @deep_limit = limit end |