main 4.6.0 → 4.7.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.
data/Rakefile CHANGED
@@ -1,23 +1,69 @@
1
+ This.rubyforge_project = 'codeforpeople'
1
2
  This.author = "Ara T. Howard"
2
3
  This.email = "ara.t.howard@gmail.com"
3
- This.homepage = "http://github.com/ahoward/#{ This.lib }/tree/master"
4
- This.rubyforge_project = 'codeforpeople'
4
+ This.homepage = "https://github.com/ahoward/#{ This.lib }"
5
+
6
+ task :license do
7
+ open('LICENSE', 'w'){|fd| fd.puts "same as ruby's"}
8
+ end
5
9
 
6
10
  task :default do
7
- puts(Rake::Task.tasks.map{|task| task.name} - ['default'])
11
+ puts((Rake::Task.tasks.map{|task| task.name.gsub(/::/,':')} - ['default']).sort)
8
12
  end
9
13
 
10
- task :spec do
11
- require 'spec/rake/spectask'
12
- Spec::Rake::SpecTask.new do |t|
13
- t.spec_files = FileList['spec/*_spec.rb']
14
+ task :test do
15
+ run_tests!
16
+ end
17
+
18
+ namespace :test do
19
+ task(:unit){ run_tests!(:unit) }
20
+ task(:functional){ run_tests!(:functional) }
21
+ task(:integration){ run_tests!(:integration) }
22
+ end
23
+
24
+ def run_tests!(which = nil)
25
+ which ||= '**'
26
+ test_dir = File.join(This.dir, "test")
27
+ test_glob ||= File.join(test_dir, "#{ which }/**_test.rb")
28
+ test_rbs = Dir.glob(test_glob).sort
29
+
30
+ div = ('=' * 119)
31
+ line = ('-' * 119)
32
+
33
+ test_rbs.each_with_index do |test_rb, index|
34
+ testno = index + 1
35
+ command = "#{ This.ruby } -I ./lib -I ./test/lib #{ test_rb }"
36
+
37
+ puts
38
+ say(div, :color => :cyan, :bold => true)
39
+ say("@#{ testno } => ", :bold => true, :method => :print)
40
+ say(command, :color => :cyan, :bold => true)
41
+ say(line, :color => :cyan, :bold => true)
42
+
43
+ system(command)
44
+
45
+ say(line, :color => :cyan, :bold => true)
46
+
47
+ status = $?.exitstatus
48
+
49
+ if status.zero?
50
+ say("@#{ testno } <= ", :bold => true, :color => :white, :method => :print)
51
+ say("SUCCESS", :color => :green, :bold => true)
52
+ else
53
+ say("@#{ testno } <= ", :bold => true, :color => :white, :method => :print)
54
+ say("FAILURE", :color => :red, :bold => true)
55
+ end
56
+ say(line, :color => :cyan, :bold => true)
57
+
58
+ exit(status) unless status.zero?
14
59
  end
15
60
  end
16
61
 
62
+
17
63
  task :gemspec do
18
- ignore_extensions = 'git', 'svn', 'tmp', /sw./, 'bak', 'gem'
19
- ignore_directories = 'pkg'
20
- ignore_files = 'test/log'
64
+ ignore_extensions = ['git', 'svn', 'tmp', /sw./, 'bak', 'gem']
65
+ ignore_directories = ['pkg']
66
+ ignore_files = ['test/log']
21
67
 
22
68
  shiteless =
23
69
  lambda do |list|
@@ -39,14 +85,18 @@ task :gemspec do
39
85
  end
40
86
 
41
87
  lib = This.lib
88
+ object = This.object
42
89
  version = This.version
43
90
  files = shiteless[Dir::glob("**/**")]
44
91
  executables = shiteless[Dir::glob("bin/*")].map{|exe| File.basename(exe)}
45
- has_rdoc = true #File.exist?('doc')
92
+ #has_rdoc = true #File.exist?('doc')
46
93
  test_files = "test/#{ lib }.rb" if File.file?("test/#{ lib }.rb")
94
+ summary = object.respond_to?(:summary) ? object.summary : "summary: #{ lib } kicks the ass"
95
+ description = object.respond_to?(:description) ? object.description : "description: #{ lib } kicks the ass"
47
96
 
48
- extensions = This.extensions
49
- if extensions.nil?
97
+ if This.extensions.nil?
98
+ This.extensions = []
99
+ extensions = This.extensions
50
100
  %w( Makefile configure extconf.rb ).each do |ext|
51
101
  extensions << ext if File.exists?(ext)
52
102
  end
@@ -64,23 +114,20 @@ task :gemspec do
64
114
 
65
115
  Gem::Specification::new do |spec|
66
116
  spec.name = #{ lib.inspect }
67
- spec.description = 'a class factory and dsl for generating command line programs real quick'
68
117
  spec.version = #{ version.inspect }
69
118
  spec.platform = Gem::Platform::RUBY
70
119
  spec.summary = #{ lib.inspect }
120
+ spec.description = #{ description.inspect }
71
121
 
72
- spec.files = #{ files.inspect }
122
+ spec.files =\n#{ files.sort.pretty_inspect }
73
123
  spec.executables = #{ executables.inspect }
74
124
 
75
- <% if test(?d, 'lib') %>
76
125
  spec.require_path = "lib"
77
- <% end %>
78
126
 
79
- spec.has_rdoc = #{ has_rdoc.inspect }
80
127
  spec.test_files = #{ test_files.inspect }
81
- spec.add_dependency 'fattr', '>= 2.1.0'
82
- spec.add_dependency 'arrayfields', '>= 4.7.4'
83
- spec.add_dependency 'map', '>= 2.0.0'
128
+
129
+ ### spec.add_dependency 'lib', '>= version'
130
+ #### spec.add_dependency 'map'
84
131
 
85
132
  spec.extensions.push(*#{ extensions.inspect })
86
133
 
@@ -94,19 +141,20 @@ task :gemspec do
94
141
  end
95
142
 
96
143
  Fu.mkdir_p(This.pkgdir)
97
- This.gemspec = File.join(This.pkgdir, "gemspec.rb")
98
- open("#{ This.gemspec }", "w"){|fd| fd.puts(template)}
144
+ gemspec = "#{ lib }.gemspec"
145
+ open(gemspec, "w"){|fd| fd.puts(template)}
146
+ This.gemspec = gemspec
99
147
  end
100
148
 
101
149
  task :gem => [:clean, :gemspec] do
102
- Fu.mkdir_p This.pkgdir
150
+ Fu.mkdir_p(This.pkgdir)
103
151
  before = Dir['*.gem']
104
152
  cmd = "gem build #{ This.gemspec }"
105
153
  `#{ cmd }`
106
154
  after = Dir['*.gem']
107
155
  gem = ((after - before).first || after.first) or abort('no gem!')
108
156
  Fu.mv(gem, This.pkgdir)
109
- This.gem = File.basename(gem)
157
+ This.gem = File.join(This.pkgdir, File.basename(gem))
110
158
  end
111
159
 
112
160
  task :readme do
@@ -125,7 +173,7 @@ task :readme do
125
173
  cmd = "ruby #{ sample }"
126
174
  samples << Util.indent(prompt + cmd, 2) << "\n\n"
127
175
 
128
- cmd = "ruby -e'STDOUT.sync=true; exec %(ruby -Ilib #{ sample })'"
176
+ cmd = "ruby -e'STDOUT.sync=true; exec %(ruby -I ./lib #{ sample })'"
129
177
  samples << Util.indent(`#{ cmd } 2>&1`, 4) << "\n"
130
178
  end
131
179
 
@@ -162,9 +210,18 @@ task :release => [:clean, :gemspec, :gem] do
162
210
  gems = Dir[File.join(This.pkgdir, '*.gem')].flatten
163
211
  raise "which one? : #{ gems.inspect }" if gems.size > 1
164
212
  raise "no gems?" if gems.size < 1
165
- cmd = "rubyforge login && rubyforge add_release #{ This.rubyforge_project } #{ This.lib } #{ This.version } #{ This.pkgdir }/#{ This.gem }"
213
+
214
+ cmd = "gem push #{ This.gem }"
215
+ puts cmd
216
+ puts
217
+ system(cmd)
218
+ abort("cmd(#{ cmd }) failed with (#{ $?.inspect })") unless $?.exitstatus.zero?
219
+
220
+ cmd = "rubyforge login && rubyforge add_release #{ This.rubyforge_project } #{ This.lib } #{ This.version } #{ This.gem }"
166
221
  puts cmd
167
- system cmd
222
+ puts
223
+ system(cmd)
224
+ abort("cmd(#{ cmd }) failed with (#{ $?.inspect })") unless $?.exitstatus.zero?
168
225
  end
169
226
 
170
227
 
@@ -172,44 +229,63 @@ end
172
229
 
173
230
 
174
231
  BEGIN {
232
+ # support for this rakefile
233
+ #
175
234
  $VERBOSE = nil
176
235
 
177
236
  require 'ostruct'
178
237
  require 'erb'
179
238
  require 'fileutils'
239
+ require 'rbconfig'
240
+ require 'pp'
180
241
 
242
+ # fu shortcut
243
+ #
181
244
  Fu = FileUtils
182
245
 
246
+ # cache a bunch of stuff about this rakefile/environment
247
+ #
183
248
  This = OpenStruct.new
184
249
 
185
250
  This.file = File.expand_path(__FILE__)
186
251
  This.dir = File.dirname(This.file)
187
252
  This.pkgdir = File.join(This.dir, 'pkg')
188
253
 
254
+ # grok lib
255
+ #
189
256
  lib = ENV['LIB']
190
257
  unless lib
191
- lib = File.basename(Dir.pwd)
258
+ lib = File.basename(Dir.pwd).sub(/[-].*$/, '')
192
259
  end
193
260
  This.lib = lib
194
261
 
262
+ # grok version
263
+ #
195
264
  version = ENV['VERSION']
196
265
  unless version
197
- name = lib.capitalize
198
- library = "./lib/#{ lib }.rb"
199
- program = "./bin/#{ lib }"
200
- if test(?e, library)
201
- require library
202
- version = eval(name).send(:version)
203
- elsif test(?e, program)
204
- version = `#{ program } --version`.strip
205
- end
206
- abort('no version') if(version.nil? or version.empty?)
266
+ require "./lib/#{ This.lib }"
267
+ This.name = lib.capitalize
268
+ This.object = eval(This.name)
269
+ version = This.object.send(:version)
207
270
  end
208
271
  This.version = version
209
272
 
273
+ # we need to know the name of the lib an it's version
274
+ #
210
275
  abort('no lib') unless This.lib
211
276
  abort('no version') unless This.version
212
277
 
278
+ # discover full path to this ruby executable
279
+ #
280
+ c = Config::CONFIG
281
+ bindir = c["bindir"] || c['BINDIR']
282
+ ruby_install_name = c['ruby_install_name'] || c['RUBY_INSTALL_NAME'] || 'ruby'
283
+ ruby_ext = c['EXEEXT'] || ''
284
+ ruby = File.join(bindir, (ruby_install_name + ruby_ext))
285
+ This.ruby = ruby
286
+
287
+ # some utils
288
+ #
213
289
  module Util
214
290
  def indent(s, n = 2)
215
291
  s = unindent(s)
@@ -219,7 +295,7 @@ BEGIN {
219
295
 
220
296
  def unindent(s)
221
297
  indent = nil
222
- s.each do |line|
298
+ s.each_line do |line|
223
299
  next if line =~ %r/^\s*$/
224
300
  indent = line[%r/^\s*/] and break
225
301
  end
@@ -228,17 +304,71 @@ BEGIN {
228
304
  extend self
229
305
  end
230
306
 
307
+ # template support
308
+ #
231
309
  class Template
232
310
  def initialize(&block)
233
311
  @block = block
234
312
  @template = block.call.to_s
235
313
  end
236
314
  def expand(b=nil)
237
- ERB.new(Util.unindent(@template)).result(b||@block)
315
+ ERB.new(Util.unindent(@template)).result((b||@block).binding)
238
316
  end
239
317
  alias_method 'to_s', 'expand'
240
318
  end
241
319
  def Template(*args, &block) Template.new(*args, &block) end
242
320
 
321
+ # colored console output support
322
+ #
323
+ This.ansi = {
324
+ :clear => "\e[0m",
325
+ :reset => "\e[0m",
326
+ :erase_line => "\e[K",
327
+ :erase_char => "\e[P",
328
+ :bold => "\e[1m",
329
+ :dark => "\e[2m",
330
+ :underline => "\e[4m",
331
+ :underscore => "\e[4m",
332
+ :blink => "\e[5m",
333
+ :reverse => "\e[7m",
334
+ :concealed => "\e[8m",
335
+ :black => "\e[30m",
336
+ :red => "\e[31m",
337
+ :green => "\e[32m",
338
+ :yellow => "\e[33m",
339
+ :blue => "\e[34m",
340
+ :magenta => "\e[35m",
341
+ :cyan => "\e[36m",
342
+ :white => "\e[37m",
343
+ :on_black => "\e[40m",
344
+ :on_red => "\e[41m",
345
+ :on_green => "\e[42m",
346
+ :on_yellow => "\e[43m",
347
+ :on_blue => "\e[44m",
348
+ :on_magenta => "\e[45m",
349
+ :on_cyan => "\e[46m",
350
+ :on_white => "\e[47m"
351
+ }
352
+ def say(phrase, *args)
353
+ options = args.last.is_a?(Hash) ? args.pop : {}
354
+ options[:color] = args.shift.to_s.to_sym unless args.empty?
355
+ keys = options.keys
356
+ keys.each{|key| options[key.to_s.to_sym] = options.delete(key)}
357
+
358
+ color = options[:color]
359
+ bold = options.has_key?(:bold)
360
+
361
+ parts = [phrase]
362
+ parts.unshift(This.ansi[color]) if color
363
+ parts.unshift(This.ansi[:bold]) if bold
364
+ parts.push(This.ansi[:clear]) if parts.size > 1
365
+
366
+ method = options[:method] || :puts
367
+
368
+ Kernel.send(method, parts.join)
369
+ end
370
+
371
+ # always run out of the project dir
372
+ #
243
373
  Dir.chdir(This.dir)
244
374
  }
@@ -2,7 +2,7 @@ module Main
2
2
  #
3
3
  # top level constants
4
4
  #
5
- Main::VERSION = '4.6.0' unless
5
+ Main::VERSION = '4.7.0' unless
6
6
  defined? Main::VERSION
7
7
  def self.version() Main::VERSION end
8
8
 
@@ -564,14 +564,14 @@ module Main
564
564
  def fattr a = nil, &block
565
565
  name = param.name
566
566
  a ||= name
567
- b = fattr_block_for name, &block
567
+ b = fattr_block_for(name, &block)
568
568
  @param.main.module_eval{ fattr(*a, &b) }
569
569
  end
570
570
  alias_method 'attribute', 'fattr'
571
571
 
572
572
  def fattr_block_for name, &block
573
573
  block ||= lambda{|param| [0,1].include?(param.arity) ? param.value : param.values }
574
- lambda{ block.call self.param[name] }
574
+ lambda{|*args| block.call(self.param[name]) }
575
575
  end
576
576
 
577
577
  def attr(*a, &b)
@@ -812,12 +812,12 @@ class T < Test::Unit::TestCase
812
812
  name = 'arity_one_paramter_attr'
813
813
  m = nil
814
814
  argv = %w( a )
815
- assert_nothing_raised{
815
+ #assert_nothing_raised{
816
816
  main(argv.dup) {
817
817
  argument(name){ arity 1; attr }
818
818
  run{ m = send(name) }
819
819
  }
820
- }
820
+ #}
821
821
  assert m == argv.first
822
822
  end
823
823
  def test_0520
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: main
3
3
  version: !ruby/object:Gem::Version
4
- hash: 39
5
4
  prerelease:
6
- segments:
7
- - 4
8
- - 6
9
- - 0
10
- version: 4.6.0
5
+ version: 4.7.0
11
6
  platform: ruby
12
7
  authors:
13
8
  - Ara T. Howard
@@ -15,58 +10,10 @@ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2011-06-30 00:00:00 -06:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- name: fattr
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 11
30
- segments:
31
- - 2
32
- - 1
33
- - 0
34
- version: 2.1.0
35
- type: :runtime
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: arrayfields
39
- prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- hash: 43
46
- segments:
47
- - 4
48
- - 7
49
- - 4
50
- version: 4.7.4
51
- type: :runtime
52
- version_requirements: *id002
53
- - !ruby/object:Gem::Dependency
54
- name: map
55
- prerelease: false
56
- requirement: &id003 !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- hash: 15
62
- segments:
63
- - 2
64
- - 0
65
- - 0
66
- version: 2.0.0
67
- type: :runtime
68
- version_requirements: *id003
69
- description: a class factory and dsl for generating command line programs real quick
13
+ date: 2011-08-16 00:00:00 Z
14
+ dependencies: []
15
+
16
+ description: "description: main kicks the ass"
70
17
  email: ara.t.howard@gmail.com
71
18
  executables: []
72
19
 
@@ -75,6 +22,12 @@ extensions: []
75
22
  extra_rdoc_files: []
76
23
 
77
24
  files:
25
+ - LICENSE
26
+ - README
27
+ - README.erb
28
+ - Rakefile
29
+ - TODO
30
+ - lib/main.rb
78
31
  - lib/main/cast.rb
79
32
  - lib/main/dsl.rb
80
33
  - lib/main/factories.rb
@@ -82,19 +35,14 @@ files:
82
35
  - lib/main/logger.rb
83
36
  - lib/main/mode.rb
84
37
  - lib/main/parameter.rb
38
+ - lib/main/program.rb
85
39
  - lib/main/program/class_methods.rb
86
40
  - lib/main/program/instance_methods.rb
87
- - lib/main/program.rb
88
41
  - lib/main/softspoken.rb
89
42
  - lib/main/stdext.rb
90
43
  - lib/main/test.rb
91
44
  - lib/main/usage.rb
92
45
  - lib/main/util.rb
93
- - lib/main.rb
94
- - LICENSE
95
- - Rakefile
96
- - README
97
- - README.erb
98
46
  - samples/a.rb
99
47
  - samples/b.rb
100
48
  - samples/c.rb
@@ -104,10 +52,8 @@ files:
104
52
  - samples/g.rb
105
53
  - samples/h.rb
106
54
  - samples/j.rb
107
- - test/main.rb
108
- - TODO
109
- has_rdoc: true
110
- homepage: http://github.com/ahoward/main/tree/master
55
+ - test/main_test.rb
56
+ homepage: https://github.com/ahoward/main
111
57
  licenses: []
112
58
 
113
59
  post_install_message:
@@ -120,25 +66,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
120
66
  requirements:
121
67
  - - ">="
122
68
  - !ruby/object:Gem::Version
123
- hash: 3
124
- segments:
125
- - 0
126
69
  version: "0"
127
70
  required_rubygems_version: !ruby/object:Gem::Requirement
128
71
  none: false
129
72
  requirements:
130
73
  - - ">="
131
74
  - !ruby/object:Gem::Version
132
- hash: 3
133
- segments:
134
- - 0
135
75
  version: "0"
136
76
  requirements: []
137
77
 
138
78
  rubyforge_project: codeforpeople
139
- rubygems_version: 1.4.2
79
+ rubygems_version: 1.7.2
140
80
  signing_key:
141
81
  specification_version: 3
142
82
  summary: main
143
- test_files:
144
- - test/main.rb
83
+ test_files: []
84
+