hen 0.0.1.142 → 0.0.2.144

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == VERSION
4
4
 
5
- This documentation refers to hen version 0.0.1
5
+ This documentation refers to hen version 0.0.2
6
6
 
7
7
 
8
8
  == DESCRIPTION
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ require 'hen'
4
4
  require 'hen/version'
5
5
 
6
6
  task(:doc_spec) {{
7
- :title => 'hen Application documentation',
7
+ :title => 'hen Application documentation'
8
8
  }}
9
9
 
10
10
  task(:gem_spec) {{
@@ -14,7 +14,8 @@ task(:gem_spec) {{
14
14
  :summary => "Hoe or Echoe? No, thanks! Just a Rake helper " <<
15
15
  "that fits my own personal style.",
16
16
  :files => FileList['lib/**/*.rb', 'bin/*'].to_a,
17
- :extra_files => FileList['[A-Z]*', 'lib/hens/*.rake', 'example/*', 'example/.henrc'].to_a
17
+ :extra_files => FileList['[A-Z]*', 'lib/hens/*.rake', 'example/*', 'example/.henrc'].to_a,
18
+ :dependencies => %w[rubyforge]
18
19
  }}
19
20
 
20
- Hen.lay
21
+ Hen.lay!
@@ -20,4 +20,4 @@ task(:gem_spec) {{
20
20
  :dependencies => %w[hyper magic]
21
21
  }}
22
22
 
23
- Hen.lay
23
+ Hen.lay!
data/lib/hen.rb CHANGED
@@ -30,15 +30,18 @@ require 'rake'
30
30
  require 'yaml'
31
31
 
32
32
  require 'hen/dsl'
33
+ require 'hen/errors'
33
34
 
34
- module Hen
35
+ class Hen
35
36
 
36
- extend self
37
+ # The directory (directories?) with the hen files
38
+ # TODO: Replace/extend with HENPATH
39
+ HENS = File.join(File.dirname(__FILE__), 'hens')
37
40
 
38
- HENS = File.join(File.dirname(__FILE__), 'hens')
41
+ # Directories to search for .henrc
39
42
  RCDIRS = ['.', ENV['HOME'], File.expand_path('~')]
40
43
 
41
- HENRC = if henrc = ENV['HENRC']
44
+ find_henrc = if henrc = ENV['HENRC']
42
45
  if File.readable?(henrc)
43
46
  henrc
44
47
  else
@@ -52,39 +55,152 @@ module Hen
52
55
  "Please create one first ('hen config')."
53
56
  end
54
57
 
55
- @@hens = Hash.new { |h, k| h[k] = true; false }
56
- @@config = YAML.load_file(HENRC)
57
-
58
- def create(args, &block)
59
- name, dependencies = resolve_args(args)
58
+ # The path to the user's .henrc
59
+ HENRC = find_henrc
60
+
61
+ # A container for all loaded hens
62
+ @hens = {}
63
+
64
+ # The configuration resulting from the user's .henrc
65
+ @config = YAML.load_file(HENRC)
66
+
67
+ # The verbosity concerning errors and warnings
68
+ @verbose = true
69
+
70
+ class << self
71
+
72
+ attr_reader :hens, :config, :verbose
73
+
74
+ # call-seq:
75
+ # lay!
76
+ # lay! :some_hen, :some_other_hen
77
+ # lay! :exclude => [:some_hen, :some_other_hen]
78
+ #
79
+ # Loads the hens, causing them to lay their eggs^H^H^Htasks. Either all,
80
+ # if no restrictions are specified, or the given hens, or all but those
81
+ # given in the <tt>:exclude</tt> option.
82
+ def lay!(*args)
83
+ # Extract potential options hash
84
+ options = args.last.is_a?(Hash) ? args.pop : {}
85
+
86
+ @verbose = options[:verbose] if options.has_key?(:verbose)
87
+
88
+ # Handle include/exclude requirements
89
+ exclude = *options[:exclude]
90
+ args, default = args.empty? ? [exclude || [], true] : [args, false]
91
+
92
+ inclexcl = Hash.new(default)
93
+ args.each { |arg|
94
+ inclexcl[arg.to_s] = !default
95
+ }
96
+
97
+ # Load all available hens (as far as the
98
+ # include/exclude conditions are met)
99
+ load_hens { |hen|
100
+ inclexcl[hen]
101
+ }
102
+
103
+ # Execute each hen definition
104
+ hens.each { |name, hen|
105
+ # Load any dependencies first
106
+ load_hens(*hen.dependencies)
107
+
108
+ begin
109
+ hen.lay!
110
+ rescue HenError => err
111
+ warn "#{name}: #{err}" if verbose
112
+ end
113
+ }
114
+ end
60
115
 
61
- raise LocalJumpError, "#{name}: no block given" unless block
116
+ # call-seq:
117
+ # add_hen(hen, overwrite = false)
118
+ #
119
+ # Adds +hen+ to the global container. Overwrites
120
+ # an existing hen only if +overwrite+ is true.
121
+ def add_hen(hen, overwrite = false)
122
+ if overwrite
123
+ @hens[hen.name] = hen
124
+ else
125
+ @hens[hen.name] ||= hen
126
+ end
127
+ end
62
128
 
63
- return if @@hens[name]
129
+ private
130
+
131
+ # call-seq:
132
+ # load_hens(*hens)
133
+ # load_hens(*hens) { |hen_name| ... }
134
+ #
135
+ # Actually loads the hen files for +hens+, or all available if none are
136
+ # specified. If a block is given, only those hen files are loaded for
137
+ # which the block evaluates to true.
138
+ def load_hens(*hens, &block)
139
+ # By default, include all
140
+ block ||= lambda { true }
141
+
142
+ # No hens given means get 'em all
143
+ if hens.empty?
144
+ # TODO: Search HENPATH for available hens
145
+ hens = Dir[File.join(HENS, '*.rake')].map { |hen|
146
+ File.basename(hen, '.rake') # This is kind of awkward, but
147
+ # simplifies condition checking
148
+ }
149
+ end
150
+
151
+ hens.each { |hen|
152
+ # TODO: Search HENPATH for hen
153
+ load File.join(HENS, "#{hen}.rake") if block[hen.to_s]
154
+ }
155
+ end
64
156
 
65
- dependencies.each { |hen|
66
- load File.join(HENS, "#{hen}.rake")
67
- }
157
+ end
68
158
 
69
- begin
70
- block[DSL.new]
71
- rescue Error => err
72
- warn err.to_s
159
+ attr_reader :name, :dependencies, :block
160
+
161
+ # call-seq:
162
+ # new(args, overwrite = false) { ... }
163
+ #
164
+ # Creates a new Hen instance of a certain name and optional
165
+ # dependencies; see #resolve_args for details on the +args+
166
+ # argument. Requires a definition block; see #lay! for details.
167
+ #
168
+ # Adds itself to the global hen container via add_hen.
169
+ def initialize(args, overwrite = false, &block)
170
+ @name, @dependencies = resolve_args(args)
171
+
172
+ unless @block = block
173
+ raise LocalJumpError, "#{@name}: no block given" if verbose
174
+ return
73
175
  end
176
+
177
+ self.class.add_hen(self, overwrite)
74
178
  end
75
179
 
76
- def lay
77
- Dir[File.join(Hen::HENS, '*.rake')].each { |hen|
78
- load hen
79
- }
180
+ # call-seq:
181
+ # hen.lay!
182
+ #
183
+ # Runs the definition block, exposing the DSL if requested.
184
+ def lay!
185
+ block.arity == 1 ? block[DSL] : block.call
80
186
  end
81
187
 
82
- def config
83
- @@config
188
+ # call-seq:
189
+ # hen.verbose
190
+ #
191
+ # Just an accessor to the class attribute.
192
+ def verbose
193
+ self.class.verbose
84
194
  end
85
195
 
86
196
  private
87
197
 
198
+ # call-seq:
199
+ # resolve_args(args) => [name, dependencies]
200
+ #
201
+ # Splits into hen name and optional dependencies: +args+ may be a single
202
+ # symbol (or string), or a hash with a single key pointing to a list of
203
+ # hens this one depends upon.
88
204
  def resolve_args(args)
89
205
  name, dependencies = case args
90
206
  when Hash
@@ -101,23 +217,20 @@ module Hen
101
217
  [name.to_sym, dependencies.map { |d| d.to_sym }]
102
218
  end
103
219
 
104
- class Error < StandardError
105
- end
106
-
107
- class TaskRequired < Error
108
-
109
- def initialize(task)
110
- @task = task
111
- end
112
-
113
- def to_s
114
- "Required task missing: #{@task}"
115
- end
116
-
117
- end
118
-
119
220
  end
120
221
 
222
+ # call-seq:
223
+ # Hen(args) { ... }
224
+ #
225
+ # Just forwards to Hen.new.
121
226
  def Hen(args, &block)
122
- Hen.create(args, &block)
227
+ Hen.new(args, &block)
228
+ end
229
+
230
+ # call-seq:
231
+ # Hen!(args) { ... }
232
+ #
233
+ # Same as before, but overwrites any existing hen with the same name.
234
+ def Hen!(args, &block)
235
+ Hen.new(args, true, &block)
123
236
  end
@@ -26,24 +26,46 @@
26
26
  ###############################################################################
27
27
  #++
28
28
 
29
- module Hen
29
+ class Hen
30
30
 
31
- class DSL
31
+ # Some helper methods for use inside of a Hen definition.
32
+ module DSL
32
33
 
34
+ extend self
35
+
36
+ # call-seq:
37
+ # hen.requires(*tasks)
38
+ #
39
+ # Specify a list of +tasks+ the hen requires to be present in
40
+ # actual the Rakefile. In case one of those is not available,
41
+ # a HenError::TaskRequired error is raised.
33
42
  def requires(*tasks)
34
43
  tasks.each { |task|
35
- raise TaskRequired.new(task) unless Rake::Task.task_defined?(task)
44
+ raise HenError::TaskRequired.new(task) \
45
+ unless Rake::Task.task_defined?(task)
36
46
  }
37
47
  end
38
48
 
49
+ # call-seq:
50
+ # hen.call(task)
51
+ #
52
+ # Short-cut to call Rake task +task+.
39
53
  def call(task)
40
54
  Rake::Task[task].invoke.first.call
41
55
  end
42
56
 
57
+ # call-seq:
58
+ # hen.config
59
+ #
60
+ # The Hen configuration.
43
61
  def config
44
62
  Hen.config
45
63
  end
46
64
 
65
+ # call-seq:
66
+ # hen[key]
67
+ #
68
+ # Short-cut to the config.
47
69
  def [](key)
48
70
  config[key]
49
71
  end
@@ -0,0 +1,55 @@
1
+ #--
2
+ ###############################################################################
3
+ # #
4
+ # A component of hen, the Rake helper. #
5
+ # #
6
+ # Copyright (C) 2007 University of Cologne, #
7
+ # Albertus-Magnus-Platz, #
8
+ # 50932 Cologne, Germany #
9
+ # #
10
+ # Authors: #
11
+ # Jens Wille <jens.wille@uni-koeln.de> #
12
+ # #
13
+ # hen is free software; you can redistribute it and/or modify it under the #
14
+ # terms of the GNU General Public License as published by the Free Software #
15
+ # Foundation; either version 3 of the License, or (at your option) any later #
16
+ # version. #
17
+ # #
18
+ # hen is distributed in the hope that it will be useful, but WITHOUT ANY #
19
+ # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
20
+ # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more #
21
+ # details. #
22
+ # #
23
+ # You should have received a copy of the GNU General Public License along #
24
+ # with hen. If not, see <http://www.gnu.org/licenses/>. #
25
+ # #
26
+ ###############################################################################
27
+ #++
28
+
29
+ class Hen
30
+
31
+ # Base class for Hen errors.
32
+ class HenError < StandardError
33
+
34
+ # Raised if a required task is missing.
35
+ class TaskRequired < HenError
36
+
37
+ # call-seq:
38
+ # new(task)
39
+ #
40
+ def initialize(task)
41
+ @task = task
42
+ end
43
+
44
+ # call-seq:
45
+ # to_s
46
+ #
47
+ def to_s
48
+ "Required task missing: #{@task}"
49
+ end
50
+
51
+ end
52
+
53
+ end
54
+
55
+ end
@@ -26,13 +26,13 @@
26
26
  ###############################################################################
27
27
  #++
28
28
 
29
- module Hen
29
+ class Hen
30
30
 
31
31
  module Version
32
32
 
33
33
  MAJOR = 0
34
34
  MINOR = 0
35
- TINY = 1
35
+ TINY = 2
36
36
 
37
37
  class << self
38
38
 
@@ -47,8 +47,8 @@ Hen :gem => :rdoc do |hen|
47
47
  gem_spec.bindir = File.dirname(executable_files.first)
48
48
  end
49
49
 
50
- gem_spec.extra_rdoc_files =
51
- gem_options.delete(:extra_rdoc_files) || rdoc_files - files
50
+ gem_spec.extra_rdoc_files = gem_options.delete(:extra_rdoc_files)
51
+ gem_spec.extra_rdoc_files ||= rdoc_files - files if rdoc_files
52
52
 
53
53
  gem_spec.files = files + extra_files
54
54
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.142
4
+ version: 0.0.2.144
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Wille
@@ -9,23 +9,30 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2007-12-20 00:00:00 +01:00
12
+ date: 2007-12-21 00:00:00 +01:00
13
13
  default_executable:
14
- dependencies: []
15
-
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rubyforge
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ version:
16
24
  description:
17
25
  email: jens.wille@uni-koeln.de
18
26
  executables:
19
27
  - hen
20
28
  extensions: []
21
29
 
22
- extra_rdoc_files:
23
- - README
24
- - COPYING
25
- - ChangeLog
30
+ extra_rdoc_files: []
31
+
26
32
  files:
27
33
  - lib/hen/version.rb
28
34
  - lib/hen/dsl.rb
35
+ - lib/hen/errors.rb
29
36
  - lib/hen.rb
30
37
  - bin/hen
31
38
  - COPYING
@@ -40,15 +47,15 @@ has_rdoc: true
40
47
  homepage: prometheus.rubyforge.org/hen
41
48
  post_install_message:
42
49
  rdoc_options:
43
- - --charset
44
- - UTF-8
50
+ - --all
51
+ - --line-numbers
45
52
  - --main
46
53
  - README
47
- - --line-numbers
54
+ - --inline-source
48
55
  - --title
49
56
  - hen Application documentation
50
- - --inline-source
51
- - --all
57
+ - --charset
58
+ - UTF-8
52
59
  require_paths:
53
60
  - lib
54
61
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -66,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
73
  requirements: []
67
74
 
68
75
  rubyforge_project: prometheus
69
- rubygems_version: 1.0.0
76
+ rubygems_version: 1.0.1
70
77
  signing_key:
71
78
  specification_version: 2
72
79
  summary: Hoe or Echoe? No, thanks! Just a Rake helper that fits my own personal style.