rakext 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 by Domizio Demichelis
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,86 @@
1
+ # rakext
2
+
3
+ Lite and powerful rake extension.
4
+
5
+ Rakext allows you to create rake tasks by just writing methods. Besides, you can pass tasks arguments as ruby code, YAML or JSON strings and they will be evaluated as you expect.
6
+
7
+ ## Task Usage
8
+
9
+ You can define your own modules and `include Rakext::Tasks` in order to create your tasks:
10
+
11
+ ```ruby
12
+ # file 'my_tasks.rb'
13
+ module MyTasks
14
+ include Rakext::Tasks
15
+ # the default prefix would be 'my_tasks:'
16
+ prefix 'my_pref:'
17
+
18
+ desc 'this is the my_pref:foo - args(opts)'
19
+ def foo(opts)
20
+ print 'received arguments: '
21
+ p opts
22
+ end
23
+
24
+ module NestedNamespace
25
+ include Rakext::Tasks
26
+ # uses the default prefix 'my_task:nested_namespace:'
27
+
28
+ desc 'this is the my_task:nested_namespace:bar - args(a,b,c)'
29
+ def bar(a, b, c)
30
+ print 'received arguments: '
31
+ p a, b, c
32
+ end
33
+
34
+ end
35
+ end
36
+ ```
37
+
38
+ In the Rakefile:
39
+
40
+ ```ruby
41
+ require 'rakext'
42
+ require 'my_tasks'
43
+ ```
44
+
45
+ Check the tasks:
46
+
47
+ ```sh
48
+ $ rake -T
49
+ rake my_pref:foo # this is the my_pref:foo - args(opts)
50
+ rake my_tasks:nested_namespace:bar # this is the my_task:nested_namespace:bar - args(a,b,c)
51
+ ```
52
+
53
+ ## CLI Usage
54
+
55
+ A few examples about passing args:
56
+
57
+ ```sh
58
+ # pure rake
59
+ $ rake my_pref:foo RUBY_ARGS='a:"foo", b: "bar"'
60
+ $ rake my_task:nested_namespace:bar RUBY_ARGS='{a:4,b:3}, "a", "b"'
61
+
62
+ # need rakext for multiline args (rake does not parse them correctly)
63
+ $ rakext my_pref:foo YAML_ARGS='
64
+ ---
65
+ :a: foo
66
+ :b: bar
67
+ '
68
+
69
+ $ rakext my_task:nested_namespace:bar JSON_ARGS='
70
+ [{"a":4,"b":3}, "a", "b"]
71
+ '
72
+ ```
73
+
74
+ ## Try it
75
+
76
+ Look at the 2 files in [test](./rakext/blob/master/test) to see how it works. You may also run `. text.sh` to try it.
77
+
78
+ ## Tips and tricks
79
+
80
+ Since the `rakext` bin is exactly the same `rake` bin with just an added `m` multiline flag, you can symlink it so you will always use `rakext` when you type `rake`.
81
+
82
+ ## Copyright
83
+
84
+ Copyright (c) 2012 by [Domizio Demichelis](mailto://dd.nexus@gmail.com)<br>
85
+ See [LICENSE](./rakext/blob/master/LICENSE) for details.
86
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # This bin does exactly what rake does, but allows to use multiline arguments that
4
+ # rake does not parse correctly, so we fix the collect_tasks method.
5
+
6
+ begin
7
+ require 'rubygems'
8
+ rescue LoadError
9
+ end
10
+
11
+ require 'rake'
12
+
13
+ require 'rake/application'
14
+ module Rake
15
+ class Application
16
+ # Fixes the RegEx that doesn't parse correctly multiline args
17
+ def collect_tasks
18
+ @top_level_tasks = []
19
+ ARGV.each do |arg|
20
+ if arg =~ /^(\w+)=(.*)$/m # m is needed for multiline parsing
21
+ ENV[$1] = $2
22
+ else
23
+ @top_level_tasks << arg unless arg =~ /^-/
24
+ end
25
+ end
26
+ @top_level_tasks.push("default") if @top_level_tasks.size == 0
27
+ end
28
+ end
29
+ end
30
+
31
+ Rake.application.run
@@ -0,0 +1,53 @@
1
+ require 'rake'
2
+ require 'yaml'
3
+ require 'multi_json'
4
+
5
+ module Rakext
6
+ module Tasks
7
+ def self.included(base)
8
+ base.class_eval do
9
+ extend self
10
+ @prefix = ( p = name.gsub('::', ':')
11
+ p.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
12
+ p.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
13
+ p.downcase!
14
+ "#{p}:" )
15
+ end
16
+ end
17
+
18
+ def method_added(meth)
19
+ return unless public_instance_methods.include?(meth) || public_instance_methods.include?(meth.to_sym)
20
+ args = Rakext.get_args
21
+ m = method(meth.to_sym)
22
+ Rake::Task.define_task("#{@prefix}#{meth}") do
23
+ args.is_a?(Hash) ? m.call(args) : m.call(*args)
24
+ end
25
+ end
26
+
27
+ def desc(description)
28
+ Rake.application.last_description = description
29
+ end
30
+
31
+ def prefix(p=nil)
32
+ p.nil? ? @prefix : @prefix = p
33
+ end
34
+ end
35
+
36
+ def self.get_args
37
+ case
38
+ when ENV['RUBY_ARGS']
39
+ a = ENV['RUBY_ARGS'].strip
40
+ a = a[1..-2] if a =~ /^\(.*\)$/
41
+ eval("echo(#{a})")
42
+ when ENV['YAML_ARGS']
43
+ YAML.load(ENV['YAML_ARGS'])
44
+ when ENV['JSON_ARGS']
45
+ MultiJson.decode(ENV['JSON_ARGS'])
46
+ end
47
+ end
48
+
49
+ private
50
+ def self.echo(*a); a end
51
+
52
+ end
53
+
@@ -0,0 +1,22 @@
1
+ require 'date'
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'rakext'
5
+ s.authors = ["Domizio Demichelis"]
6
+ s.email = 'dd.nexus@gmail.com'
7
+ s.homepage = 'http://github.com/ddnexus/ake'
8
+ s.summary = 'Lite and powerful rake extension'
9
+ s.description = 'Rakext allows you to create rake tasks by just writing methods. Besides, you can pass tasks arguments as ruby code, YAML or JSON strings and they will be evaluated as you expect.'
10
+ s.executables = ['rakext']
11
+ s.extra_rdoc_files = ["README.md"]
12
+ s.require_paths = ["lib"]
13
+ s.files = `git ls-files -z`.split("\0")
14
+ s.version = File.read(File.expand_path('../VERSION', __FILE__)).strip
15
+ s.date = Date.today.to_s
16
+ s.required_rubygems_version = ">= 1.3.6"
17
+ s.rdoc_options = ["--charset=UTF-8"]
18
+
19
+ s.add_runtime_dependency 'multi_json', '~> 1.3.4'
20
+ s.add_runtime_dependency 'rake', '~> 0.9.2.2'
21
+ end
22
+
@@ -0,0 +1,29 @@
1
+ require 'rakext'
2
+
3
+ module TopLevel
4
+ include Rakext::Tasks
5
+ prefix 'my_pref:'
6
+
7
+ desc 'this is the my_pref:task_a - args(opts)'
8
+ def task_a(opts)
9
+ print 'received arguments: '
10
+ p opts
11
+ end
12
+
13
+ module NestedNamespace
14
+ include Rakext::Tasks
15
+
16
+ desc 'this is the top_level:nested_namespace:task_b - args(a,b,c)'
17
+ def task_b(a, b, c)
18
+ print 'received arguments: '
19
+ p a, b, c
20
+ end
21
+
22
+ end
23
+ end
24
+
25
+ desc 'get_args task, will just echo the passed args'
26
+ task 'get_args' do
27
+ print 'received arguments: '
28
+ p Rakext.get_args
29
+ end
@@ -0,0 +1,49 @@
1
+ echo %%% RAKEXT TRANSFORMS YOUR METHODS IN RAKE TASKS %%%
2
+ echo
3
+ echo $ rakext -T
4
+ RUBYLIB=../lib ../bin/rakext -T
5
+ echo
6
+
7
+ echo %%% YOU CAN PASS ARGUMENTS IN RUBY CODE %%%
8
+ echo
9
+ echo $ rakext my_pref:task_a RUBY_ARGS=\'\{a:4,b:3\'\}
10
+ RUBYLIB=../lib ../bin/rakext my_pref:task_a RUBY_ARGS='{a:4,b:3}'
11
+ echo
12
+
13
+ echo $ rakext my_pref:task_a RUBY_ARGS=\"a:4,b:3\"
14
+ RUBYLIB=../lib ../bin/rakext my_pref:task_a RUBY_ARGS="a:4,b:3"
15
+ echo
16
+
17
+ echo $ rakext my_pref:task_a RUBY_ARGS='(a:"4",b:3)'
18
+ RUBYLIB=../lib ../bin/rakext my_pref:task_a RUBY_ARGS='(a:"4",b:3)'
19
+ echo
20
+
21
+ echo $ rakext top_level:nested_namespace:task_b RUBY_ARGS=\'1,2,3\'
22
+ RUBYLIB=../lib ../bin/rakext top_level:nested_namespace:task_b RUBY_ARGS='1,2,3'
23
+ echo
24
+
25
+ echo $ rakext top_level:nested_namespace:task_b RUBY_ARGS=\'[1,2,3], \"foo\", \"bar\"\'
26
+ RUBYLIB=../lib ../bin/rakext top_level:nested_namespace:task_b RUBY_ARGS='[1,2,3], "foo", "bar"'
27
+ echo
28
+
29
+ echo %%% YOU CAN PASS ARGUMENTS IN YAML %%%
30
+ echo
31
+ echo $ rakext my_pref:task_a YAML_ARGS=\'---
32
+ echo :a: 4
33
+ echo :b: 3
34
+ echo \'
35
+ RUBYLIB=../lib ../bin/rakext get_args YAML_ARGS='---
36
+ :a: 4
37
+ :b: 3
38
+ '
39
+ echo
40
+ echo %%% YOU CAN PASS ARGUMENTS IN JSON %%%
41
+ echo
42
+
43
+ echo $ rakext my_pref:task_a JSON_ARGS=\'
44
+ echo {\"a\": 4, \"b\": 3}
45
+ echo \'
46
+ RUBYLIB=../lib ../bin/rakext my_pref:task_a JSON_ARGS='
47
+ {"a": 4, "b": 3}
48
+ '
49
+ echo
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rakext
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Domizio Demichelis
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: multi_json
16
+ requirement: &70356619482580 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.3.4
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70356619482580
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &70356619482120 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 0.9.2.2
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70356619482120
36
+ description: Rakext allows you to create rake tasks by just writing methods. Besides,
37
+ you can pass tasks arguments as ruby code, YAML or JSON strings and they will be
38
+ evaluated as you expect.
39
+ email: dd.nexus@gmail.com
40
+ executables:
41
+ - rakext
42
+ extensions: []
43
+ extra_rdoc_files:
44
+ - README.md
45
+ files:
46
+ - LICENSE
47
+ - README.md
48
+ - VERSION
49
+ - bin/rakext
50
+ - lib/rakext.rb
51
+ - rakext.gemspec
52
+ - test/Rakefile
53
+ - test/test.sh
54
+ homepage: http://github.com/ddnexus/ake
55
+ licenses: []
56
+ post_install_message:
57
+ rdoc_options:
58
+ - --charset=UTF-8
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: 1.3.6
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 1.8.10
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: Lite and powerful rake extension
79
+ test_files: []
80
+ has_rdoc: