Class: ThemeCheck::Check

Inherits:
Object
  • Object
show all
Includes:
JsonHelpers
Defined in:
lib/theme_check/check.rb

Direct Known Subclasses

JsonCheck, LiquidCheck

Constant Summary collapse

SEVERITIES =
[
  :error,
  :suggestion,
  :style,
]
CATEGORIES =
[
  :liquid,
  :translation,
  :json,
]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from JsonHelpers

#format_json_parse_error

Instance Attribute Details

#offensesObject

Returns the value of attribute offenses.



9
10
11
# File 'lib/theme_check/check.rb', line 9

def offenses
  @offenses
end

#optionsObject

Returns the value of attribute options.



10
11
12
# File 'lib/theme_check/check.rb', line 10

def options
  @options
end

#themeObject

Returns the value of attribute theme.



8
9
10
# File 'lib/theme_check/check.rb', line 8

def theme
  @theme
end

Class Method Details

.allObject



25
26
27
# File 'lib/theme_check/check.rb', line 25

def all
  @all ||= []
end

.can_disable(disableable = nil) ⇒ Object



54
55
56
57
58
59
# File 'lib/theme_check/check.rb', line 54

def can_disable(disableable = nil)
  unless disableable.nil?
    @can_disable = disableable
  end
  defined?(@can_disable) ? @can_disable : true
end

.category(category = nil) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/theme_check/check.rb', line 39

def category(category = nil)
  if category
    unless CATEGORIES.include?(category)
      raise ArgumentError, "unknown category. Use: #{CATEGORIES.join(', ')}"
    end
    @category = category
  end
  @category if defined?(@category)
end

.doc(doc = nil) ⇒ Object



49
50
51
52
# File 'lib/theme_check/check.rb', line 49

def doc(doc = nil)
  @doc = doc if doc
  @doc if defined?(@doc)
end

.severity(severity = nil) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/theme_check/check.rb', line 29

def severity(severity = nil)
  if severity
    unless SEVERITIES.include?(severity)
      raise ArgumentError, "unknown severity. Use: #{SEVERITIES.join(', ')}"
    end
    @severity = severity
  end
  @severity if defined?(@severity)
end

Instance Method Details

#can_disable?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/theme_check/check.rb', line 90

def can_disable?
  self.class.can_disable
end

#categoryObject



66
67
68
# File 'lib/theme_check/check.rb', line 66

def category
  self.class.category
end

#code_nameObject



74
75
76
# File 'lib/theme_check/check.rb', line 74

def code_name
  self.class.name.demodulize
end

#docObject



70
71
72
# File 'lib/theme_check/check.rb', line 70

def doc
  self.class.doc
end

#ignore!Object



78
79
80
# File 'lib/theme_check/check.rb', line 78

def ignore!
  @ignored = true
end

#ignored?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/theme_check/check.rb', line 86

def ignored?
  defined?(@ignored) && @ignored
end

#severityObject



62
63
64
# File 'lib/theme_check/check.rb', line 62

def severity
  self.class.severity
end

#to_sObject



94
95
96
97
98
99
100
101
# File 'lib/theme_check/check.rb', line 94

def to_s
  s = +"#{code_name}:\n"
  properties = { severity: severity, category: category, doc: doc }.merge(options)
  properties.each_pair do |name, value|
    s << "  #{name}: #{value}\n" if value
  end
  s
end

#unignore!Object



82
83
84
# File 'lib/theme_check/check.rb', line 82

def unignore!
  @ignored = false
end