nake 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG CHANGED
@@ -26,3 +26,6 @@
26
26
  = Version 0.0.6
27
27
  * Cucumber features
28
28
  * DSL helper rule
29
+
30
+ = Version 0.0.7
31
+ * Added Task#boot method for setting some stuff after other tasks boot
data/bin/nake CHANGED
@@ -6,22 +6,6 @@ require "nake"
6
6
  require "nake/args"
7
7
  require "nake/helpers"
8
8
 
9
- # TODO: what if I want to run:
10
- # ./bin/nake -T
11
- # ./bin/nake --verbose -T
12
- # ./examples/flags.rb --verbose
13
-
14
- # First file in arguments is separator between args for nake and for task
15
- # If there is no file in the arguments
16
- # co kdyz omezim tasky na list etc a nebudou moct mit --task etc?
17
- # nake --verbose list arg1 arg2 --with-something
18
- # => zmizi potreba aliasu
19
- # => potreba API pro mapovani na -T etc
20
- # Nake.args["-T"] = Nake::Task[:tasks]
21
-
22
- # !!!!!! --verbose neni runable task to jen switchuje naky shity, takze -T by melo fungovat tak, ze naplni Nake.parse[:task] s taskem co se ma runnout
23
- # First argument has to be path to file with your tasks
24
-
25
9
  # parse arguments
26
10
  begin
27
11
  Nake.parse
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ./bin/nake
2
+
3
+ # You might want to give more useful description, however you don't have access
4
+ # to some variables so far ... at least with Rake. Nake provides boot method which
5
+ # run after everything is loaded, and if you specify optional dependencies for the
6
+ # boot method, it will run the boot block of specified tasks first. This might come
7
+ # handy time to time, but usually it's enough to use it without arguments since you
8
+ # usually need just to load the whole task file where is all the configuration.
9
+
10
+ # Typical usecases:
11
+ # - you want to provide concrete info in description
12
+ # - you need to access configuration of a task on other place than in the define block
13
+
14
+ Task.new(:build) do |task|
15
+ task.boot(:release) do
16
+ task.description = "Release version #{Task[:release].config[:version]}"
17
+ end
18
+ end
@@ -1,5 +1,8 @@
1
1
  #!/usr/bin/env ./bin/nake
2
2
 
3
+ # You can do the same by adding Task[name].call in the define block, but please,
4
+ # don't use this approach. Dependencies are readable and if someone wants to,
5
+ # he can simply remove a dependency from the dependency array.
3
6
  task(:greet1)
4
7
  task(:greet2)
5
8
 
File without changes
@@ -1,5 +1,8 @@
1
1
  #!/usr/bin/env cucumber
2
2
 
3
+ # ./bin/nake -T
4
+ # ./bin/nake --verbose -T
5
+ # ./examples/flags.rb --verbose
3
6
  Feature: Running bin/nake
4
7
  Scenario: Running bin/nake without any arguments
5
8
  When I run "./bin/nake"
@@ -3,7 +3,7 @@
3
3
  require "nake/task"
4
4
 
5
5
  module Nake
6
- VERSION ||= "0.0.6"
6
+ VERSION ||= "0.0.7"
7
7
  def self.verbose
8
8
  @@verbose
9
9
  rescue NameError
@@ -79,6 +79,7 @@ module Nake
79
79
  # @since 0.0.1
80
80
  # @author Jakub Stastny
81
81
  def self.run_task
82
+ Task.boot
82
83
  name, *args = Nake.parse[:task]
83
84
  task = Task[name]
84
85
  if name.nil?
@@ -7,6 +7,8 @@ argument("-H", "--help") do
7
7
  end
8
8
 
9
9
  argument("-T", "--tasks") do |pattern = nil|
10
+ Task.boot
11
+
10
12
  tasks, options = Task.tasks.select { |name, task| not task.hidden? }.sort.partition { |key, value| not key.match(/^-/) }
11
13
  arguments = Nake.args.sort
12
14
 
@@ -31,6 +33,7 @@ argument("-T", "--tasks") do |pattern = nil|
31
33
  end
32
34
 
33
35
  argument("-i", "--interactive") do |task = nil|
36
+ Task.boot
34
37
  ARGV.clear # otherwise IRB will parse it
35
38
 
36
39
  require "irb"
@@ -9,14 +9,7 @@ module Nake
9
9
 
10
10
  class Task
11
11
  def self.[](name)
12
- name = name.to_s
13
- self.tasks[name] || self.find_in_aliases(name)
14
- end
15
-
16
- # @private
17
- def self.find_in_aliases(name)
18
- _, task = self.tasks.find { |_, task| task.aliases.include?(name) }
19
- return task
12
+ self.tasks[name.to_s]
20
13
  end
21
14
 
22
15
  def self.[]=(name, task)
@@ -28,6 +21,12 @@ module Nake
28
21
  @@tasks ||= Hash.new
29
22
  end
30
23
 
24
+ def self.boot
25
+ self.tasks.each do |name, task|
26
+ task.boot!
27
+ end
28
+ end
29
+
31
30
  # return existing task if task with given name already exist
32
31
  def self.new(name, *dependencies, &block)
33
32
  task = self[name]
@@ -35,16 +34,9 @@ module Nake
35
34
  end
36
35
 
37
36
  attr_accessor :name, :description, :dependencies, :hidden, :original_args
38
- attr_reader :blocks, :aliases
37
+ attr_reader :blocks
39
38
  def initialize(name, *dependencies, &block)
40
- @aliases, @hidden = Array.new, false
41
- # This is a bit weird, but it's best solution
42
- # when we want to keep API simple and keep it
43
- # as one object even if it has more names
44
- if name.respond_to?(:join) # array
45
- name, *aliases = name
46
- self.aliases.push(*aliases)
47
- end
39
+ @hidden = false
48
40
  @name, @blocks = name.to_sym, Array.new
49
41
  @dependencies = Array.new
50
42
  self.register
@@ -95,27 +87,48 @@ module Nake
95
87
  note "Executing task #{name} with arguments #{args.inspect} and options #{options.inspect}"
96
88
  debug "Config #{self.config.inspect}"
97
89
  self.blocks.each do |block|
98
- # we can't use arity, because it returns 0 for lambda { |options = Hash.new| }.arity
99
- # if we define method with one optional argument, it will returns -1
90
+ block.call(*args, options)
91
+ end
92
+ end
93
+ end
100
94
 
101
- if RUBY_VERSION >= "1.9.2"
102
- raise ArgumentError, "Task can't take block arguments" if args.length + 1 > block.parameters.select { |type, name| type.eql?(:req) || type.eql?(:opt) }.length
103
- raise ArgumentError, "Task can't take block arguments" if block.parameters.any? { |type, name| type.eql?(:block) }
104
- end
95
+ def bootloaders
96
+ @bootloaders ||= Array.new
97
+ end
98
+
99
+ def boot_dependencies
100
+ @boot_dependencies ||= Array.new
101
+ end
102
+
103
+ def boot(*dependencies, &block)
104
+ self.boot_dependencies.push(*dependencies)
105
+ self.bootloaders.push(block)
106
+ end
105
107
 
106
- if RUBY_VERSION >= "1.9.2" && block.parameters.empty?
107
- block.call
108
- else
109
- block.call(*args, options)
108
+ def boot!
109
+ unless self.boot_dependencies.empty? && self.bootloaders.empty?
110
+ note "Booting #{self.name}"
111
+ end
112
+ while dependency = self.boot_dependencies.shift
113
+ self.class[dependency].tap do |task|
114
+ if task.nil?
115
+ raise TaskNotFound, "Task #{dependency} doesn't exist!"
110
116
  end
117
+ task.boot!
111
118
  end
112
119
  end
120
+ while block = self.bootloaders.shift
121
+ block.call
122
+ end
123
+ end
124
+
125
+ def booted?
126
+ self.bootloaders.empty? && self.boot_dependencies.empty?
113
127
  end
114
128
 
115
129
  def reset!
116
130
  self.dependencies.clear
117
131
  self.blocks.clear
118
- self.aliases.clear
119
132
  end
120
133
 
121
134
  protected
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nake
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Jakub \xC5\xA0\xC5\xA5astn\xC3\xBD aka Botanicus"
@@ -38,6 +38,7 @@ files:
38
38
  - CHANGELOG
39
39
  - examples/arguments.rb
40
40
  - examples/basic.rb
41
+ - examples/boot.rb
41
42
  - examples/complex.rb
42
43
  - examples/configuration.rb
43
44
  - examples/default.rb
@@ -47,10 +48,10 @@ files:
47
48
  - examples/helpers.rb
48
49
  - examples/invoking.rb
49
50
  - examples/script.rb
50
- - examples/setup.rb
51
51
  - examples/task_arguments.rb
52
52
  - features/arguments.feature
53
53
  - features/basic.feature
54
+ - features/boot.feature
54
55
  - features/builtin_arguments.feature
55
56
  - features/complex.feature
56
57
  - features/configuration.feature
@@ -63,7 +64,6 @@ files:
63
64
  - features/helpers.feature
64
65
  - features/invoking.feature
65
66
  - features/script.feature
66
- - features/setup.feature
67
67
  - features/steps.rb
68
68
  - features/task_arguments.feature
69
69
  - lib/nake/args.rb
@@ -104,8 +104,7 @@ licenses: []
104
104
 
105
105
  post_install_message: |-
106
106
  === Changes in the last Nake ===
107
- - Cucumber features
108
- - DSL helper rule
107
+ - Added Task#boot method for setting some stuff after other tasks boot
109
108
  rdoc_options: []
110
109
 
111
110
  require_paths:
@@ -1,24 +0,0 @@
1
- #!/usr/bin/env ./bin/nake
2
-
3
- # NOTE: this isn't implemented yet!
4
- # THERE MIGHT TO BE USEFUL TO HAVE BASE CLASS FOR TASK, BECAUSE FILE TASK DOESN'T HAVE ALIASES ETC
5
- Task.new(:build) do |task|
6
- task.description = "Release version #{Task[:release].config[:version]}" # but release task might not exist yet
7
- end
8
-
9
- # soo ...
10
- Task.new(:build) do |task|
11
- task.setup do |variable|
12
- task.description = "Release version #{Task[:release].config[:version]}"
13
- end
14
- end
15
-
16
- # hodi se hlavne pro descriptions a pro pushovani veci do dependencies, protoze z dependencies se daji odstranit, kdezto z procu, kde se invokujou explicitne, to jde fakt tezko
17
- # setup task se vola na zacatku Nake.run
18
-
19
- # advanced ...
20
- Task.new(:build) do |task|
21
- task.setup(:release, :other_task) do |variable|
22
- task.description = "Release version #{Task[:release].config[:version]}"
23
- end
24
- end