Class: Querly::Check
- Inherits:
-
Object
- Object
- Querly::Check
- Defined in:
- lib/querly/check.rb
Defined Under Namespace
Classes: Query
Instance Attribute Summary collapse
-
#patterns ⇒ Object
readonly
Returns the value of attribute patterns.
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
Class Method Summary collapse
Instance Method Summary collapse
- #has_middle_slash? ⇒ Boolean
- #has_trailing_slash? ⇒ Boolean
-
#initialize(pattern:, rules:) ⇒ Check
constructor
A new instance of Check.
- #match?(path:) ⇒ Boolean
Constructor Details
#initialize(pattern:, rules:) ⇒ Check
Returns a new instance of Check.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/querly/check.rb', line 23 def initialize(pattern:, rules:) @rules = rules @has_trailing_slash = pattern.end_with?("/") @has_middle_slash = /\/./ =~ pattern @patterns = [] pattern.sub!(/\A\//, '') case when has_trailing_slash? && has_middle_slash? patterns << File.join(pattern, "**") when has_trailing_slash? patterns << File.join(pattern, "**") patterns << File.join("**", pattern, "**") when has_middle_slash? patterns << pattern patterns << File.join(pattern, "**") else patterns << pattern patterns << File.join("**", pattern) patterns << File.join(pattern, "**") patterns << File.join("**", pattern, "**") end end |
Instance Attribute Details
#patterns ⇒ Object (readonly)
Returns the value of attribute patterns.
20 21 22 |
# File 'lib/querly/check.rb', line 20 def patterns @patterns end |
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
21 22 23 |
# File 'lib/querly/check.rb', line 21 def rules @rules end |
Class Method Details
.load(hash) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/querly/check.rb', line 58 def self.load(hash) pattern = hash["path"] rules = Array(hash["rules"]).map do |rule| case rule when String parse_rule_query(:append, rule) when Hash case when rule["append"] parse_rule_query(:append, rule["append"]) when rule["except"] parse_rule_query(:except, rule["except"]) when rule["only"] parse_rule_query(:only, rule["only"]) else parse_rule_query(:append, rule) end end end self.new(pattern: pattern, rules: rules) end |
.parse_rule_query(opr, query) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/querly/check.rb', line 82 def self.parse_rule_query(opr, query) case query when String Query.new(opr, nil, query) when Hash if query['tags'] ts = query['tags'] if ts.is_a?(String) ts = ts.split end = Set.new(ts) end identifier = query['id'] Query.new(opr, , identifier) end end |
Instance Method Details
#has_middle_slash? ⇒ Boolean
54 55 56 |
# File 'lib/querly/check.rb', line 54 def has_middle_slash? @has_middle_slash end |
#has_trailing_slash? ⇒ Boolean
50 51 52 |
# File 'lib/querly/check.rb', line 50 def has_trailing_slash? @has_trailing_slash end |
#match?(path:) ⇒ Boolean
100 101 102 |
# File 'lib/querly/check.rb', line 100 def match?(path:) patterns.any? {|pat| File.fnmatch?(pat, path.to_s) } end |