evoke 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +3 -0
- data/CODE_OF_CONDUCT.md +27 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +129 -0
- data/Rakefile +9 -0
- data/bin/console +7 -0
- data/bin/setup +5 -0
- data/evoke.gemspec +23 -0
- data/exe/evoke +9 -0
- data/lib/evoke/cli.rb +84 -0
- data/lib/evoke/inflections/camelize.rb +35 -0
- data/lib/evoke/inflections/underscore.rb +38 -0
- data/lib/evoke/inflections.rb +11 -0
- data/lib/evoke/task.rb +44 -0
- data/lib/evoke/version.rb +3 -0
- data/lib/evoke.rb +89 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: de1ac06c3626655a6e1d041392fd749cfde7c820
|
4
|
+
data.tar.gz: 7d634505e1b52a26b03bc2aaef687678f458d62e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3bef13d6b793bbdaa4225cdf375579a2788e05b3dd47fa508ce301ce2e9f4c6809b847d69f26d127a3773b974866b833b6a37fd82468c22761ea20bd93e76a2e
|
7
|
+
data.tar.gz: 9b12056349fedfbbf8845e135f1303a574b6e8a637c13fa77b3a252894fa63ce67b070f4c777b739780c5a9464e29af8fe8b2f58dc6cf80af8a25fbb646d466b
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people
|
4
|
+
who contribute through reporting issues, posting feature requests, updating
|
5
|
+
documentation, submitting pull requests or patches, and other activities.
|
6
|
+
|
7
|
+
We are committed to making participation in this project a harassment-free
|
8
|
+
experience for everyone, regardless of level of experience, gender, gender
|
9
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
10
|
+
body size, race, age, or religion.
|
11
|
+
|
12
|
+
Examples of unacceptable behavior by participants include the use of sexual
|
13
|
+
language or imagery, derogatory comments or personal attacks, trolling, public
|
14
|
+
or private harassment, insults, or other unprofessional conduct.
|
15
|
+
|
16
|
+
Project maintainers have the right and responsibility to remove, edit, or reject
|
17
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
18
|
+
not aligned to this Code of Conduct. Project maintainers who do not follow the
|
19
|
+
Code of Conduct may be removed from the project team.
|
20
|
+
|
21
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
22
|
+
reported by opening an issue or contacting one or more of the project
|
23
|
+
maintainers.
|
24
|
+
|
25
|
+
This Code of Conduct is adapted from the
|
26
|
+
[Contributor Covenant](http:contributor-covenant.org),
|
27
|
+
[version 1.0.0](http://contributor-covenant.org/version/1/0/0/).
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Travis Haynes
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
# Evoke
|
2
|
+
|
3
|
+
A lightweight, zero-dependency task tool for Ruby.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
$ gem install evoke
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
### Writing Tasks
|
12
|
+
|
13
|
+
Evoke tasks are Ruby classes that look like this:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
class HelloWorld < Evoke::Task
|
17
|
+
# This description appears when your run `evoke` without any arguments.
|
18
|
+
desc "Prints a friendly message"
|
19
|
+
|
20
|
+
# This method is called by Evoke when the task is executed.
|
21
|
+
def invoke
|
22
|
+
puts "Hello world!"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
```
|
26
|
+
|
27
|
+
**Important:** Initializers for Evoke::Tasks cannot have any required arguments.
|
28
|
+
|
29
|
+
This task would be invoked from the command-line with `evoke hello_world`.
|
30
|
+
|
31
|
+
#### Namespacing
|
32
|
+
|
33
|
+
Tasks are namespaced using modules. Their command names are underscored from
|
34
|
+
their Ruby class names. For example, a task named `Example::HelloWorld` would be
|
35
|
+
invoked on the command line with `evoke example/hello_world`.
|
36
|
+
|
37
|
+
#### Command-line-arguments
|
38
|
+
|
39
|
+
Here's an example of a task that uses command-line arguments and is namespaced.
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
module Math
|
43
|
+
class Add < Evoke::Task
|
44
|
+
desc "Adds two integers and prints the result in the console"
|
45
|
+
|
46
|
+
def invoke(a, b)
|
47
|
+
puts a.to_i + b.to_i
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
```
|
52
|
+
|
53
|
+
**Note:** All arguments come through as strings since they are read from the
|
54
|
+
command-line.
|
55
|
+
|
56
|
+
This task would be invoked from the command-line with `evoke math/add 5 10`,
|
57
|
+
where a=5 and b=10 in this example.
|
58
|
+
|
59
|
+
Switches are not currently supported. Use environment variables to use named
|
60
|
+
arguments. Here's the same example as above using environment variables:
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
module Math
|
64
|
+
class Add < Evoke::Task
|
65
|
+
desc "Adds two integers and prints the result in the console"
|
66
|
+
|
67
|
+
def initialize
|
68
|
+
@a = ENV['A'].to_i
|
69
|
+
@b = ENV['B'].to_i
|
70
|
+
end
|
71
|
+
|
72
|
+
def invoke
|
73
|
+
puts @a + @b
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
```
|
78
|
+
|
79
|
+
This task would be invoked from the command-line with `evoke math/add A=5 B=10`.
|
80
|
+
|
81
|
+
### Loading Tasks
|
82
|
+
|
83
|
+
There are two ways tasks can be loaded.
|
84
|
+
|
85
|
+
1. Place the tasks in the working directory's lib/tasks folder and end the file
|
86
|
+
names with `_task.rb`.
|
87
|
+
2. Create a file named `evoke.rb` and load the tasks manually or place them
|
88
|
+
directly in that file.
|
89
|
+
|
90
|
+
Running `evoke` from the command line will scan the current working directory.
|
91
|
+
It will first search for a file named `evoke.rb`. If found, Evoke will assume
|
92
|
+
this file takes care of loading the tasks. Otherwise the `lib/tasks` folder will
|
93
|
+
be recursively searched for `_task.rb` files, which will be loaded in the order
|
94
|
+
they are found.
|
95
|
+
|
96
|
+
Here's an example `evoke.rb` file for using Evoke with a Rails application:
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
# Searches the lib/evoke folder for _task.rb files and loads them.
|
100
|
+
Evoke.load_tasks('lib/evoke')
|
101
|
+
|
102
|
+
# Load the Rails environment before a task is invoked.
|
103
|
+
Evoke.before_task do |task, *args|
|
104
|
+
require File.expand_path("../config/environment.rb", __FILE__)
|
105
|
+
end
|
106
|
+
```
|
107
|
+
|
108
|
+
Note that the Rails environment is loaded in a #before_task callback. This makes
|
109
|
+
sure that the environment only loads when the task is actually being invoked,
|
110
|
+
and not when the user is simply trying to list the available tasks or made a
|
111
|
+
mistake in the task's name or arguments.
|
112
|
+
|
113
|
+
## Development
|
114
|
+
|
115
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
116
|
+
`bin/console` for an interactive prompt that will allow you to experiment.
|
117
|
+
|
118
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To
|
119
|
+
release a new version, update the version number in `version.rb`, and then run
|
120
|
+
`bundle exec rake release` to create a git tag for the version, push git commits
|
121
|
+
and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
122
|
+
|
123
|
+
## Contributing
|
124
|
+
|
125
|
+
1. [Fork it](https://github.com/travishaynes/evoke/fork)
|
126
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
127
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
128
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
129
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/setup
ADDED
data/evoke.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'evoke/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'evoke'
|
8
|
+
spec.version = Evoke::VERSION
|
9
|
+
spec.authors = ['Travis Haynes']
|
10
|
+
spec.email = ['travis@hi5dev.com']
|
11
|
+
|
12
|
+
spec.summary = 'A build tool for Ruby.'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
|
+
spec.bindir = 'exe'
|
17
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_development_dependency 'bundler', '~> 1.8'
|
21
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
22
|
+
spec.add_development_dependency 'minitest', '~> 5.5.1'
|
23
|
+
end
|
data/exe/evoke
ADDED
data/lib/evoke/cli.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
module Evoke
|
2
|
+
# The command-line-interface for Evoke.
|
3
|
+
class CLI
|
4
|
+
def initialize
|
5
|
+
@command = ARGV.shift
|
6
|
+
@arguments = ARGV.dup
|
7
|
+
|
8
|
+
ARGV.clear
|
9
|
+
end
|
10
|
+
|
11
|
+
# Starts the CLI. This will check lib/tasks in the current working directory
|
12
|
+
# for evoke tasks and invoke the task supplied on the command line.
|
13
|
+
def start
|
14
|
+
load_tasks
|
15
|
+
|
16
|
+
return usage if @command.nil?
|
17
|
+
|
18
|
+
task = Evoke.find_task(@command) unless @command.nil?
|
19
|
+
|
20
|
+
return unknown_command if task.nil?
|
21
|
+
|
22
|
+
Evoke.invoke(task, *@arguments)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Prints the usage for all the discovered tasks.
|
26
|
+
def usage
|
27
|
+
name_col_size = task_names.group_by(&:size).keys.max + 2
|
28
|
+
tasks.each {|task| task.print_usage(name_col_size) }
|
29
|
+
|
30
|
+
exit(2)
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
# Gets the path for the local evoke.rb file. This doesn't check if the file
|
36
|
+
# actually exists, it only returns the location where it might be.
|
37
|
+
#
|
38
|
+
# @return [String] The path for the evoke file.
|
39
|
+
def evoke_file
|
40
|
+
@evoke_file = File.join(Dir.pwd, "evoke.rb")
|
41
|
+
end
|
42
|
+
|
43
|
+
# Loads the Evoke tasks. This will first search for a file named `evoke.rb`
|
44
|
+
# in the current working directory. If one is found it will be loaded. If
|
45
|
+
# none is found the default working directory's lib/tasks folder will be
|
46
|
+
# used to load the tasks.
|
47
|
+
def load_tasks
|
48
|
+
return load(evoke_file) if File.file?(evoke_file)
|
49
|
+
|
50
|
+
# Load the tasks from the current working directory.
|
51
|
+
Evoke.load_tasks("lib/tasks")
|
52
|
+
|
53
|
+
# No reason to continue if there are no tasks to work with.
|
54
|
+
return no_tasks if tasks.empty?
|
55
|
+
end
|
56
|
+
|
57
|
+
# Tells the user there are no tasks to invoke and exits with status 1.
|
58
|
+
def no_tasks
|
59
|
+
STDERR.puts "No tasks found in the current working directory."
|
60
|
+
exit(1)
|
61
|
+
end
|
62
|
+
|
63
|
+
# Tells the user that the supplied task could not be found.
|
64
|
+
def unknown_command
|
65
|
+
STDERR.puts "No task for #{@command.inspect}"
|
66
|
+
exit(1)
|
67
|
+
end
|
68
|
+
|
69
|
+
# Finds and caches all the Evoke tasks.
|
70
|
+
#
|
71
|
+
# @return [Array] The tasks.
|
72
|
+
def tasks
|
73
|
+
@tasks ||= Evoke.tasks
|
74
|
+
end
|
75
|
+
|
76
|
+
# Gets the underscored names of all the tasks and caches it. These are the
|
77
|
+
# names are that used on the command line.
|
78
|
+
#
|
79
|
+
# @return [Array] The name of all the tasks.
|
80
|
+
def task_names
|
81
|
+
@task_names ||= tasks.map {|task| task.name.underscore }
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# String inflections for converting to CamelCase.
|
2
|
+
#
|
3
|
+
# Camelizing a string takes all the compound words separated by an underscore
|
4
|
+
# and combines them together, capitalizing the first letter of each word. It
|
5
|
+
# also converts '/' to '::'. For example "hello_world" is camelized to
|
6
|
+
# "HelloWorld", and "hello/world" is camelized to "Hello::World".
|
7
|
+
module Evoke::Inflections::Camelize
|
8
|
+
# Converts a string to CamelCase. It also converts '/' to '::'.
|
9
|
+
#
|
10
|
+
# @example Camelize the string "example/hello_world".
|
11
|
+
#
|
12
|
+
# "example/hello_world".camelize # => "Example::HelloWorld"
|
13
|
+
#
|
14
|
+
# @return [String] The CamelCase string.
|
15
|
+
def camelize
|
16
|
+
dup.tap {|s|
|
17
|
+
s.capitalize!
|
18
|
+
s.gsub!(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{$2.capitalize}" }
|
19
|
+
s.gsub!("/", "::")
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
# Replaces the existing String instance with a CamelCase string.
|
24
|
+
#
|
25
|
+
# @example Camelizing the string "example/hello_world".
|
26
|
+
#
|
27
|
+
# string = "example/hello_world"
|
28
|
+
# string.camelize!
|
29
|
+
# string # => "Example::HelloWorld"
|
30
|
+
#
|
31
|
+
# @return [String] This string modified to CamelCase.
|
32
|
+
def camelize!
|
33
|
+
replace(camelize)
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# String inflections for converting to underscored form.
|
2
|
+
#
|
3
|
+
# Underscoring a string injects an underscore between CamelCase words, replaces
|
4
|
+
# all '::' with '/' and converts the string to lowercase. For example, the
|
5
|
+
# string "HelloWorld" is underscored to "hello_world", and the string
|
6
|
+
# "Hello::World" is underscored to "hello/world".
|
7
|
+
module Evoke::Inflections::Underscore
|
8
|
+
# Creates an underscored, lowercase form of the string and changes '::' to '/'
|
9
|
+
# to convert namespaces to paths.
|
10
|
+
#
|
11
|
+
# @example Underscoring "Example::HelloWorld".
|
12
|
+
#
|
13
|
+
# "Example::HelloWorld" # => "example/hello_world"
|
14
|
+
#
|
15
|
+
# @return [String] The underscored string.
|
16
|
+
def underscore
|
17
|
+
dup.tap {|s|
|
18
|
+
s.gsub!(/::/, '/')
|
19
|
+
s.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
|
20
|
+
s.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
|
21
|
+
s.tr!("-", "_")
|
22
|
+
s.downcase!
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
# Replaces the existing String instance with its underscored form.
|
27
|
+
#
|
28
|
+
# @example Underscoring the string "Example::HelloWorld".
|
29
|
+
#
|
30
|
+
# string = "Example::HelloWorld"
|
31
|
+
# string.underscore!
|
32
|
+
# string # => "example/hello_world"
|
33
|
+
#
|
34
|
+
# @return [String] This underscored form of the original string.
|
35
|
+
def underscore!
|
36
|
+
replace(underscore)
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Evoke
|
2
|
+
# Inflections define new methods on the String class to transform names for
|
3
|
+
# different purposes.
|
4
|
+
module Inflections
|
5
|
+
# Load the inflections.
|
6
|
+
Dir[File.expand_path("../inflections/*.rb", __FILE__)].each {|f| require f }
|
7
|
+
|
8
|
+
# Add the inflections to the String class.
|
9
|
+
constants.each {|i| String.send(:include, const_get(i)) }
|
10
|
+
end
|
11
|
+
end
|
data/lib/evoke/task.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
module Evoke
|
2
|
+
class Task
|
3
|
+
class << self
|
4
|
+
# Prints the usage of this task to the console.
|
5
|
+
#
|
6
|
+
# @param [Integer] name_col_size The size of the name column.
|
7
|
+
# @private
|
8
|
+
def print_usage(name_col_size)
|
9
|
+
$stdout.print name.underscore.ljust(name_col_size)
|
10
|
+
$stdout.puts "# #{@desc || 'No description.'}"
|
11
|
+
end
|
12
|
+
|
13
|
+
# Describes the task. This message will be printed to the console when
|
14
|
+
# evoke is called without any arguments.
|
15
|
+
#
|
16
|
+
# @note All descriptions end with a period. One will be added if missing.
|
17
|
+
#
|
18
|
+
# @param [String] value The description. Keep it short!
|
19
|
+
# @return [String] The supplied description.
|
20
|
+
def desc(value)
|
21
|
+
value += "." unless value.end_with?(?.)
|
22
|
+
@desc = value
|
23
|
+
end
|
24
|
+
|
25
|
+
# Ensures that the task's #invoke method has the same amount of arguments
|
26
|
+
# as the user supplied on the command-line. If not, an error message is
|
27
|
+
# printed to STDERR and Evoke is terminated with an exit-status of 1.
|
28
|
+
#
|
29
|
+
# @param [Array] arguments The arguments to validate.
|
30
|
+
# @return nil if the validation passes.
|
31
|
+
# @private
|
32
|
+
def validate_arguments(arguments)
|
33
|
+
e_size = instance_method(:invoke).arity
|
34
|
+
a_size = Array(arguments).size
|
35
|
+
|
36
|
+
return if e_size == a_size
|
37
|
+
|
38
|
+
$stderr.print "Wrong number of arguments. "
|
39
|
+
$stderr.print "Received #{a_size} instead of #{e_size}.\n"
|
40
|
+
exit(1)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/evoke.rb
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'evoke/version'
|
2
|
+
require 'evoke/task'
|
3
|
+
|
4
|
+
module Evoke
|
5
|
+
require 'evoke/inflections'
|
6
|
+
|
7
|
+
class << self
|
8
|
+
# Gets all the classes that descend from Evoke::Task.
|
9
|
+
#
|
10
|
+
# @return [Array] The task classes.
|
11
|
+
def tasks
|
12
|
+
ObjectSpace.each_object(Class).select {|klass| klass < Evoke::Task }
|
13
|
+
end
|
14
|
+
|
15
|
+
# Finds a task with the supplied name.
|
16
|
+
#
|
17
|
+
# @param [String] name The underscored name of the task.
|
18
|
+
# @return [Evoke::Task] The task or nil if not found.
|
19
|
+
# @example Find a task that has the class name `Example::HelloWorld`.
|
20
|
+
#
|
21
|
+
# Evoke.find_task('example/hello_world') # => Example::HelloWorld
|
22
|
+
#
|
23
|
+
def find_task(name)
|
24
|
+
tasks.find {|task| task.to_s == name.camelize }
|
25
|
+
end
|
26
|
+
|
27
|
+
# Loads all the Evoke tasks in the supplied path.
|
28
|
+
#
|
29
|
+
# @example Loading tasks in the local "lib/tasks" folder.
|
30
|
+
#
|
31
|
+
# Evoke.load_tasks("lib/tasks")
|
32
|
+
#
|
33
|
+
# @example Loading tasks with an absolute path name.
|
34
|
+
#
|
35
|
+
# path = File.expand_path("../lib/evoke", __FILE__)
|
36
|
+
# Evoke.load_tasks(path, false)
|
37
|
+
#
|
38
|
+
# @param [String] path The root path that contains the tasks.
|
39
|
+
# @param [Boolean] relative Path is relative to working directory (default).
|
40
|
+
# @return [Array] The files that were loaded.
|
41
|
+
def load_tasks(path, relative=true)
|
42
|
+
if relative
|
43
|
+
path = File.join(Dir.pwd, path)
|
44
|
+
path = File.expand_path(path)
|
45
|
+
end
|
46
|
+
|
47
|
+
Dir[File.join(path, "**", "*_task.rb")].each {|f| load f }
|
48
|
+
end
|
49
|
+
|
50
|
+
# Adds a code block that will be called before the task is invoked.
|
51
|
+
#
|
52
|
+
# @param [Proc] &block The code to execute before the task is invoked.
|
53
|
+
# @example Loading the Rails environment before running any Evoke tasks.
|
54
|
+
#
|
55
|
+
# # File: evoke.rb - In the Rails application's root path
|
56
|
+
#
|
57
|
+
# Evoke.before_task {|task, *args|
|
58
|
+
# require File.expand_path("../config/environment.rb", __FILE__)
|
59
|
+
# }
|
60
|
+
#
|
61
|
+
def before_task(&block)
|
62
|
+
@before_hooks ||= []
|
63
|
+
@before_hooks << block if block_given?
|
64
|
+
end
|
65
|
+
|
66
|
+
# Creates an instance of a task, validates the amount of arguments supplied
|
67
|
+
# matches the task's #invoke method, executes the #before_task callbacks,
|
68
|
+
# and invokes the task.
|
69
|
+
#
|
70
|
+
# @param [Class] task The Evoke::Task class to invoke.
|
71
|
+
# @param [Array] *arguments The arguments to invoke the task with.
|
72
|
+
def invoke(task, *arguments)
|
73
|
+
task.validate_arguments(arguments)
|
74
|
+
task = task.new
|
75
|
+
Evoke.call_before_hooks(task, *arguments)
|
76
|
+
task.invoke(*arguments)
|
77
|
+
end
|
78
|
+
|
79
|
+
protected
|
80
|
+
|
81
|
+
# Executes the before callbacks.
|
82
|
+
#
|
83
|
+
# @param [Evoke::Task] task The task instance that is being invoked.
|
84
|
+
# @param [Array] args The arguments that are being passed to the task.
|
85
|
+
def call_before_hooks(task, *args)
|
86
|
+
Array(@before_hooks).each {|hook| hook.call(*args) }
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: evoke
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Travis Haynes
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.8'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 5.5.1
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 5.5.1
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- travis@hi5dev.com
|
58
|
+
executables:
|
59
|
+
- evoke
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- .travis.yml
|
65
|
+
- CODE_OF_CONDUCT.md
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/console
|
71
|
+
- bin/setup
|
72
|
+
- evoke.gemspec
|
73
|
+
- exe/evoke
|
74
|
+
- lib/evoke.rb
|
75
|
+
- lib/evoke/cli.rb
|
76
|
+
- lib/evoke/inflections.rb
|
77
|
+
- lib/evoke/inflections/camelize.rb
|
78
|
+
- lib/evoke/inflections/underscore.rb
|
79
|
+
- lib/evoke/task.rb
|
80
|
+
- lib/evoke/version.rb
|
81
|
+
homepage:
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
metadata: {}
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 2.2.2
|
102
|
+
signing_key:
|
103
|
+
specification_version: 4
|
104
|
+
summary: A build tool for Ruby.
|
105
|
+
test_files: []
|