Module: GeminaboxClient::GemLocator

Extended by:
GemLocator
Included in:
GemLocator
Defined in:
lib/geminabox_client.rb

Constant Summary collapse

NO_GEM_PROVIDED_ERROR_MESSAGE =
"Couldn't find a gem in pkg, please specify a gem name on the command line (e.g. gem inabox GEMNAME)"

Instance Method Summary collapse

Instance Method Details

#find_gem(dir) ⇒ Object


41
42
43
44
45
# File 'lib/geminabox_client.rb', line 41

def find_gem(dir)
  gemname = File.split(dir).last
  glob_matcher = "{pkg/,}#{gemname}-*.gem"
  latest_gem_for(gemname, Dir.glob(glob_matcher)) or raise Gem::CommandLineError, NO_GEM_PROVIDED_ERROR_MESSAGE
end

#latest_gem_for(gemname, files) ⇒ Object


47
48
49
50
51
# File 'lib/geminabox_client.rb', line 47

def latest_gem_for(gemname, files)
  regexp_matcher = %r{(?:pkg/)#{gemname}-(#{Gem::Version::VERSION_PATTERN})\.gem}
  sorter = lambda{|v| Gem::Version.new(regexp_matcher.match(v)[1]) }
  files.grep(regexp_matcher).max_by(&sorter)
end