Class: Scripting::Commands::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/scripting/commands.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, name) ⇒ Command

Returns a new instance of Command.



7
8
9
10
11
12
# File 'lib/scripting/commands.rb', line 7

def initialize app, name
  @app = app
  @name = name.to_s.downcase.to_sym
  @description = nil
  @work = lambda {} # noop by default
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/scripting/commands.rb', line 5

def name
  @name
end

Instance Method Details

#describe(&blk) ⇒ Object



14
15
16
17
# File 'lib/scripting/commands.rb', line 14

def describe &blk
  instance_eval &blk if block_given?
  self
end

#description(desc = nil) ⇒ Object



19
20
21
22
23
24
# File 'lib/scripting/commands.rb', line 19

def description desc=nil
  unless desc.nil?
    @description = desc
  end
  @description
end

#run!(*args) ⇒ Object



31
32
33
# File 'lib/scripting/commands.rb', line 31

def run! *args
  @app.instance_exec(*args, &work)
end

#work(&blk) ⇒ Object



26
27
28
29
# File 'lib/scripting/commands.rb', line 26

def work &blk
  @work = blk if block_given?
  @work
end