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



45
46
47
48
49
# File 'lib/geminabox_client.rb', line 45

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



51
52
53
54
55
# File 'lib/geminabox_client.rb', line 51

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