Class: Dev::Ruby
- 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
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
-
#container_path ⇒ Object
Returns the value of attribute container_path.
-
#coverage ⇒ Object
Returns the value of attribute coverage.
-
#local_path ⇒ Object
Returns the value of attribute local_path.
-
#package_file ⇒ Object
Returns the value of attribute package_file.
Class Method Summary collapse
-
.config {|@config| ... } ⇒ Object
(also: 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.
-
.version ⇒ Object
Returns the version of the ruby executable running on the system.
Instance Method Summary collapse
-
#audit_command ⇒ Object
Build the command which can be use to perform a security audit report.
-
#base_command ⇒ Object
The base npm command that is the starting point for all subsequent commands.
-
#check_test_coverage(application:) ⇒ Object
Run the check to ensure code coverage meets the desired threshold.
-
#check_version ⇒ Object
Checks the min and max version against the current ruby version if they have been configured.
-
#initialize(container_path: nil, local_path: nil, package_file: nil, coverage: nil) ⇒ Ruby
constructor
A new instance of Ruby.
-
#install_command ⇒ Object
Build the bundle install command.
-
#lint_command ⇒ Object
Build the bundle lint command.
-
#lint_fix_command ⇒ Object
Build the bundle lint fix command.
-
#test_command ⇒ Object
Build the bundle test command.
Constructor Details
#initialize(container_path: nil, local_path: nil, package_file: nil, coverage: nil) ⇒ Ruby
Returns a new instance of Ruby.
43 44 45 46 47 48 49 50 51 |
# File 'lib/firespring_dev_commands/ruby.rb', line 43 def initialize(container_path: nil, local_path: nil, package_file: nil, coverage: 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 @coverage = coverage || Dev::Coverage::None.new raise 'coverage must be an instance of the base class' unless @coverage.is_a?(Dev::Coverage::Base) check_version end |
Instance Attribute Details
#container_path ⇒ Object
Returns the value of attribute container_path.
41 42 43 |
# File 'lib/firespring_dev_commands/ruby.rb', line 41 def container_path @container_path end |
#coverage ⇒ Object
Returns the value of attribute coverage.
41 42 43 |
# File 'lib/firespring_dev_commands/ruby.rb', line 41 def coverage @coverage end |
#local_path ⇒ Object
Returns the value of attribute local_path.
41 42 43 |
# File 'lib/firespring_dev_commands/ruby.rb', line 41 def local_path @local_path end |
#package_file ⇒ Object
Returns the value of attribute package_file.
41 42 43 |
# File 'lib/firespring_dev_commands/ruby.rb', line 41 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
26 27 28 29 30 |
# File 'lib/firespring_dev_commands/ruby.rb', line 26 def config @config ||= Config.new yield(@config) if block_given? @config end |
.version ⇒ Object
Returns the version of the ruby executable running on the system
36 37 38 |
# File 'lib/firespring_dev_commands/ruby.rb', line 36 def version @version ||= RUBY_VERSION end |
Instance Method Details
#audit_command ⇒ Object
Build the command which can be use to perform a security audit report
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/firespring_dev_commands/ruby.rb', line 68 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_command ⇒ Object
The base npm command that is the starting point for all subsequent commands
63 64 65 |
# File 'lib/firespring_dev_commands/ruby.rb', line 63 def base_command ['bundle'] end |
#check_test_coverage(application:) ⇒ Object
Run the check to ensure code coverage meets the desired threshold
121 122 123 |
# File 'lib/firespring_dev_commands/ruby.rb', line 121 def check_test_coverage(application:) coverage.check(application:) end |
#check_version ⇒ Object
Checks the min and max version against the current ruby version if they have been configured
54 55 56 57 58 59 60 |
# File 'lib/firespring_dev_commands/ruby.rb', line 54 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_command ⇒ Object
Build the bundle install command
88 89 90 91 92 93 |
# File 'lib/firespring_dev_commands/ruby.rb', line 88 def install_command install = base_command install << 'install' install.concat(Dev::Common.new.tokenize(ENV['OPTS'].to_s)) install end |
#lint_command ⇒ Object
Build the bundle lint command
96 97 98 99 100 101 |
# File 'lib/firespring_dev_commands/ruby.rb', line 96 def lint_command lint = base_command lint << 'exec' << 'rake' << 'lint' lint.concat(Dev::Common.new.tokenize(ENV['OPTS'].to_s)) lint end |
#lint_fix_command ⇒ Object
Build the bundle lint fix command
104 105 106 107 108 109 |
# File 'lib/firespring_dev_commands/ruby.rb', line 104 def lint_fix_command lint_fix = base_command lint_fix << 'exec' << 'rake' << 'lint:fix' lint_fix.concat(Dev::Common.new.tokenize(ENV['OPTS'].to_s)) lint_fix end |
#test_command ⇒ Object
Build the bundle test command
112 113 114 115 116 117 118 |
# File 'lib/firespring_dev_commands/ruby.rb', line 112 def test_command test = base_command test << 'exec' << 'rake' << 'test' test.concat(coverage.) if coverage test.concat(Dev::Common.new.tokenize(ENV['OPTS'].to_s)) test end |