Class: Goodcheck::Config
- Inherits:
-
Object
- Object
- Goodcheck::Config
- Defined in:
- lib/goodcheck/config.rb
Instance Attribute Summary collapse
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
Instance Method Summary collapse
-
#initialize(rules:) ⇒ Config
constructor
A new instance of Config.
- #rules_for_path(path, rules_filter:, &block) ⇒ Object
Constructor Details
#initialize(rules:) ⇒ Config
Returns a new instance of Config.
5 6 7 |
# File 'lib/goodcheck/config.rb', line 5 def initialize(rules:) @rules = rules end |
Instance Attribute Details
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
3 4 5 |
# File 'lib/goodcheck/config.rb', line 3 def rules @rules end |
Instance Method Details
#rules_for_path(path, rules_filter:, &block) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/goodcheck/config.rb', line 9 def rules_for_path(path, rules_filter:, &block) if block_given? rules.map do |rule| if rules_filter.empty? || rules_filter.any? {|filter| /\A#{Regexp.escape(filter)}\.?/ =~ rule.id } if rule.globs.empty? [rule, nil] else glob = rule.globs.find {|glob| path.fnmatch?(glob.pattern, File::FNM_PATHNAME) } if glob [rule, glob] end end end end.compact.each(&block) else enum_for(:rules_for_path, path, rules_filter: rules_filter) end end |