Class: Vial::FixtureAnalyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/vial/fixture_analyzer.rb

Defined Under Namespace

Classes: FixtureInfo

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#errorsObject (readonly)

Returns the value of attribute errors.



9
10
11
# File 'lib/vial/fixture_analyzer.rb', line 9

def errors
  @errors
end

#fixture_pathsObject (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_mappingsObject (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

#analyzeObject



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_fixturesObject



37
38
39
# File 'lib/vial/fixture_analyzer.rb', line 37

def mapped_fixtures
  @model_mappings.select { |_, v| v.model_class.present? }
end

#summaryObject



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_fixturesObject



41
42
43
# File 'lib/vial/fixture_analyzer.rb', line 41

def unmapped_fixtures
  @model_mappings.select { |_, v| v.model_class.nil? }
end