lib/evil_seed/configuration/root.rb in evil-seed-0.5.0 vs lib/evil_seed/configuration/root.rb in evil-seed-0.6.0

- old
+ new

@@ -3,28 +3,37 @@ module EvilSeed class Configuration # Configuration for dumping some root model and its associations class Root attr_reader :model, :constraints - attr_reader :total_limit, :association_limits - attr_reader :exclusions + attr_reader :total_limit, :association_limits, :deep_limit, :dont_nullify + attr_reader :exclusions, :inclusions # @param model [String] Name of the model class to dump # @param constraints [String, Hash] Everything you can feed into +where+ to limit number of records - def initialize(model, *constraints) + def initialize(model, dont_nullify, *constraints) @model = model @constraints = constraints @exclusions = [] + @inclusions = [] @association_limits = {} + @deep_limit = nil + @dont_nullify = dont_nullify end # Exclude some of associations from the dump # @param association_patterns Array<String, Regex> Patterns to exclude associated models from dump def exclude(*association_patterns) @exclusions += association_patterns end + # Include some excluded associations back to the dump + # @param association_patterns Array<String, Regex> Patterns to exclude associated models from dump + def include(*association_patterns) + @inclusions += association_patterns + end + # Limit number of records in all (if pattern is not provided) or given associations to include into dump # @param limit [Integer] Maximum number of records in associations to include into dump # @param association_pattern [String, Regex] Pattern to limit number of records for certain associated models def limit_associations_size(limit, association_pattern = nil) if association_pattern @@ -32,11 +41,25 @@ else @total_limit = limit end end + # Limit deepenes of associations to include into dump + # @param limit [Integer] Maximum level to recursively dive into associations + def limit_deep(limit) + @deep_limit = limit + end + + def do_not_nullify(nullify_flag) + @dont_nullify = nullify_flag + end + def excluded?(association_path) - exclusions.any? { |exclusion| exclusion.match(association_path) } + exclusions.any? { |exclusion| association_path.match(exclusion) } #.match(association_path) } + end + + def included?(association_path) + inclusions.any? { |inclusion| association_path.match(inclusion) } #.match(association_path) } end end end end