class EpubForge::Action::ActionDefinition

Public Instance Methods

default( name, value ) click to toggle source
# File lib/epubforge/action/action_definition.rb, line 33
def default( name, value )
  (@default_args ||= {})[name] = value
end
execute( &block ) click to toggle source
# File lib/epubforge/action/action_definition.rb, line 11
def execute( &block )
  proc( block )
end
project_not_required() click to toggle source
# File lib/epubforge/action/action_definition.rb, line 57
def project_not_required
  @project_required = false
end
project_required?() click to toggle source

Most actions require – nay, demand! – a project to act upon. Add the line ‘project_not_required’ to the class definition to keep it from failing out if it can’t find an existing project. Used for things like initializing new projects, printing help, or… my imagination fails me.

# File lib/epubforge/action/action_definition.rb, line 51
def project_required?
  @project_required = true if @project_required.nil?
  @project_required
end
run( *args ) click to toggle source
# File lib/epubforge/action/action_definition.rb, line 15
def run( *args )
  action = klass.new    # one of the action classes (New or Git or Epub, etc.)
  puts( "Sending args to Action(#{self.keyword}) : #{ 'NO ARGS' if args.fwf_blank? }".paint(:pink) ) if EpubForge.gem_test_mode?
  for arg, i in args.each_with_index
    puts "    #{i}: #{arg.inspect}".paint(:pink) if verbose?
  end
  
  if args.first.is_a?(Project)
    action.project( args.first )
    action.args( args[1..-1] )
  else
    action.args( args )
  end
  
  action.instance_exec( &@proc )
end