Class: Querly::Config::Factory
- Inherits:
-
Object
- Object
- Querly::Config::Factory
- Defined in:
- lib/querly/config.rb
Instance Attribute Summary collapse
-
#config_path ⇒ Object
readonly
Returns the value of attribute config_path.
-
#root_dir ⇒ Object
readonly
Returns the value of attribute root_dir.
-
#stderr ⇒ Object
readonly
Returns the value of attribute stderr.
-
#yaml ⇒ Object
readonly
Returns the value of attribute yaml.
Instance Method Summary collapse
- #config ⇒ Object
-
#initialize(yaml, config_path:, root_dir:, stderr: STDERR) ⇒ Factory
constructor
A new instance of Factory.
Constructor Details
#initialize(yaml, config_path:, root_dir:, stderr: STDERR) ⇒ Factory
Returns a new instance of Factory.
50 51 52 53 54 55 |
# File 'lib/querly/config.rb', line 50 def initialize(yaml, config_path:, root_dir:, stderr: STDERR) @yaml = yaml @config_path = config_path @root_dir = root_dir @stderr = stderr end |
Instance Attribute Details
#config_path ⇒ Object (readonly)
Returns the value of attribute config_path.
48 49 50 |
# File 'lib/querly/config.rb', line 48 def config_path @config_path end |
#root_dir ⇒ Object (readonly)
Returns the value of attribute root_dir.
46 47 48 |
# File 'lib/querly/config.rb', line 46 def root_dir @root_dir end |
#stderr ⇒ Object (readonly)
Returns the value of attribute stderr.
47 48 49 |
# File 'lib/querly/config.rb', line 47 def stderr @stderr end |
#yaml ⇒ Object (readonly)
Returns the value of attribute yaml.
45 46 47 |
# File 'lib/querly/config.rb', line 45 def yaml @yaml end |
Instance Method Details
#config ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/querly/config.rb', line 57 def config if yaml["tagging"] stderr.puts "tagging is deprecated and ignored" end rules = Array(yaml["rules"]).map {|hash| Rule.load(hash) } preprocessors = (yaml["preprocessor"] || {}).each.with_object({}) do |(key, value), hash| hash[key] = Preprocessor.new(ext: key, command: value) end imports = Array(yaml["import"]) imports.each do |import| if import["load"] load_pattern = Pathname(import["load"]) load_pattern = config_path.parent + load_pattern if load_pattern.relative? Pathname.glob(load_pattern.to_s) do |path| stderr.puts "Loading rules from #{path}..." YAML.load(path.read).each do |hash| rules << Rule.load(hash) end end end end checks = Array(yaml["check"]).map {|hash| Check.load(hash) } Config.new(rules: rules, preprocessors: preprocessors, checks: checks, root_dir: root_dir) end |