Class: EpubForge::Action::ActionDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/epubforge/action/action_definition.rb

Instance Method Summary collapse

Instance Method Details

#default(name, value) ⇒ Object



33
34
35
# File 'lib/epubforge/action/action_definition.rb', line 33

def default( name, value )
  (@default_args ||= {})[name] = value
end

#execute(&block) ⇒ Object



11
12
13
# File 'lib/epubforge/action/action_definition.rb', line 11

def execute( &block )
  proc( block )
end

#project_not_requiredObject



57
58
59
# File 'lib/epubforge/action/action_definition.rb', line 57

def project_not_required
  @project_required = false
end

#project_required?Boolean

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.

Returns:

  • (Boolean)


51
52
53
54
# File 'lib/epubforge/action/action_definition.rb', line 51

def project_required?
  @project_required = true if @project_required.nil?
  @project_required
end

#run(*args) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 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