options 2.2.0 → 2.3.0

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.
Files changed (3) hide show
  1. data/Rakefile +160 -22
  2. data/lib/options.rb +2 -2
  3. metadata +29 -8
data/Rakefile CHANGED
@@ -1,19 +1,63 @@
1
+ This.rubyforge_project = 'codeforpeople'
1
2
  This.author = "Ara T. Howard"
2
3
  This.email = "ara.t.howard@gmail.com"
3
4
  This.homepage = "http://github.com/ahoward/#{ This.lib }/tree/master"
4
- This.rubyforge_project = 'codeforpeople'
5
+
5
6
 
6
7
  task :default do
7
- puts(Rake::Task.tasks.map{|task| task.name} - ['default'])
8
+ puts((Rake::Task.tasks.map{|task| task.name.gsub(/::/,':')} - ['default']).sort)
8
9
  end
9
10
 
10
- task :spec do
11
- require 'spec/rake/spectask'
12
- Spec::Rake::SpecTask.new do |t|
13
- t.spec_files = FileList['spec/*_spec.rb']
11
+ task :test do
12
+ run_tests!
13
+ end
14
+
15
+ namespace :test do
16
+ task(:unit){ run_tests!(:unit) }
17
+ task(:functional){ run_tests!(:functional) }
18
+ task(:integration){ run_tests!(:integration) }
19
+ end
20
+
21
+ def run_tests!(which = nil)
22
+ which ||= '**'
23
+ test_dir = File.join(This.dir, "test")
24
+ test_glob ||= File.join(test_dir, "#{ which }/**_test.rb")
25
+ test_rbs = Dir.glob(test_glob).sort
26
+
27
+ div = ('=' * 119)
28
+ line = ('-' * 119)
29
+ helper = "-r ./test/helper.rb" if test(?e, "./test/helper.rb")
30
+
31
+ test_rbs.each_with_index do |test_rb, index|
32
+ testno = index + 1
33
+ command = "#{ This.ruby } -I ./lib -I ./test/lib #{ helper } #{ test_rb }"
34
+
35
+ puts
36
+ say(div, :color => :cyan, :bold => true)
37
+ say("@#{ testno } => ", :bold => true, :method => :print)
38
+ say(command, :color => :cyan, :bold => true)
39
+ say(line, :color => :cyan, :bold => true)
40
+
41
+ system(command)
42
+
43
+ say(line, :color => :cyan, :bold => true)
44
+
45
+ status = $?.exitstatus
46
+
47
+ if status.zero?
48
+ say("@#{ testno } <= ", :bold => true, :color => :white, :method => :print)
49
+ say("SUCCESS", :color => :green, :bold => true)
50
+ else
51
+ say("@#{ testno } <= ", :bold => true, :color => :white, :method => :print)
52
+ say("FAILURE", :color => :red, :bold => true)
53
+ end
54
+ say(line, :color => :cyan, :bold => true)
55
+
56
+ exit(status) unless status.zero?
14
57
  end
15
58
  end
16
59
 
60
+
17
61
  task :gemspec do
18
62
  ignore_extensions = 'git', 'svn', 'tmp', /sw./, 'bak', 'gem'
19
63
  ignore_directories = 'pkg'
@@ -39,14 +83,18 @@ task :gemspec do
39
83
  end
40
84
 
41
85
  lib = This.lib
86
+ object = This.object
42
87
  version = This.version
43
88
  files = shiteless[Dir::glob("**/**")]
44
89
  executables = shiteless[Dir::glob("bin/*")].map{|exe| File.basename(exe)}
45
90
  has_rdoc = true #File.exist?('doc')
46
91
  test_files = "test/#{ lib }.rb" if File.file?("test/#{ lib }.rb")
92
+ summary = object.respond_to?(:summary) ? object.summary : "summary: #{ lib } kicks the ass"
93
+ description = object.respond_to?(:description) ? object.description : "description: #{ lib } kicks the ass"
47
94
 
48
- extensions = This.extensions
49
- if extensions.nil?
95
+ if This.extensions.nil?
96
+ This.extensions = []
97
+ extensions = This.extensions
50
98
  %w( Makefile configure extconf.rb ).each do |ext|
51
99
  extensions << ext if File.exists?(ext)
52
100
  end
@@ -67,6 +115,7 @@ task :gemspec do
67
115
  spec.version = #{ version.inspect }
68
116
  spec.platform = Gem::Platform::RUBY
69
117
  spec.summary = #{ lib.inspect }
118
+ spec.description = #{ description.inspect }
70
119
 
71
120
  spec.files = #{ files.inspect }
72
121
  spec.executables = #{ executables.inspect }
@@ -76,7 +125,7 @@ task :gemspec do
76
125
  spec.has_rdoc = #{ has_rdoc.inspect }
77
126
  spec.test_files = #{ test_files.inspect }
78
127
  #spec.add_dependency 'lib', '>= version'
79
- #spec.add_dependency 'fattr'
128
+ spec.add_dependency 'fattr'
80
129
 
81
130
  spec.extensions.push(*#{ extensions.inspect })
82
131
 
@@ -89,19 +138,21 @@ task :gemspec do
89
138
  }
90
139
  end
91
140
 
92
- open("#{ lib }.gemspec", "w"){|fd| fd.puts template}
93
- This.gemspec = "#{ lib }.gemspec"
141
+ Fu.mkdir_p(This.pkgdir)
142
+ gemspec = File.join(This.pkgdir, "#{ lib }.gemspec")
143
+ open(gemspec, "w"){|fd| fd.puts(template)}
144
+ This.gemspec = gemspec
94
145
  end
95
146
 
96
147
  task :gem => [:clean, :gemspec] do
97
- Fu.mkdir_p This.pkgdir
148
+ Fu.mkdir_p(This.pkgdir)
98
149
  before = Dir['*.gem']
99
150
  cmd = "gem build #{ This.gemspec }"
100
151
  `#{ cmd }`
101
152
  after = Dir['*.gem']
102
153
  gem = ((after - before).first || after.first) or abort('no gem!')
103
- Fu.mv gem, This.pkgdir
104
- This.gem = File.basename(gem)
154
+ Fu.mv(gem, This.pkgdir)
155
+ This.gem = File.join(This.pkgdir, File.basename(gem))
105
156
  end
106
157
 
107
158
  task :readme do
@@ -120,7 +171,7 @@ task :readme do
120
171
  cmd = "ruby #{ sample }"
121
172
  samples << Util.indent(prompt + cmd, 2) << "\n\n"
122
173
 
123
- cmd = "ruby -e'STDOUT.sync=true; exec %(ruby -Ilib #{ sample })'"
174
+ cmd = "ruby -e'STDOUT.sync=true; exec %(ruby -I ./lib #{ sample })'"
124
175
  samples << Util.indent(`#{ cmd } 2>&1`, 4) << "\n"
125
176
  end
126
177
 
@@ -157,10 +208,18 @@ task :release => [:clean, :gemspec, :gem] do
157
208
  gems = Dir[File.join(This.pkgdir, '*.gem')].flatten
158
209
  raise "which one? : #{ gems.inspect }" if gems.size > 1
159
210
  raise "no gems?" if gems.size < 1
160
- #cmd = "rubyforge login && rubyforge add_release #{ This.rubyforge_project } #{ This.lib } #{ This.version } #{ This.pkgdir }/#{ This.gem }"
161
- cmd = "rubyforge add_release #{ This.rubyforge_project } #{ This.lib } #{ This.version } #{ This.pkgdir }/#{ This.gem }"
211
+
212
+ cmd = "gem push #{ This.gem }"
213
+ puts cmd
214
+ puts
215
+ system(cmd)
216
+ abort("cmd(#{ cmd }) failed with (#{ $?.inspect })") unless $?.exitstatus.zero?
217
+
218
+ cmd = "rubyforge login && rubyforge add_release #{ This.rubyforge_project } #{ This.lib } #{ This.version } #{ This.gem }"
162
219
  puts cmd
163
- system cmd
220
+ puts
221
+ system(cmd)
222
+ abort("cmd(#{ cmd }) failed with (#{ $?.inspect })") unless $?.exitstatus.zero?
164
223
  end
165
224
 
166
225
 
@@ -168,37 +227,62 @@ end
168
227
 
169
228
 
170
229
  BEGIN {
230
+ # support for this rakefile
231
+ #
171
232
  $VERBOSE = nil
172
233
 
173
234
  require 'ostruct'
174
235
  require 'erb'
175
236
  require 'fileutils'
237
+ require 'rbconfig'
176
238
 
239
+ # fu shortcut
240
+ #
177
241
  Fu = FileUtils
178
242
 
243
+ # cache a bunch of stuff about this rakefile/environment
244
+ #
179
245
  This = OpenStruct.new
180
246
 
181
247
  This.file = File.expand_path(__FILE__)
182
248
  This.dir = File.dirname(This.file)
183
249
  This.pkgdir = File.join(This.dir, 'pkg')
184
250
 
251
+ # grok lib
252
+ #
185
253
  lib = ENV['LIB']
186
254
  unless lib
187
- lib = File.basename(Dir.pwd)
255
+ lib = File.basename(Dir.pwd).sub(/[-].*$/, '')
188
256
  end
189
257
  This.lib = lib
190
258
 
259
+ # grok version
260
+ #
191
261
  version = ENV['VERSION']
192
262
  unless version
193
- name = lib.capitalize
194
- require "./lib/#{ lib }"
195
- version = eval(name).send(:version)
263
+ require "./lib/#{ This.lib }"
264
+ This.name = lib.capitalize
265
+ This.object = eval(This.name)
266
+ version = This.object.send(:version)
196
267
  end
197
268
  This.version = version
198
269
 
270
+ # we need to know the name of the lib an it's version
271
+ #
199
272
  abort('no lib') unless This.lib
200
273
  abort('no version') unless This.version
201
274
 
275
+ # discover full path to this ruby executable
276
+ #
277
+ c = Config::CONFIG
278
+ bindir = c["bindir"] || c['BINDIR']
279
+ ruby_install_name = c['ruby_install_name'] || c['RUBY_INSTALL_NAME'] || 'ruby'
280
+ ruby_ext = c['EXEEXT'] || ''
281
+ ruby = File.join(bindir, (ruby_install_name + ruby_ext))
282
+ This.ruby = ruby
283
+
284
+ # some utils
285
+ #
202
286
  module Util
203
287
  def indent(s, n = 2)
204
288
  s = unindent(s)
@@ -217,6 +301,8 @@ BEGIN {
217
301
  extend self
218
302
  end
219
303
 
304
+ # template support
305
+ #
220
306
  class Template
221
307
  def initialize(&block)
222
308
  @block = block
@@ -229,5 +315,57 @@ BEGIN {
229
315
  end
230
316
  def Template(*args, &block) Template.new(*args, &block) end
231
317
 
318
+ # colored console output support
319
+ #
320
+ This.ansi = {
321
+ :clear => "\e[0m",
322
+ :reset => "\e[0m",
323
+ :erase_line => "\e[K",
324
+ :erase_char => "\e[P",
325
+ :bold => "\e[1m",
326
+ :dark => "\e[2m",
327
+ :underline => "\e[4m",
328
+ :underscore => "\e[4m",
329
+ :blink => "\e[5m",
330
+ :reverse => "\e[7m",
331
+ :concealed => "\e[8m",
332
+ :black => "\e[30m",
333
+ :red => "\e[31m",
334
+ :green => "\e[32m",
335
+ :yellow => "\e[33m",
336
+ :blue => "\e[34m",
337
+ :magenta => "\e[35m",
338
+ :cyan => "\e[36m",
339
+ :white => "\e[37m",
340
+ :on_black => "\e[40m",
341
+ :on_red => "\e[41m",
342
+ :on_green => "\e[42m",
343
+ :on_yellow => "\e[43m",
344
+ :on_blue => "\e[44m",
345
+ :on_magenta => "\e[45m",
346
+ :on_cyan => "\e[46m",
347
+ :on_white => "\e[47m"
348
+ }
349
+ def say(phrase, *args)
350
+ options = args.last.is_a?(Hash) ? args.pop : {}
351
+ options[:color] = args.shift.to_s.to_sym unless args.empty?
352
+ keys = options.keys
353
+ keys.each{|key| options[key.to_s.to_sym] = options.delete(key)}
354
+
355
+ color = options[:color]
356
+ bold = options.has_key?(:bold)
357
+
358
+ parts = [phrase]
359
+ parts.unshift(This.ansi[color]) if color
360
+ parts.unshift(This.ansi[:bold]) if bold
361
+ parts.push(This.ansi[:clear]) if parts.size > 1
362
+
363
+ method = options[:method] || :puts
364
+
365
+ Kernel.send(method, parts.join)
366
+ end
367
+
368
+ # always run out of the project dir
369
+ #
232
370
  Dir.chdir(This.dir)
233
371
  }
@@ -1,5 +1,5 @@
1
1
  module Options
2
- Options::VERSION = '2.2.0' unless defined?(Options::VERSION)
2
+ Options::VERSION = '2.3.0' unless defined?(Options::VERSION)
3
3
 
4
4
  class << Options
5
5
  def version
@@ -53,7 +53,7 @@ module Options
53
53
  when Hash
54
54
  Options.for(args)
55
55
  else
56
- raise ArgumentError, "`args` should be and Array or Hash"
56
+ raise ArgumentError, "`args` should be an Array or Hash"
57
57
  end
58
58
  end
59
59
  end
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: options
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ prerelease: false
5
+ segments:
6
+ - 2
7
+ - 3
8
+ - 0
9
+ version: 2.3.0
5
10
  platform: ruby
6
11
  authors:
7
12
  - Ara T. Howard
@@ -9,11 +14,23 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-06-19 00:00:00 -06:00
17
+ date: 2010-09-12 00:00:00 -06:00
13
18
  default_executable:
14
- dependencies: []
15
-
16
- description:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: fattr
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ description: "description: options kicks the ass"
17
34
  email: ara.t.howard@gmail.com
18
35
  executables: []
19
36
 
@@ -43,21 +60,25 @@ rdoc_options: []
43
60
  require_paths:
44
61
  - lib
45
62
  required_ruby_version: !ruby/object:Gem::Requirement
63
+ none: false
46
64
  requirements:
47
65
  - - ">="
48
66
  - !ruby/object:Gem::Version
67
+ segments:
68
+ - 0
49
69
  version: "0"
50
- version:
51
70
  required_rubygems_version: !ruby/object:Gem::Requirement
71
+ none: false
52
72
  requirements:
53
73
  - - ">="
54
74
  - !ruby/object:Gem::Version
75
+ segments:
76
+ - 0
55
77
  version: "0"
56
- version:
57
78
  requirements: []
58
79
 
59
80
  rubyforge_project: codeforpeople
60
- rubygems_version: 1.3.5
81
+ rubygems_version: 1.3.7
61
82
  signing_key:
62
83
  specification_version: 3
63
84
  summary: options