From 09d8238b2e7fdf630a461b33c97e3971a495be50 Mon Sep 17 00:00:00 2001 From: Jakukyo Friel Date: Sat, 25 Apr 2015 13:41:26 +0800 Subject: [PATCH 1/3] Add gem2 installer to use `gem2.0`. Same as gem installer except it uses `gem2.0`. --- lib/sprinkle/installers/gem2.rb | 65 +++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 lib/sprinkle/installers/gem2.rb diff --git a/lib/sprinkle/installers/gem2.rb b/lib/sprinkle/installers/gem2.rb new file mode 100644 index 0000000..2543463 --- /dev/null +++ b/lib/sprinkle/installers/gem2.rb @@ -0,0 +1,65 @@ +module Sprinkle + module Installers + # Same as gem installer except it uses `gem2.0`. + # + # The installer has a single optional configuration: source. + # By changing source you can specify a given ruby gems + # repository from which to install. + # + # == Example Usage + # + # First, a simple installation of the magic_beans gem: + # + # package :magic_beans do + # description "Beans beans they're good for your heart..." + # gem2 'magic_beans' + # end + # + # Second, install magic_beans gem from github: + # + # package :magic_beans do + # gem2 'magic_beans_package' do + # source 'http://gems.github.com' + # end + # end + # + # As you can see, setting options is as simple as creating a + # block and calling the option as a method with the value as + # its parameter. + class Gem2 < Installer + + api do + def gem2(name, options = {}, &block) + recommends :rubygems + install Gem2.new(self, name, options, &block) + end + end + + attr_accessor :gem #:nodoc: + + def initialize(parent, gem, options = {}, &block) #:nodoc: + super parent, options, &block + @gem = gem + end + + attributes :source, :repository, :http_proxy, :build_flags, :version + # FIXME Why is ':build_docs' not included? + + protected + + # rubygems 0.9.5+ installs dependencies by default, and does platform selection + + def install_commands #:nodoc: + cmd = "#{sudo_cmd}gem2.0 install #{gem}" + cmd << " --version '#{version}'" if version + cmd << " --source #{source}" if source + cmd << " --install-dir #{repository}" if option?(:repository) + cmd << " --no-rdoc --no-ri" unless option?(:build_docs) + cmd << " --http-proxy #{http_proxy}" if option?(:http_proxy) + cmd << " -- #{build_flags}" if option?(:build_flags) + cmd + end + + end + end +end From 73d6e9c9d893fe79db3e89c75dd886864d0fc40e Mon Sep 17 00:00:00 2001 From: Jakukyo Friel Date: Mon, 11 Jul 2016 17:53:51 +0800 Subject: [PATCH 2/3] Merge `gem2.rb` to `gem.rb`. Add a new option to Gem installer: `gem_command`. --- lib/sprinkle/installers/gem.rb | 29 +++++++++++---- lib/sprinkle/installers/gem2.rb | 65 --------------------------------- 2 files changed, 21 insertions(+), 73 deletions(-) delete mode 100644 lib/sprinkle/installers/gem2.rb diff --git a/lib/sprinkle/installers/gem.rb b/lib/sprinkle/installers/gem.rb index 6b5d82a..8da1bc3 100644 --- a/lib/sprinkle/installers/gem.rb +++ b/lib/sprinkle/installers/gem.rb @@ -5,7 +5,7 @@ module Installers # The installer has a single optional configuration: source. # By changing source you can specify a given ruby gems # repository from which to install. - # + # # == Example Usage # # First, a simple installation of the magic_beans gem: @@ -23,33 +23,46 @@ module Installers # end # end # + # Third, specify the `gem` command: + # + # package :magic_beans do + # gem 'magic_beans' do + # gem_command '/usr/bin/gem2.0' # Or just `gem2.0`. + # end + # end + # # As you can see, setting options is as simple as creating a - # block and calling the option as a method with the value as + # block and calling the option as a method with the value as # its parameter. class Gem < Installer - + api do def gem(name, options = {}, &block) recommends :rubygems install Gem.new(self, name, options, &block) end end - + attr_accessor :gem #:nodoc: def initialize(parent, gem, options = {}, &block) #:nodoc: super parent, options, &block @gem = gem end - - attributes :source, :repository, :http_proxy, :build_flags, :version + + attributes :gem_command, :source, :repository, :http_proxy, :build_flags, :version protected # rubygems 0.9.5+ installs dependencies by default, and does platform selection def install_commands #:nodoc: - cmd = "#{sudo_cmd}gem install #{gem}" + if option?(:gem_command) + gem_cmd = gem_command + else + gem_cmd = 'gem' + end + cmd = "#{sudo_cmd}#{gem_cmd} install #{gem}" cmd << " --version '#{version}'" if version cmd << " --source #{source}" if source cmd << " --install-dir #{repository}" if option?(:repository) @@ -58,7 +71,7 @@ def install_commands #:nodoc: cmd << " -- #{build_flags}" if option?(:build_flags) cmd end - + end end end diff --git a/lib/sprinkle/installers/gem2.rb b/lib/sprinkle/installers/gem2.rb deleted file mode 100644 index 2543463..0000000 --- a/lib/sprinkle/installers/gem2.rb +++ /dev/null @@ -1,65 +0,0 @@ -module Sprinkle - module Installers - # Same as gem installer except it uses `gem2.0`. - # - # The installer has a single optional configuration: source. - # By changing source you can specify a given ruby gems - # repository from which to install. - # - # == Example Usage - # - # First, a simple installation of the magic_beans gem: - # - # package :magic_beans do - # description "Beans beans they're good for your heart..." - # gem2 'magic_beans' - # end - # - # Second, install magic_beans gem from github: - # - # package :magic_beans do - # gem2 'magic_beans_package' do - # source 'http://gems.github.com' - # end - # end - # - # As you can see, setting options is as simple as creating a - # block and calling the option as a method with the value as - # its parameter. - class Gem2 < Installer - - api do - def gem2(name, options = {}, &block) - recommends :rubygems - install Gem2.new(self, name, options, &block) - end - end - - attr_accessor :gem #:nodoc: - - def initialize(parent, gem, options = {}, &block) #:nodoc: - super parent, options, &block - @gem = gem - end - - attributes :source, :repository, :http_proxy, :build_flags, :version - # FIXME Why is ':build_docs' not included? - - protected - - # rubygems 0.9.5+ installs dependencies by default, and does platform selection - - def install_commands #:nodoc: - cmd = "#{sudo_cmd}gem2.0 install #{gem}" - cmd << " --version '#{version}'" if version - cmd << " --source #{source}" if source - cmd << " --install-dir #{repository}" if option?(:repository) - cmd << " --no-rdoc --no-ri" unless option?(:build_docs) - cmd << " --http-proxy #{http_proxy}" if option?(:http_proxy) - cmd << " -- #{build_flags}" if option?(:build_flags) - cmd - end - - end - end -end From 6995cf681e6adc3902928f3a2f7f9021ae2e5c73 Mon Sep 17 00:00:00 2001 From: Jakukyo Friel Date: Fri, 15 Jul 2016 00:15:12 +0800 Subject: [PATCH 3/3] `gem2()`: shortcut for `gem2.0` as `:gem_command`. Thanks to [yyyc514][]. [yyyc514]: https://github.com/sprinkle-tool/sprinkle/pull/210#issuecomment-232502781 --- lib/sprinkle/installers/gem.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/sprinkle/installers/gem.rb b/lib/sprinkle/installers/gem.rb index 8da1bc3..b56ede8 100644 --- a/lib/sprinkle/installers/gem.rb +++ b/lib/sprinkle/installers/gem.rb @@ -31,6 +31,14 @@ module Installers # end # end # + # There is an additional `gem2` installer: + # + # package :magic_beans do + # gem2 'magic_beans' + # end + # + # This is a shortcut for `gem` using `gem2.0` as value of `gem_command`. + # # As you can see, setting options is as simple as creating a # block and calling the option as a method with the value as # its parameter. @@ -41,6 +49,9 @@ def gem(name, options = {}, &block) recommends :rubygems install Gem.new(self, name, options, &block) end + def gem2(name, options = {}, &block) + gem(name, options.merge(:gem_command => 'gem2.0'), &block) + end end attr_accessor :gem #:nodoc: