Class: ThemeCheck::Analyzer
- Inherits:
-
Object
- Object
- ThemeCheck::Analyzer
- Defined in:
- lib/theme_check/analyzer.rb
Instance Attribute Summary collapse
-
#offenses ⇒ Object
readonly
Returns the value of attribute offenses.
Instance Method Summary collapse
- #analyze_theme ⇒ Object
- #correct_offenses ⇒ Object
-
#initialize(theme, checks = Check.all.map(&:new), auto_correct = false) ⇒ Analyzer
constructor
A new instance of Analyzer.
- #uncorrectable_offenses ⇒ Object
Constructor Details
#initialize(theme, checks = Check.all.map(&:new), auto_correct = false) ⇒ Analyzer
Returns a new instance of Analyzer.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/theme_check/analyzer.rb', line 6 def initialize(theme, checks = Check.all.map(&:new), auto_correct = false) @theme = theme @offenses = [] @auto_correct = auto_correct @liquid_checks = Checks.new @json_checks = Checks.new checks.each do |check| check.theme = @theme check.offenses = @offenses case check when LiquidCheck @liquid_checks << check when JsonCheck @json_checks << check end end @visitor = Visitor.new(@liquid_checks) end |
Instance Attribute Details
#offenses ⇒ Object (readonly)
Returns the value of attribute offenses.
4 5 6 |
# File 'lib/theme_check/analyzer.rb', line 4 def offenses @offenses end |
Instance Method Details
#analyze_theme ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/theme_check/analyzer.rb', line 29 def analyze_theme @offenses.clear @theme.liquid.each { |template| @visitor.visit_template(template) } @theme.json.each { |json_file| @json_checks.call(:on_file, json_file) } @liquid_checks.call(:on_end) @json_checks.call(:on_end) @offenses end |
#correct_offenses ⇒ Object
46 47 48 49 50 51 |
# File 'lib/theme_check/analyzer.rb', line 46 def correct_offenses if @auto_correct @offenses.each(&:correct) @theme.liquid.each(&:write) end end |
#uncorrectable_offenses ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/theme_check/analyzer.rb', line 38 def uncorrectable_offenses unless @auto_correct return @offenses end @offenses.select { |offense| !offense.correctable? } end |