Class: Ridley::CommandContext::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/ridley-connectors/command_context.rb

Overview

A base class to provide common functionality between OS specific command contexts. A command context takes an options hash and binds it against a template file. You can then retrieve the command to be run on a node by calling #command.

Examples:

my_context = MyCommandContext.new(message: "hello, world!")
my_context.command #=> "echo 'hello, world!'"

Direct Known Subclasses

Unix, Windows

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.

Parameters:

  • options (Hash) (defaults to: {})


36
# File 'lib/ridley-connectors/command_context.rb', line 36

def initialize(options = {}); end

Class Method Details

.command(options = {}) ⇒ Object

Build a command context and immediately run it’s command

Parameters:

  • options (Hash) (defaults to: {})

    an options hash to pass to the new CommandContext



18
19
20
# File 'lib/ridley-connectors/command_context.rb', line 18

def command(options = {})
  new(options).command
end

.template_file(filename = nil) ⇒ Pathname

Set or get the path to the template file for the inheriting class

Parameters:

  • filename (String) (defaults to: nil)

    the filename (without extension) of the template file to use to bind the inheriting command context class to

Returns:

  • (Pathname)


29
30
31
32
# File 'lib/ridley-connectors/command_context.rb', line 29

def template_file(filename = nil)
  return @template_file if filename.nil?
  @template_file = Ridley::Connectors.scripts.join("#{filename}.erb")
end

Instance Method Details

#commandString

Returns:

  • (String)


39
40
41
# File 'lib/ridley-connectors/command_context.rb', line 39

def command
  template.evaluate(self)
end