lib/jarbler/config.rb in jarbler-0.1.3 vs lib/jarbler/config.rb in jarbler-0.1.4
- old
+ new
@@ -1,11 +1,14 @@
+require 'rubygems'
+require 'json'
+
module Jarbler
class Config
attr_accessor :jar_name, :includes, :excludes, :jruby_version, :executable, :executable_params
CONFIG_FILE = 'config/jarble.rb'
- # create instence of Config class with defaults or from config file
+ # create instance of Config class with defaults or from config file
# Should be called from rails/ruby root directory
def self.create
if File.exist?(CONFIG_FILE)
config = eval(File.read(CONFIG_FILE), binding, CONFIG_FILE, 0)
else
@@ -88,15 +91,21 @@
self.jruby_version = File.read('.ruby-version')[6..20].strip
debug "jRuby version from .ruby-version file: #{jruby_version}"
else
# no .ruby-version file, use jRuby version of the latest Gem
# Fetch the gem specification from Rubygems.org
- command = "gem search --remote jruby-jars"
- lines = `#{command}`
- raise "Command \"#{command}\" failed with return code #{$?} and output:\n#{lines}" unless $?.success?
- jruby_jars_line = lines.match(/^jruby-jars \((.*)\)/)
- raise "No jruby-jars gem found in rubygems.org!" unless jruby_jars_line
- self.jruby_version = /\((.*?)\)/.match(jruby_jars_line.to_s)[1]
+ # search for the gem and get the JSON response
+ response = Gem::SpecFetcher.fetcher.search_for_dependency(Gem::Dependency.new('jruby-jars'))
+ # extract the versions from the response
+ self.jruby_version = response&.first&.first&.first&.version&.to_s
+ raise "Unable to determine the latest available version of jruby-jars gem!\Rsponse = #{response.inspect}" unless self.jruby_version
+
+ #command = "gem search --remote jruby-jars"
+ #lines = `#{command}`
+ #raise "Command \"#{command}\" failed with return code #{$?} and output:\n#{lines}" unless $?.success?
+ #jruby_jars_line = lines.match(/^jruby-jars \((.*)\)/)
+ #raise "No jruby-jars gem found in rubygems.org!" unless jruby_jars_line
+ #self.jruby_version = /\((.*?)\)/.match(jruby_jars_line.to_s)[1]
debug "jRuby version from latest jruby-jars gem: #{jruby_version}"
end
end
end
\ No newline at end of file