Module: GeminaboxClient::GemLocator
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 50 51 |
# File 'lib/geminabox_client.rb', line 45 def find_gem(dir) gemspec_path = Dir.glob(File.join(dir, "*.gemspec")).first gemspec = Gem::Specification::load(gemspec_path) gemname = gemspec.name 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
53 54 55 56 57 |
# File 'lib/geminabox_client.rb', line 53 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 |