Class: XCAssetsCop::LinterRule
- Inherits:
-
Object
- Object
- XCAssetsCop::LinterRule
- Defined in:
- lib/xcassetscop/linter_rule.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#paths ⇒ Object
readonly
Returns the value of attribute paths.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(obj) ⇒ LinterRule
constructor
A new instance of LinterRule.
Constructor Details
#initialize(obj) ⇒ LinterRule
9 10 11 12 13 14 15 |
# File 'lib/xcassetscop/linter_rule.rb', line 9 def initialize(obj) LinterRule.ensure_no_missing_keys obj LinterRule.ensure_all_keys_are_allowed obj = obj.sdig(:paths).map { |path| File.(path) } @paths = Dir.glob() @config = ConfigOptions.new obj.sdig(:config) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
7 8 9 |
# File 'lib/xcassetscop/linter_rule.rb', line 7 def config @config end |
#paths ⇒ Object (readonly)
Returns the value of attribute paths.
7 8 9 |
# File 'lib/xcassetscop/linter_rule.rb', line 7 def paths @paths end |
Class Method Details
.ensure_all_keys_are_allowed(obj) ⇒ Object
25 26 27 28 |
# File 'lib/xcassetscop/linter_rule.rb', line 25 def self.ensure_all_keys_are_allowed(obj) diff = obj.keys.map(&:to_sym) - i[paths config] raise StandardError, "Unexpected key#{'s' if diff.size > 1}: #{diff.map { |s| "'#{s}'" }.join(', ')}" if diff.size.positive? end |
.ensure_no_missing_keys(obj) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/xcassetscop/linter_rule.rb', line 17 def self.ensure_no_missing_keys(obj) obj_sym = obj.keys.map(&:to_sym) missing_keys = [] missing_keys << :paths unless obj_sym.include? :paths missing_keys << :config unless obj_sym.include? :config raise StandardError, "Missing key#{'s' if missing_keys.size > 1}: #{missing_keys.map { |s| "'#{s}'" }.join(', ')}" if missing_keys.size.positive? end |