Class: Vial::FixtureAnalyzer
- Inherits:
-
Object
- Object
- Vial::FixtureAnalyzer
- Defined in:
- lib/vial/fixture_analyzer.rb
Defined Under Namespace
Classes: FixtureInfo
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#fixture_paths ⇒ Object
readonly
Returns the value of attribute fixture_paths.
-
#model_mappings ⇒ Object
readonly
Returns the value of attribute model_mappings.
Instance Method Summary collapse
- #analyze ⇒ Object
- #fixture_for_model(model_name) ⇒ Object
-
#initialize(fixture_paths = nil) ⇒ FixtureAnalyzer
constructor
A new instance of FixtureAnalyzer.
- #mapped_fixtures ⇒ Object
- #summary ⇒ Object
- #unmapped_fixtures ⇒ Object
Constructor Details
#initialize(fixture_paths = nil) ⇒ FixtureAnalyzer
Returns a new instance of FixtureAnalyzer.
11 12 13 14 15 16 |
# File 'lib/vial/fixture_analyzer.rb', line 11 def initialize(fixture_paths = nil) @fixture_paths = Array(fixture_paths || default_fixture_paths) @model_mappings = {} @errors = [] @fixture_class_names = {} end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
9 10 11 |
# File 'lib/vial/fixture_analyzer.rb', line 9 def errors @errors end |
#fixture_paths ⇒ Object (readonly)
Returns the value of attribute fixture_paths.
9 10 11 |
# File 'lib/vial/fixture_analyzer.rb', line 9 def fixture_paths @fixture_paths end |
#model_mappings ⇒ Object (readonly)
Returns the value of attribute model_mappings.
9 10 11 |
# File 'lib/vial/fixture_analyzer.rb', line 9 def model_mappings @model_mappings end |
Instance Method Details
#analyze ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/vial/fixture_analyzer.rb', line 18 def analyze load_fixture_class_mappings @fixture_paths.each do |path| analyze_path(path) end self end |
#fixture_for_model(model_name) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/vial/fixture_analyzer.rb', line 45 def fixture_for_model(model_name) model_class = model_name.is_a?(Class) ? model_name : model_name.to_s.safe_constantize return nil unless model_class @model_mappings.select { |_, v| v.model_class == model_class } end |
#mapped_fixtures ⇒ Object
37 38 39 |
# File 'lib/vial/fixture_analyzer.rb', line 37 def mapped_fixtures @model_mappings.select { |_, v| v.model_class.present? } end |
#summary ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/vial/fixture_analyzer.rb', line 28 def summary { total_fixtures: @model_mappings.size, mapped_fixtures: @model_mappings.count { |_, v| v.model_class.present? }, unmapped_fixtures: @model_mappings.count { |_, v| v.model_class.nil? }, errors: @errors } end |
#unmapped_fixtures ⇒ Object
41 42 43 |
# File 'lib/vial/fixture_analyzer.rb', line 41 def unmapped_fixtures @model_mappings.select { |_, v| v.model_class.nil? } end |