Class: Vial::FixtureIdStandardizer
- Inherits:
-
Object
- Object
- Vial::FixtureIdStandardizer
- Defined in:
- lib/vial/fixture_id_standardizer.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#fixture_paths ⇒ Object
readonly
Returns the value of attribute fixture_paths.
-
#updates_needed ⇒ Object
readonly
Returns the value of attribute updates_needed.
Instance Method Summary collapse
- #analyze ⇒ Object
-
#initialize(fixture_paths = nil) ⇒ FixtureIdStandardizer
constructor
A new instance of FixtureIdStandardizer.
- #standardize!(dry_run: false) ⇒ Object
- #summary ⇒ Object
Constructor Details
#initialize(fixture_paths = nil) ⇒ FixtureIdStandardizer
Returns a new instance of FixtureIdStandardizer.
9 10 11 12 13 14 |
# File 'lib/vial/fixture_id_standardizer.rb', line 9 def initialize(fixture_paths = nil) @fixture_paths = Array(fixture_paths || default_fixture_paths) @updates_needed = [] @errors = [] @analyzer = FixtureAnalyzer.new(fixture_paths) end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
7 8 9 |
# File 'lib/vial/fixture_id_standardizer.rb', line 7 def errors @errors end |
#fixture_paths ⇒ Object (readonly)
Returns the value of attribute fixture_paths.
7 8 9 |
# File 'lib/vial/fixture_id_standardizer.rb', line 7 def fixture_paths @fixture_paths end |
#updates_needed ⇒ Object (readonly)
Returns the value of attribute updates_needed.
7 8 9 |
# File 'lib/vial/fixture_id_standardizer.rb', line 7 def updates_needed @updates_needed end |
Instance Method Details
#analyze ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/vial/fixture_id_standardizer.rb', line 16 def analyze @analyzer.analyze @analyzer.mapped_fixtures.each do |fixture_name, info| analyze_fixture_file(info) end self end |
#standardize!(dry_run: false) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/vial/fixture_id_standardizer.rb', line 26 def standardize!(dry_run: false) analyze if @updates_needed.empty? @updates_needed.each do |update| if dry_run puts "Would update: #{update.file}" update.changes.each do |change| puts " #{change.label}: #{change.current_id} -> #{change.new_id}" end else apply_updates(update) end end end |
#summary ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/vial/fixture_id_standardizer.rb', line 41 def summary pk_type_stats = @analyzer.mapped_fixtures.values.group_by do |info| next :unmapped unless info.model_class pk = info.model_class.primary_key get_primary_key_type(info.model_class, pk) || :unknown end.transform_values(&:size) { total_fixtures: @analyzer.mapped_fixtures.size, fixtures_needing_updates: @updates_needed.size, records_to_update: @updates_needed.sum { |u| u.changes.size }, primary_key_types: pk_type_stats, errors: @errors } end |