Module: SyncWrap::RubySupport

Included in:
CRubyVM, JRubyVM
Defined in:
lib/syncwrap/ruby_support.rb

Overview

A Support module for Ruby VM components, also providing gem handling utilties which are largely common to all Ruby VMs.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#gem_commandObject

The name of the gem command to be installed/used (default: gem)



24
25
26
# File 'lib/syncwrap/ruby_support.rb', line 24

def gem_command
  @gem_command
end

#gem_install_argsObject

Default gem install arguments (default: –no-rdoc, –no-ri)



27
28
29
# File 'lib/syncwrap/ruby_support.rb', line 27

def gem_install_args
  @gem_install_args
end

Instance Method Details

#gem_install(gem, opts = {}) ⇒ Object

Install the specified gem.

Options

:version

Version specifier array or single value, like in a gemspec. (Default: nil -> latest) Examples:

'1.1.0'
'~> 1.1'
['>=1.0', '<1.2']
:user_install

If true, perform a –user-install as the current user. Otherwise system install with sudo (the default, false).

:check

If true, capture output and return the number of gems actually installed. Combine with :minimize to only install what is required, and short circuit when zero gems installed. (Default: false)

:minimize

Use –conservative and –minimal-deps (rubygems 2.1.5+, #min_deps_supported?) flags to reduce installs to the minimum required to satisfy the version requirements. (Default: true)



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/syncwrap/ruby_support.rb', line 70

def gem_install( gem, opts = {} )
  cmd = [ gem_command, 'install',
          gem_install_args,
          ( '--user-install' if opts[ :user_install ] ),
          ( '--conservative' if opts[ :minimize] != false ),
          ( '--minimal-deps' if opts[ :minimize] != false &&
            min_deps_supported? ),
          gem_version_flags( opts[ :version ] ),
          gem ].flatten.compact.join( ' ' )

  shopts = opts[ :user_install ] ? {} : {user: :root}

  if opts[ :check ]
    _,out = capture( cmd, shopts.merge!( accept: 0 ) )

    count = 0
    out.split( "\n" ).each do |oline|
      if oline =~ /^\s+(\d+)\s+gem(s)?\s+installed/
        count = $1.to_i
      end
    end
    count
  else
    sh( cmd, shopts )
  end

end

#gemrc_pathObject



36
37
38
# File 'lib/syncwrap/ruby_support.rb', line 36

def gemrc_path
  "/etc/gemrc"
end

#initialize(*args) ⇒ Object



29
30
31
32
33
34
# File 'lib/syncwrap/ruby_support.rb', line 29

def initialize( *args )
  @gem_command = 'gem'
  @gem_install_args = %w[ --no-rdoc --no-ri ]

  super( *args )
end

#install_gemrcObject

Install gemrc file to gemrc_path



41
42
43
# File 'lib/syncwrap/ruby_support.rb', line 41

def install_gemrc
  rput( 'etc/gemrc', gemrc_path, user: :root )
end