Module: Evoke

Defined in:
lib/evoke.rb,
lib/evoke/cli.rb,
lib/evoke/task.rb,
lib/evoke/comment.rb,
lib/evoke/version.rb,
lib/evoke/parameters.rb,
lib/evoke/inflections.rb,
lib/evoke/inflections/camelize.rb,
lib/evoke/inflections/underscore.rb

Defined Under Namespace

Modules: Comment, Inflections, Parameters Classes: CLI, Task

Constant Summary collapse

VERSION =
'0.1.3'

Class Method Summary collapse

Class Method Details

.before_task(&block) ⇒ Object

Adds a code block that will be called before the task is invoked.

Examples:

Loading the Rails environment before running any Evoke tasks.


# File: evoke.rb - In the Rails application's root path

Evoke.before_task {|task, *args|
  require File.expand_path("../config/environment.rb", __FILE__)
}

Parameters:

  • &block (Proc)

    The code to execute before the task is invoked.



62
63
64
65
# File 'lib/evoke.rb', line 62

def before_task(&block)
  @before_hooks ||= []
  @before_hooks << block if block_given?
end

.find_task(name) ⇒ Evoke::Task

Finds a task with the supplied name.

Examples:

Find a task that has the class name ‘Example::HelloWorld`.


Evoke.find_task('example/hello_world') # => Example::HelloWorld

Parameters:

  • name (String)

    The underscored name of the task.

Returns:



24
25
26
# File 'lib/evoke.rb', line 24

def find_task(name)
  tasks.find { |task| task.to_s == name.camelize }
end

.invoke(task, *arguments) ⇒ Object

Creates an instance of a task, validates the amount of arguments supplied matches the task’s #invoke method, executes the #before_task callbacks, and invokes the task.

Parameters:

  • task (Class)

    The Evoke::Task class to invoke.

  • *arguments (Array)

    The arguments to invoke the task with.



73
74
75
76
77
78
# File 'lib/evoke.rb', line 73

def invoke(task, *arguments)
  task.validate_arguments(arguments)
  task = task.new
  Evoke.call_before_hooks(task, *arguments)
  task.invoke(*arguments)
end

.load_tasks(path, relative = true) ⇒ Array

Loads all the Evoke tasks in the supplied path.

Examples:

Loading tasks in the local “lib/tasks” folder.


Evoke.load_tasks("lib/tasks")

Loading tasks with an absolute path name.


path = File.expand_path("../lib/evoke", __FILE__)
Evoke.load_tasks(path, false)

Parameters:

  • path (String)

    The root path that contains the tasks.

  • relative (Boolean) (defaults to: true)

    Path is relative to working directory (default).

Returns:

  • (Array)

    The files that were loaded.



42
43
44
45
46
47
48
49
# File 'lib/evoke.rb', line 42

def load_tasks(path, relative=true)
  if relative
    path = File.join(Dir.pwd, path)
    path = File.expand_path(path)
  end

  Dir[File.join(path, '**', '*_task.rb')].each { |f| load f }
end

.tasksArray

Gets all the classes that descend from Evoke::Task.

Returns:

  • (Array)

    The task classes.



12
13
14
# File 'lib/evoke.rb', line 12

def tasks
  ObjectSpace.each_object(Class).select { |klass| klass < Evoke::Task }
end