Class: Matchd::Registry
- Inherits:
-
Object
- Object
- Matchd::Registry
- Includes:
- Enumerable
- Defined in:
- lib/matchd/registry.rb
Overview
Tthe dns pattern registry It basically delegates everything to a YAML::Store but handles the conversion of Regexp dns-patterns into YAML string keys and reverse.
Defined Under Namespace
Classes: ParseError
Constant Summary collapse
- LoadError =
Class.new(RuntimeError)
Instance Attribute Summary collapse
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
Class Method Summary collapse
- .load(data, registry_file = nil) ⇒ Object
-
.load_file(registry_file) ⇒ Object
Loads a registry YAML file.
-
.parse(rules) ⇒ Array<Matchd::Rule>
Parses raw rule hash definitions (like those read from a YAML config) into ‘Matchd::Rule`s.
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(rules) ⇒ Registry
constructor
A new instance of Registry.
- #valid? ⇒ Boolean
Constructor Details
#initialize(rules) ⇒ Registry
Returns a new instance of Registry.
24 25 26 27 |
# File 'lib/matchd/registry.rb', line 24 def initialize(rules) raise ArgumentError unless rules.is_a?(Enumerable) @rules = rules end |
Instance Attribute Details
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
29 30 31 |
# File 'lib/matchd/registry.rb', line 29 def rules @rules end |
Class Method Details
.load(data, registry_file = nil) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/matchd/registry.rb', line 40 def self.load(data, registry_file = nil) raise ParseError, registry_file unless data.is_a?(Hash) && data.key?("rules") rules = data["rules"] new(rules ? parse(rules) : []) end |
.load_file(registry_file) ⇒ Object
Loads a registry YAML file
32 33 34 35 36 37 38 |
# File 'lib/matchd/registry.rb', line 32 def self.load_file(registry_file) unless File.file?(registry_file) raise LoadError, "Registry file '#{registry_file}' does not exist" end load(YAML.load_file(registry_file), registry_file) end |
.parse(rules) ⇒ Array<Matchd::Rule>
Parses raw rule hash definitions (like those read from a YAML config) into ‘Matchd::Rule`s
53 54 55 56 |
# File 'lib/matchd/registry.rb', line 53 def self.parse(rules) rules = rules.is_a?(Array) ? rules : [rules] rules.map { |r| Matchd.Rule(r) } end |