Class: Dev::Ruby

Inherits:
Object show all
Defined in:
lib/firespring_dev_commands/ruby.rb,
lib/firespring_dev_commands/ruby/audit.rb

Overview

Class containing methods related to ruby application

Defined Under Namespace

Classes: Audit, Config

Constant Summary collapse

DEFAULT_PATH =

The default path of the application inside the container

'/usr/src/app'.freeze
DEFAULT_PACKAGE_FILE =

The default name of the ruby package file

'Gemfile'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(container_path: nil, local_path: nil, package_file: nil) ⇒ Ruby



42
43
44
45
46
47
# File 'lib/firespring_dev_commands/ruby.rb', line 42

def initialize(container_path: nil, local_path: nil, package_file: nil)
  @container_path = container_path || self.class.config.container_path
  @local_path = local_path || self.class.config.local_path
  @package_file = package_file || self.class.config.package_file
  check_version
end

Instance Attribute Details

#container_pathObject

Returns the value of attribute container_path.



40
41
42
# File 'lib/firespring_dev_commands/ruby.rb', line 40

def container_path
  @container_path
end

#local_pathObject

Returns the value of attribute local_path.



40
41
42
# File 'lib/firespring_dev_commands/ruby.rb', line 40

def local_path
  @local_path
end

#package_fileObject

Returns the value of attribute package_file.



40
41
42
# File 'lib/firespring_dev_commands/ruby.rb', line 40

def package_file
  @package_file
end

Class Method Details

.config {|@config| ... } ⇒ Object Also known as: configure

Instantiates a new top level config object if one hasn’t already been created Yields that config object to any given block Returns the resulting config object

Yields:



25
26
27
28
29
# File 'lib/firespring_dev_commands/ruby.rb', line 25

def config
  @config ||= Config.new
  yield(@config) if block_given?
  @config
end

.versionObject

Returns the version of the ruby executable running on the system



35
36
37
# File 'lib/firespring_dev_commands/ruby.rb', line 35

def version
  @version ||= RUBY_VERSION
end

Instance Method Details

#audit_commandObject

Build the command which can be use to perform a security audit report



64
65
66
67
68
69
70
71
72
73
# File 'lib/firespring_dev_commands/ruby.rb', line 64

def audit_command
  audit = base_command
  audit << 'audit' << 'check'
  audit << '--format' << 'json'
  audit.concat(Dev::Common.new.tokenize(ENV['OPTS'].to_s))
  audit << '2>&1' << '||' << 'true'

  # Run the command as part of a shell script
  ['sh', '-c', audit.join(' ')]
end

#base_commandObject

The base npm command that is the starting point for all subsequent commands



59
60
61
# File 'lib/firespring_dev_commands/ruby.rb', line 59

def base_command
  ['bundle']
end

#check_versionObject

Checks the min and max version against the current ruby version if they have been configured



50
51
52
53
54
55
56
# File 'lib/firespring_dev_commands/ruby.rb', line 50

def check_version
  min_version = self.class.config.min_version
  raise "requires ruby version >= #{min_version} (found #{self.class.version})" if min_version && !Dev::Common.new.version_greater_than(min_version, self.class.version)

  max_version = self.class.config.max_version
  raise "requires ruby version < #{max_version} (found #{self.class.version})" if max_version && Dev::Common.new.version_greater_than(max_version, self.class.version)
end

#install_commandObject

Build the bundle install command



84
85
86
87
88
89
# File 'lib/firespring_dev_commands/ruby.rb', line 84

def install_command
  install = base_command
  install << 'install'
  install.concat(Dev::Common.new.tokenize(ENV['OPTS'].to_s))
  install
end

#lint_commandObject

Build the bundle lint command



92
93
94
95
96
# File 'lib/firespring_dev_commands/ruby.rb', line 92

def lint_command
  lint = ['rubocop']
  lint.concat(Dev::Common.new.tokenize(ENV['OPTS'].to_s))
  lint
end

#lint_fix_commandObject

Build the bundle lint fix command



99
100
101
102
103
104
# File 'lib/firespring_dev_commands/ruby.rb', line 99

def lint_fix_command
  lint_fix = ['rubocop']
  lint_fix << '-A'
  lint_fix.concat(Dev::Common.new.tokenize(ENV['OPTS'].to_s))
  lint_fix
end

#test_commandObject

Build the bundle test command



107
108
109
110
111
# File 'lib/firespring_dev_commands/ruby.rb', line 107

def test_command
  test = ['rspec']
  test.concat(Dev::Common.new.tokenize(ENV['OPTS'].to_s))
  test
end