Class: Shellissimo::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/shellissimo/command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, description = "", aliases = [], param_definitions = [], &block) ⇒ Command

Returns a new instance of Command.



8
9
10
11
12
# File 'lib/shellissimo/command.rb', line 8

def initialize(name, description = "", aliases = [],  param_definitions = [], &block)
  @name, @description = CommandName.new(name, aliases), String(description)
  @param_definitions = Array(param_definitions)
  self.block = block
end

Instance Attribute Details

#aliasesObject (readonly)

Returns the value of attribute aliases.



6
7
8
# File 'lib/shellissimo/command.rb', line 6

def aliases
  @aliases
end

#blockObject

Returns the value of attribute block.



6
7
8
# File 'lib/shellissimo/command.rb', line 6

def block
  @block
end

#descriptionObject (readonly)

Returns the value of attribute description.



6
7
8
# File 'lib/shellissimo/command.rb', line 6

def description
  @description
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/shellissimo/command.rb', line 6

def name
  @name
end

#param_definitionsObject (readonly)

Returns the value of attribute param_definitions.



6
7
8
# File 'lib/shellissimo/command.rb', line 6

def param_definitions
  @param_definitions
end

Instance Method Details

#call(*args) ⇒ Object Also known as: []



24
25
26
# File 'lib/shellissimo/command.rb', line 24

def call(*args)
  block.call(*args)
end

#prepend_params(params) ⇒ Object



18
19
20
21
22
# File 'lib/shellissimo/command.rb', line 18

def prepend_params(params)
  params = filter_params(params)
  old_block = block # let's fool ruby
  dup.tap { |c| c.block = proc { instance_exec(params, &old_block) } }
end

#to_procObject



29
30
31
# File 'lib/shellissimo/command.rb', line 29

def to_proc
  block
end