Class: RCoLi::Program

Inherits:
Object
  • Object
show all
Includes:
CommandContainer, Help
Defined in:
lib/rcoli/model.rb

Instance Attribute Summary

Attributes included from CommandContainer

#parent

Instance Method Summary collapse

Methods included from CommandContainer

#action, #command, #commands, #find_command, #flag, #get_action, #options, #parse_args, #put_default_values, #switch, #validate_options

Methods included from Help

#help, #template

Instance Method Details

#execute(args, context) ⇒ Object



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# File 'lib/rcoli/model.rb', line 200

def execute(args, context)
  result = ParsedArgs.new
  put_default_values(result)      
  parse_args(args, result)
  validate_options(result, :global_options)
  if result.command
    
    # command has to have the action block
    action = result.command.get_action
    raise ApplicationError, "Invalid configuration. Missing action block." unless action
    
    # enable/disable logging level DEBUG
    if (result.global_options['debug'])
      context.instance_exec do
        log.level = Logger::DEBUG
      end
    end
    
    # enable dev mode
    if (result.global_options['dev-mode'])
      ApplicationContext.instance.devmode = true
    end
    
    # execution of the pre block
    context.instance_exec(result.global_options, result.options, result.arguments, &@pre_action) if (@pre_action and !result.command.value_of_skip_pre) 
    # execution of the main block
    context.instance_exec(result.global_options, result.options, result.arguments, &action)
    # execution of the post block
    context.instance_exec(result.global_options, result.options, result.arguments, &@post_action) if (@post_action and !result.command.value_of_skip_post) 
  else
    say "This feature is comming soon. You should execute '#{value_of_name} help' now."
  end
end

#post(&block) ⇒ Object



238
239
240
# File 'lib/rcoli/model.rb', line 238

def post(&block)
  @post_action = block
end

#pre(&block) ⇒ Object



234
235
236
# File 'lib/rcoli/model.rb', line 234

def pre(&block)
  @pre_action = block
end