Class: EvilSeed::RelationDumper
- Inherits:
-
Object
- Object
- EvilSeed::RelationDumper
- Defined in:
- lib/evil_seed/relation_dumper.rb
Overview
This class performs actual dump generation for single relation and all its not yet loaded dependencies
- Fetches all tuples for root (it does not instantiate AR records but it casts values to Ruby types)
- Extracts foreign key values for all belongs_to associations
- Dumps belongs_to associations(recursion!)
- Dumps all tuples for root, writes them in file
- Dumps all other associations (recursion!)
- Returns all results to caller in correct order
TODO: This class obviously breaks SRP principle and thus should be split!
Constant Summary collapse
- MAX_IDENTIFIERS_IN_IN_STMT =
1_000
Instance Attribute Summary collapse
-
#association_path ⇒ Object
readonly
Returns the value of attribute association_path.
-
#belongs_to_reflections ⇒ Object
readonly
Returns the value of attribute belongs_to_reflections.
-
#current_deep ⇒ Object
readonly
Returns the value of attribute current_deep.
-
#custom_scope ⇒ Object
readonly
Returns the value of attribute custom_scope.
-
#foreign_keys ⇒ Object
readonly
Returns the value of attribute foreign_keys.
-
#has_many_reflections ⇒ Object
readonly
Returns the value of attribute has_many_reflections.
-
#identifiers ⇒ Object
readonly
Returns the value of attribute identifiers.
-
#inverse_reflection ⇒ Object
readonly
Returns the value of attribute inverse_reflection.
-
#loaded_ids ⇒ Object
readonly
Returns the value of attribute loaded_ids.
-
#local_load_map ⇒ Object
readonly
Returns the value of attribute local_load_map.
-
#model_class ⇒ Object
readonly
Returns the value of attribute model_class.
-
#nullify_columns ⇒ Object
readonly
Returns the value of attribute nullify_columns.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#record_dumper ⇒ Object
readonly
Returns the value of attribute record_dumper.
-
#records ⇒ Object
readonly
Returns the value of attribute records.
-
#relation ⇒ Object
readonly
Returns the value of attribute relation.
-
#root_dumper ⇒ Object
readonly
Returns the value of attribute root_dumper.
-
#search_key ⇒ Object
readonly
Returns the value of attribute search_key.
-
#table_names ⇒ Object
readonly
Returns the value of attribute table_names.
-
#verbose ⇒ Object
readonly
Returns the value of attribute verbose.
Instance Method Summary collapse
-
#call ⇒ Array<IO>
Generate dump and write it into
io. -
#initialize(relation, root_dumper, association_path, **options) ⇒ RelationDumper
constructor
A new instance of RelationDumper.
Constructor Details
#initialize(relation, root_dumper, association_path, **options) ⇒ RelationDumper
Returns a new instance of RelationDumper.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/evil_seed/relation_dumper.rb', line 33 def initialize(relation, root_dumper, association_path, **) puts("- #{association_path}") if root_dumper.configuration.verbose @relation = relation @root_dumper = root_dumper @verbose = configuration.verbose @identifiers = [:identifiers] @local_load_map = Hash.new { |h, k| h[k] = [] } @foreign_keys = Hash.new { |h, k| h[k] = [] } @loaded_ids = [] @model_class = relation.klass @search_key = [:search_key] || model_class.primary_key @association_path = association_path @inverse_reflection = [:inverse_of] @records = [] @record_dumper = configuration.record_dumper_class.new(model_class, configuration, self) @nullify_columns = [] @table_names = {} @belongs_to_reflections = setup_belongs_to_reflections @has_many_reflections = setup_has_many_reflections @options = @current_deep = association_path.split('.').size @dont_nullify = dont_nullify @custom_scope = [:custom_scope] end |
Instance Attribute Details
#association_path ⇒ Object (readonly)
Returns the value of attribute association_path.
26 27 28 |
# File 'lib/evil_seed/relation_dumper.rb', line 26 def association_path @association_path end |
#belongs_to_reflections ⇒ Object (readonly)
Returns the value of attribute belongs_to_reflections.
26 27 28 |
# File 'lib/evil_seed/relation_dumper.rb', line 26 def belongs_to_reflections @belongs_to_reflections end |
#current_deep ⇒ Object (readonly)
Returns the value of attribute current_deep.
26 27 28 |
# File 'lib/evil_seed/relation_dumper.rb', line 26 def current_deep @current_deep end |
#custom_scope ⇒ Object (readonly)
Returns the value of attribute custom_scope.
26 27 28 |
# File 'lib/evil_seed/relation_dumper.rb', line 26 def custom_scope @custom_scope end |
#foreign_keys ⇒ Object (readonly)
Returns the value of attribute foreign_keys.
26 27 28 |
# File 'lib/evil_seed/relation_dumper.rb', line 26 def foreign_keys @foreign_keys end |
#has_many_reflections ⇒ Object (readonly)
Returns the value of attribute has_many_reflections.
26 27 28 |
# File 'lib/evil_seed/relation_dumper.rb', line 26 def has_many_reflections @has_many_reflections end |
#identifiers ⇒ Object (readonly)
Returns the value of attribute identifiers.
26 27 28 |
# File 'lib/evil_seed/relation_dumper.rb', line 26 def identifiers @identifiers end |
#inverse_reflection ⇒ Object (readonly)
Returns the value of attribute inverse_reflection.
26 27 28 |
# File 'lib/evil_seed/relation_dumper.rb', line 26 def inverse_reflection @inverse_reflection end |
#loaded_ids ⇒ Object (readonly)
Returns the value of attribute loaded_ids.
26 27 28 |
# File 'lib/evil_seed/relation_dumper.rb', line 26 def loaded_ids @loaded_ids end |
#local_load_map ⇒ Object (readonly)
Returns the value of attribute local_load_map.
26 27 28 |
# File 'lib/evil_seed/relation_dumper.rb', line 26 def local_load_map @local_load_map end |
#model_class ⇒ Object (readonly)
Returns the value of attribute model_class.
26 27 28 |
# File 'lib/evil_seed/relation_dumper.rb', line 26 def model_class @model_class end |
#nullify_columns ⇒ Object (readonly)
Returns the value of attribute nullify_columns.
26 27 28 |
# File 'lib/evil_seed/relation_dumper.rb', line 26 def nullify_columns @nullify_columns end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
26 27 28 |
# File 'lib/evil_seed/relation_dumper.rb', line 26 def @options end |
#record_dumper ⇒ Object (readonly)
Returns the value of attribute record_dumper.
26 27 28 |
# File 'lib/evil_seed/relation_dumper.rb', line 26 def record_dumper @record_dumper end |
#records ⇒ Object (readonly)
Returns the value of attribute records.
26 27 28 |
# File 'lib/evil_seed/relation_dumper.rb', line 26 def records @records end |
#relation ⇒ Object (readonly)
Returns the value of attribute relation.
26 27 28 |
# File 'lib/evil_seed/relation_dumper.rb', line 26 def relation @relation end |
#root_dumper ⇒ Object (readonly)
Returns the value of attribute root_dumper.
26 27 28 |
# File 'lib/evil_seed/relation_dumper.rb', line 26 def root_dumper @root_dumper end |
#search_key ⇒ Object (readonly)
Returns the value of attribute search_key.
26 27 28 |
# File 'lib/evil_seed/relation_dumper.rb', line 26 def search_key @search_key end |
#table_names ⇒ Object (readonly)
Returns the value of attribute table_names.
26 27 28 |
# File 'lib/evil_seed/relation_dumper.rb', line 26 def table_names @table_names end |
#verbose ⇒ Object (readonly)
Returns the value of attribute verbose.
26 27 28 |
# File 'lib/evil_seed/relation_dumper.rb', line 26 def verbose @verbose end |
Instance Method Details
#call ⇒ Array<IO>
Generate dump and write it into io
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/evil_seed/relation_dumper.rb', line 61 def call dump! if deep_limit and current_deep > deep_limit [dump_records!].flatten.compact else [ dump_belongs_to_associations!, dump_records!, dump_has_many_associations!, ].flatten.compact end end |