Class: FlightConfig::Globber::Matcher

Inherits:
Object
  • Object
show all
Defined in:
lib/flight_config/globber.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#arityObject (readonly)

Returns the value of attribute arity.



32
33
34
# File 'lib/flight_config/globber.rb', line 32

def arity
  @arity
end

#klassObject (readonly)

Returns the value of attribute klass.



32
33
34
# File 'lib/flight_config/globber.rb', line 32

def klass
  @klass
end

#registryObject (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

#keysObject



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

#regexObject



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