Sha256: 800c4aa7176507e9d20d69632508005276cc2b60ef0520931c8951638c13c0aa

Contents?: true

Size: 754 Bytes

Versions: 5

Compression:

Stored size: 754 Bytes

Contents

module Goodcheck
  class Config
    attr_reader :rules

    def initialize(rules:)
      @rules = rules
    end

    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 | File::FNM_EXTGLOB) }
              if glob
                [rule, glob]
              end
            end
          end
        end.compact.each(&block)
      else
        enum_for(:rules_for_path, path, rules_filter: rules_filter)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
goodcheck-1.4.1 lib/goodcheck/config.rb
goodcheck-1.4.0 lib/goodcheck/config.rb
goodcheck-1.3.1 lib/goodcheck/config.rb
goodcheck-1.2.0 lib/goodcheck/config.rb
goodcheck-1.1.0 lib/goodcheck/config.rb