Module: Bundler::GemBytes::Actions

Included in:
ScriptExecutor
Defined in:
lib/bundler/gem_bytes/actions.rb,
lib/bundler/gem_bytes/actions/gemspec.rb,
lib/bundler/gem_bytes/actions/gemspec/attribute.rb,
lib/bundler/gem_bytes/actions/gemspec/dependency.rb,
lib/bundler/gem_bytes/actions/gemspec/attribute_node.rb,
lib/bundler/gem_bytes/actions/gemspec/dependency_node.rb,
lib/bundler/gem_bytes/actions/gemspec/delete_dependency.rb,
lib/bundler/gem_bytes/actions/gemspec/gem_specification.rb,
lib/bundler/gem_bytes/actions/gemspec/upsert_dependency.rb

Overview

The API for GemBytes templates

Defined Under Namespace

Classes: Gemspec

Instance Method Summary collapse

Instance Method Details

#gemspec(gemspec_path: Dir['*.gemspec'].first) {|gemspec_name, gemspec| ... } ⇒ void

This method returns an undefined value.

The gemspec at ‘gemspec_path` is updated per instructions in `action_block`

Examples:

Adding a runtime dependency

actions = Actions.new
actions.gemspec(gemspec_path: 'test.gemspec') do
  add_runtime_dependency 'rubocop', '~> 1.68'
end

Parameters:

  • gemspec_path (String) (defaults to: Dir['*.gemspec'].first)

    the path to the gemspec file to process

    Defaults to the first gemspec file found in the current directory.

Yields:

  • a block with instructions to modify the gemspec

    This block is run in the context of a Gemspec instance. The instructions are methods defined by this instance (e.g. ‘add_dependency`, `remove_dependency`, etc.)

Yield Parameters:

  • gemspec_name (Symbol)

    the name of the Gem::Specification varaible used in the gemspec

  • gemspec (Gem::Specification)

    the evaluated gemspec

Yield Returns:

  • (String)

    the updated gemspec



33
34
35
36
37
38
# File 'lib/bundler/gem_bytes/actions.rb', line 33

def gemspec(gemspec_path: Dir['*.gemspec'].first, &action_block)
  source = File.read(gemspec_path)
  action = Bundler::GemBytes::Actions::Gemspec.new(context: self)
  updated_source = action.call(source, source_path: gemspec_path, &action_block)
  File.write(gemspec_path, updated_source)
end