Module: Oxidized::Model::DSLCommands

Included in:
Oxidized::Model
Defined in:
lib/oxidized/model/dslcommands.rb

Overview

Domain Specific Language for model commands

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#procsObject (readonly)

output



57
58
59
# File 'lib/oxidized/model/dslcommands.rb', line 57

def procs
  @procs
end

Instance Method Details

#cmd(cmd_arg = nil, **args, &block) ⇒ Object

Store a command to be run against the device cmd_arg can be:

- a string (the command to be run)
- a symbol:
  - :all    - run the block against each command output
  - :secret - run the block against each command output when
              vars :remove_secret is true
  - :significant_changes - use the block to remove unsignificant
              changes

Optional arguments (**args):

  • clear: true

    replace all the stored blocks for this command (monkey patching)
    
  • prepend: true

    prepend the block to the stored blocks for this command (monkey
    patching)
    
  • if: lambda

    run the command only if the lambda evaluates to true
    
  • input: symbol or array of symbols

    for the inputs this command is to run against (default - run
    every command)
    


25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/oxidized/model/dslcommands.rb', line 25

def cmd(cmd_arg = nil, **args, &block)
  if cmd_arg.instance_of?(Symbol)
    process_args_block(@cmd[cmd_arg], args, block)
  else
    return unless valid_cmd_args?(cmd_arg, args)

    # Always use an array for :input
    args[:input] = Array(args[:input]) if args.include?(:input)
    process_args_block(@cmd[:cmd], args,
                       { cmd: cmd_arg, args: args, block: block })
  end
  logger.debug "Added #{cmd_arg} to the commands list"
end

#cmdsObject



39
40
41
# File 'lib/oxidized/model/dslcommands.rb', line 39

def cmds
  @cmd
end

#post(**args, &block) ⇒ Object

calls the block at the end of the model, adding the output of the block to the output string



51
52
53
# File 'lib/oxidized/model/dslcommands.rb', line 51

def post(**args, &block)
  process_args_block(@procs[:post], args, block)
end

#pre(**args, &block) ⇒ Object

calls the block at the end of the model, prepending the output of the block to the output string



45
46
47
# File 'lib/oxidized/model/dslcommands.rb', line 45

def pre(**args, &block)
  process_args_block(@procs[:pre], args, block)
end