Class: FlightConfig::Globber::Matcher
- Inherits:
-
Object
- Object
- FlightConfig::Globber::Matcher
- Defined in:
- lib/flight_config/globber.rb
Instance Attribute Summary collapse
-
#arity ⇒ Object
readonly
Returns the value of attribute arity.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#registry ⇒ Object
readonly
Returns the value of attribute registry.
Instance Method Summary collapse
-
#initialize(klass, arity, registry) ⇒ Matcher
constructor
A new instance of Matcher.
- #keys ⇒ Object
- #read(path) ⇒ Object
- #regex ⇒ Object
Constructor Details
#initialize(klass, arity, registry) ⇒ Matcher
Returns a new instance of Matcher.
34 35 36 37 38 |
# File 'lib/flight_config/globber.rb', line 34 def initialize(klass, arity, registry) @klass = klass @arity = arity @registry = (registry || FlightConfig::Registry.new) end |
Instance Attribute Details
#arity ⇒ Object (readonly)
Returns the value of attribute arity.
32 33 34 |
# File 'lib/flight_config/globber.rb', line 32 def arity @arity end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
32 33 34 |
# File 'lib/flight_config/globber.rb', line 32 def klass @klass end |
#registry ⇒ Object (readonly)
Returns the value of attribute registry.
32 33 34 |
# File 'lib/flight_config/globber.rb', line 32 def registry @registry end |
Instance Method Details
#keys ⇒ Object
40 41 42 |
# File 'lib/flight_config/globber.rb', line 40 def keys @keys ||= Array.new(arity) { |i| "arg#{i}" } end |
#read(path) ⇒ Object
51 52 53 54 55 |
# File 'lib/flight_config/globber.rb', line 51 def read(path) data = regex.match(path) init_args = keys.map { |key| data[key] } klass.read(*init_args, registry: registry) end |
#regex ⇒ Object
44 45 46 47 48 49 |
# File 'lib/flight_config/globber.rb', line 44 def regex @regex ||= begin regex_inputs = keys.map { |k| "(?<#{k}>.*)" } /#{klass.new(*regex_inputs).path}/ end end |