Class: GetVersion::ExecutableStore

Inherits:
Object
  • Object
show all
Defined in:
lib/getversion/executable_store.rb

Instance Method Summary collapse

Constructor Details

#initializeExecutableStore

Returns a new instance of ExecutableStore.



6
7
8
# File 'lib/getversion/executable_store.rb', line 6

def initialize
  @executables = []
end

Instance Method Details

#add_executable(name, namespace, &block) ⇒ Object



10
11
12
# File 'lib/getversion/executable_store.rb', line 10

def add_executable(name, namespace, &block)
  @executables << {name: name.to_sym, namespace: namespace.to_sym, value: Executable.new(&block)}
end

#get_executable(path) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/getversion/executable_store.rb', line 14

def get_executable(path)
  basename = File.basename path
  name = basename == path ? path : basename
  possibilities = [name, File.basename(name, '.*')]
  executable = @executables.find { |e| possibilities.find { |p| p.casecmp(e[:name].to_s) == 0 } }
  executable[:value] if executable
end