Class: XCAssetsCop::LinterRule

Inherits:
Object
  • Object
show all
Defined in:
lib/xcassetscop/linter_rule.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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
  expanded_paths = obj.sdig(:paths).map { |path| File.expand_path(path) }
  @paths = Dir.glob(expanded_paths)
  @config = ConfigOptions.new obj.sdig(:config)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/xcassetscop/linter_rule.rb', line 7

def config
  @config
end

#pathsObject (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

Raises:

  • (StandardError)


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

Raises:

  • (StandardError)


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