main 6.1.0 → 6.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/main.rb +2 -2
- data/lib/main/program/class_methods.rb +43 -6
- data/lib/main/program/instance_methods.rb +4 -0
- data/main.gemspec +2 -2
- data/test/main_test.rb +52 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
N2EwNDVmM2IwNTc2NDQ3ZGI0ODFhZjhhOWExYjVlODJmNzQwZGY4NQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NjM1NzA0Yzc0MzJhOTlmZTAwMGVmMmU1NWU3NjY2NDQ2NGI2Mzg2OA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZWExOGE1ODRjNDc3MDVhZmI2ZDQwZGMzMmM5Y2IwMmZkYTFhZTBkNTdhNTdk
|
10
|
+
YzY3ZGE5NmNkMjZiZDk2MDc4ZGY1OTZhMGU0YTFhNjk3Mzg4NjQ0OTAwZGMy
|
11
|
+
ZTcyNzQ5YzdmNTY3ZjE0YmVmNjBiZDJkZTNhMmY3NjhmZTBlMTE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OTdhYjlhYzc0YTg4NTRiNGNhM2ZhOTBkNWI4NGI0YWZkZjM1MWIzZTNjZjNl
|
14
|
+
NDQ5YzMyMmVkMzVmMTBjMzJlZjYyY2I2NGE4ODIyMzFiZjg0MmMwNzcxOTAy
|
15
|
+
NzY2MDk0ZDNmMDdhNzVkN2RkMzkwNDFlNzIxZjRjMGM4YTVmNTU=
|
data/lib/main.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Main
|
2
2
|
# top level constants
|
3
3
|
#
|
4
|
-
Main::VERSION = '6.
|
4
|
+
Main::VERSION = '6.2.0' unless
|
5
5
|
defined? Main::VERSION
|
6
6
|
def Main.version() Main::VERSION end
|
7
7
|
|
@@ -25,7 +25,7 @@ module Main
|
|
25
25
|
'chronic' => [ 'chronic' , '>= 0.6.2' ] ,
|
26
26
|
'fattr' => [ 'fattr' , '>= 2.2.0' ] ,
|
27
27
|
'arrayfields' => [ 'arrayfields' , '>= 4.7.4' ] ,
|
28
|
-
'map' => [ 'map' , '>=
|
28
|
+
'map' => [ 'map' , '>= 6.1.0' ] ,
|
29
29
|
}
|
30
30
|
end
|
31
31
|
|
@@ -269,29 +269,66 @@ module Main
|
|
269
269
|
define_method(:run, &block) if block
|
270
270
|
end
|
271
271
|
|
272
|
+
def main_env(*args, &block)
|
273
|
+
@main_env ||= main_env!
|
274
|
+
|
275
|
+
if args.empty?
|
276
|
+
@main_env
|
277
|
+
else
|
278
|
+
key = main_env_key_for(args.first)
|
279
|
+
@main_env[key]
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
def main_env_key_for(key)
|
284
|
+
key.to_s.strip.downcase.sub(/^main_/, '')
|
285
|
+
end
|
286
|
+
|
287
|
+
def main_env!
|
288
|
+
@main_env = Map.new
|
289
|
+
|
290
|
+
@main_env[:state] = env['STATE']
|
291
|
+
@main_env[:state_dirname] = env['STATE_DIRNAME']
|
292
|
+
@main_env[:state_basename] = env['STATE_BASENAME']
|
293
|
+
|
294
|
+
env.each do |key, val|
|
295
|
+
next unless key.to_s =~ /^\s*MAIN_/i
|
296
|
+
k = main_env_key_for(key)
|
297
|
+
@main_env[k] = val
|
298
|
+
end
|
299
|
+
|
300
|
+
@main_env
|
301
|
+
end
|
302
|
+
|
272
303
|
def state_dirname(*args)
|
273
304
|
@state_dirname = File.join(*args) unless args.empty?
|
274
|
-
@state_dirname ||=
|
305
|
+
@state_dirname ||= main_env('STATE_DIRNAME')
|
275
306
|
@state_dirname ||= Util.home
|
276
307
|
@state_dirname
|
277
308
|
end
|
278
309
|
|
279
310
|
def state_basename(*args)
|
280
311
|
@state_basename = File.join(*args) unless args.empty?
|
281
|
-
@state_basename ||=
|
312
|
+
@state_basename ||= main_env('STATE_BASENAME')
|
282
313
|
@state_basename ||= ".#{ name }"
|
283
314
|
@state_basename
|
284
315
|
end
|
285
316
|
|
286
317
|
def state_path(*state_path, &block)
|
287
|
-
|
288
|
-
|
289
|
-
|
318
|
+
unless defined?(@state_path)
|
319
|
+
if main_env('STATE')
|
320
|
+
@state_path = File.expand_path(main_env('STATE'))
|
321
|
+
@state_dirname = File.dirname(@state_path)
|
322
|
+
@state_basename = File.basename(@state_path)
|
323
|
+
else
|
324
|
+
@state_path = File.join(state_dirname, state_basename)
|
325
|
+
end
|
326
|
+
end
|
290
327
|
|
291
328
|
if block
|
292
329
|
require 'fileutils' unless defined?(FileUtils)
|
293
330
|
FileUtils.mkdir_p(@state_path) unless test(?d, @state_path)
|
294
|
-
Dir.chdir(&block)
|
331
|
+
Dir.chdir(@state_path, &block)
|
295
332
|
else
|
296
333
|
@state_path
|
297
334
|
end
|
data/main.gemspec
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
|
4
4
|
Gem::Specification::new do |spec|
|
5
5
|
spec.name = "main"
|
6
|
-
spec.version = "6.
|
6
|
+
spec.version = "6.2.0"
|
7
7
|
spec.platform = Gem::Platform::RUBY
|
8
8
|
spec.summary = "main"
|
9
9
|
spec.description = "a class factory and dsl for generating command line programs real quick"
|
@@ -63,7 +63,7 @@ Gem::Specification::new do |spec|
|
|
63
63
|
|
64
64
|
spec.add_dependency(*["arrayfields", ">= 4.7.4"])
|
65
65
|
|
66
|
-
spec.add_dependency(*["map", ">=
|
66
|
+
spec.add_dependency(*["map", ">= 6.1.0"])
|
67
67
|
|
68
68
|
|
69
69
|
spec.extensions.push(*[])
|
data/test/main_test.rb
CHANGED
@@ -433,6 +433,7 @@ class T < Test::Unit::TestCase
|
|
433
433
|
assert bar.value == 2
|
434
434
|
assert foobar.value == 'foobar'
|
435
435
|
end
|
436
|
+
|
436
437
|
def test_0270
|
437
438
|
foo = nil
|
438
439
|
assert_nothing_raised{
|
@@ -949,6 +950,57 @@ class T < Test::Unit::TestCase
|
|
949
950
|
}
|
950
951
|
assert a == ["--", "--bar"]
|
951
952
|
end
|
953
|
+
|
954
|
+
# main_env
|
955
|
+
#
|
956
|
+
def test_0900
|
957
|
+
%w[ STATE STATE_DIRNAME STATE_BASENAME ].each do |key|
|
958
|
+
value = nil
|
959
|
+
assert_nothing_raised{
|
960
|
+
main([], key => '42'){
|
961
|
+
define_method('run'){
|
962
|
+
k = key.downcase
|
963
|
+
value = main_env[k]
|
964
|
+
}
|
965
|
+
}
|
966
|
+
}
|
967
|
+
assert value == '42'
|
968
|
+
end
|
969
|
+
end
|
970
|
+
def test_0910
|
971
|
+
%w[ MAIN_STATE MAIN_STATE_DIRNAME MAIN_STATE_BASENAME ].each do |key|
|
972
|
+
value = nil
|
973
|
+
assert_nothing_raised{
|
974
|
+
main([], key => '42'){
|
975
|
+
define_method('run'){
|
976
|
+
k = key.downcase.sub('main_', '')
|
977
|
+
value = main_env[k]
|
978
|
+
}
|
979
|
+
}
|
980
|
+
}
|
981
|
+
assert value == '42'
|
982
|
+
end
|
983
|
+
end
|
984
|
+
def test_0920
|
985
|
+
%w[ STATE MAIN_STATE ].each do |key|
|
986
|
+
dir = File.expand_path(".main-test-#{ Process.pid }-#{ (rand*1000000000000).to_i }")
|
987
|
+
FileUtils.mkdir_p(dir)
|
988
|
+
begin
|
989
|
+
values = []
|
990
|
+
assert_nothing_raised{
|
991
|
+
main([], key => dir){
|
992
|
+
define_method('run'){
|
993
|
+
values.push state_path
|
994
|
+
state_path{ values.push File.expand_path(Dir.pwd) }
|
995
|
+
}
|
996
|
+
}
|
997
|
+
}
|
998
|
+
assert values == [dir, dir]
|
999
|
+
ensure
|
1000
|
+
FileUtils.rm_rf(dir)
|
1001
|
+
end
|
1002
|
+
end
|
1003
|
+
end
|
952
1004
|
end
|
953
1005
|
|
954
1006
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: main
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.
|
4
|
+
version: 6.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ara T. Howard
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chronic
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 6.1.0
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - ! '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 6.1.0
|
69
69
|
description: a class factory and dsl for generating command line programs real quick
|
70
70
|
email: ara.t.howard@gmail.com
|
71
71
|
executables: []
|
@@ -131,3 +131,4 @@ signing_key:
|
|
131
131
|
specification_version: 4
|
132
132
|
summary: main
|
133
133
|
test_files: []
|
134
|
+
has_rdoc:
|