Class: CreateRubyGem::CommandBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/create_ruby_gem/command_builder.rb

Overview

Converts a gem name and option hash into a bundle gem command array.

Examples:

entry = Compatibility::Matrix.for('3.1.0')
builder = CommandBuilder.new(compatibility_entry: entry)
builder.build(gem_name: 'my_gem', options: { exe: true, test: 'rspec' })
#=> ['bundle', 'gem', 'my_gem', '--exe', '--test=rspec']

Instance Method Summary collapse

Constructor Details

#initialize(compatibility_entry:) ⇒ CommandBuilder

Returns a new instance of CommandBuilder.

Parameters:



13
14
15
# File 'lib/create_ruby_gem/command_builder.rb', line 13

def initialize(compatibility_entry:)
  @compatibility_entry = compatibility_entry
end

Instance Method Details

#build(gem_name:, options: {}) ⇒ Array<String>

Builds the bundle gem command array.

Parameters:

  • gem_name (String)
  • options (Hash{Symbol => Object}) (defaults to: {})

Returns:

  • (Array<String>)


22
23
24
25
26
27
28
29
30
# File 'lib/create_ruby_gem/command_builder.rb', line 22

def build(gem_name:, options: {})
  command = ['bundle', 'gem', gem_name]
  Options::Catalog::ORDER.each do |key|
    next unless options.key?(key)

    append_option!(command, key, options[key])
  end
  command
end