Method: Rbeapi::Api::Entity#command_builder

Defined in:
lib/rbeapi/api.rb

#command_builder(cmd, opts = {}) ⇒ String

Method called to build the correct version of a command based on the modifier options. If value option is set then it is appended to the command. If the enable option is false then the ‘no’ keyword is prefixed to the command. If the default value is provided and set to true, then the default keyword is used. If both options are provided, then default option takes precedence.

Parameters:

  • cmd (String, Array)

    The commands to send to the node over the API connection to configure the system.

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

    The options for the command.

Options Hash (opts):

  • value (String)

    Optional value that is appended to the command if set.

  • enable (Boolean)

    Prefix the command with ‘no’. Default is true.

  • default (Boolean)

    Configure the command using the default keyword. Default is false.

Returns:

  • (String)

    Returns built command string.



158
159
160
161
162
163
164
165
# File 'lib/rbeapi/api.rb', line 158

def command_builder(cmd, opts = {})
  enable = opts.fetch(:enable, true)
  default = opts.fetch(:default, false)
  cmd << " #{opts[:value]}" if opts[:value]
  return "default #{cmd}" if default
  return "no #{cmd}" unless enable
  cmd
end