Class: Querly::Config
- Inherits:
-
Object
- Object
- Querly::Config
- Defined in:
- lib/querly/config.rb
Defined Under Namespace
Classes: Factory
Instance Attribute Summary collapse
-
#checks ⇒ Object
readonly
Returns the value of attribute checks.
-
#preprocessors ⇒ Object
readonly
Returns the value of attribute preprocessors.
-
#root_dir ⇒ Object
readonly
Returns the value of attribute root_dir.
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
-
#rules_cache ⇒ Object
readonly
Returns the value of attribute rules_cache.
Class Method Summary collapse
Instance Method Summary collapse
- #all_rules ⇒ Object
-
#initialize(rules:, preprocessors:, root_dir:, checks:) ⇒ Config
constructor
A new instance of Config.
- #relative_path_from_root(path) ⇒ Object
- #rules_for_path(path) ⇒ Object
Constructor Details
#initialize(rules:, preprocessors:, root_dir:, checks:) ⇒ Config
Returns a new instance of Config.
9 10 11 12 13 14 15 |
# File 'lib/querly/config.rb', line 9 def initialize(rules:, preprocessors:, root_dir:, checks:) @rules = rules @root_dir = root_dir @preprocessors = preprocessors @checks = checks @rules_cache = {} end |
Instance Attribute Details
#checks ⇒ Object (readonly)
Returns the value of attribute checks.
6 7 8 |
# File 'lib/querly/config.rb', line 6 def checks @checks end |
#preprocessors ⇒ Object (readonly)
Returns the value of attribute preprocessors.
4 5 6 |
# File 'lib/querly/config.rb', line 4 def preprocessors @preprocessors end |
#root_dir ⇒ Object (readonly)
Returns the value of attribute root_dir.
5 6 7 |
# File 'lib/querly/config.rb', line 5 def root_dir @root_dir end |
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
3 4 5 |
# File 'lib/querly/config.rb', line 3 def rules @rules end |
#rules_cache ⇒ Object (readonly)
Returns the value of attribute rules_cache.
7 8 9 |
# File 'lib/querly/config.rb', line 7 def rules_cache @rules_cache end |
Class Method Details
Instance Method Details
#all_rules ⇒ Object
21 22 23 |
# File 'lib/querly/config.rb', line 21 def all_rules @all_rules ||= Set.new(rules) end |
#relative_path_from_root(path) ⇒ Object
25 26 27 |
# File 'lib/querly/config.rb', line 25 def relative_path_from_root(path) path.absolute? ? path.relative_path_from(root_dir) : path.cleanpath end |
#rules_for_path(path) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/querly/config.rb', line 29 def rules_for_path(path) relative_path = relative_path_from_root(path) matching_checks = checks.select {|check| check.match?(path: relative_path) } if rules_cache.key?(matching_checks) rules_cache[matching_checks] else matching_checks.flat_map(&:rules).inject(all_rules) do |rules, query| query.apply(current: rules, all: all_rules) end.tap do |rules| rules_cache[matching_checks] = rules end end end |