Class: Hammer::CommandBuilder
- Inherits:
-
Object
- Object
- Hammer::CommandBuilder
- Defined in:
- lib/hammer/command_builder.rb
Overview
Context object for task :name do ... end blocks. Exposes
desc/example/opt/alt; the block's return value (a proc do |opts|)
becomes the command handler.
Instance Method Summary collapse
- #alt(*names) ⇒ Object
-
#cron(expr) ⇒ Object
Schedule this task for the
hammer h:cronjob server. - #desc(text) ⇒ Object
- #example(text) ⇒ Object
-
#initialize(cmd) ⇒ CommandBuilder
constructor
A new instance of CommandBuilder.
- #needs(*names) ⇒ Object
- #opt(name, **opts) ⇒ Object
Constructor Details
#initialize(cmd) ⇒ CommandBuilder
Returns a new instance of CommandBuilder.
6 7 8 |
# File 'lib/hammer/command_builder.rb', line 6 def initialize(cmd) @cmd = cmd end |
Instance Method Details
#alt(*names) ⇒ Object
22 23 24 |
# File 'lib/hammer/command_builder.rb', line 22 def alt(*names) names.each { |n| @cmd.add_alt(n) } end |
#cron(expr) ⇒ Object
Schedule this task for the hammer h:cron job server. Accepts a
5-field cron expression ('*/10 * * * *'), a simple interval ('10s',
'10m', '2h', '1d') or a shortcut (@hourly, @daily, @weekly,
@monthly). Validated immediately, so a typo fails at Hammerfile load.
34 35 36 |
# File 'lib/hammer/command_builder.rb', line 34 def cron(expr) @cmd.set_cron(expr) end |
#desc(text) ⇒ Object
10 11 12 |
# File 'lib/hammer/command_builder.rb', line 10 def desc(text) @cmd.instance_variable_set(:@desc, text.to_s.rstrip) end |
#example(text) ⇒ Object
14 15 16 |
# File 'lib/hammer/command_builder.rb', line 14 def example(text) @cmd.add_example(text) end |
#needs(*names) ⇒ Object
26 27 28 |
# File 'lib/hammer/command_builder.rb', line 26 def needs(*names) names.each { |n| @cmd.add_need(n) } end |