Checked 2.0.2 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Checked.gemspec +0 -2
- data/lib/Checked/All.rb +34 -0
- data/lib/Checked/Arch.rb +33 -14
- data/lib/Checked/Ask/Arrays.rb +13 -22
- data/lib/Checked/Ask/Strings.rb +2 -8
- data/lib/Checked/Ask/Vars.rb +15 -23
- data/lib/Checked/Clean/Strings.rb +66 -97
- data/lib/Checked/DSL.rb +19 -68
- data/lib/Checked/Demand/Arrays.rb +40 -52
- data/lib/Checked/Demand/Bools.rb +17 -25
- data/lib/Checked/Demand/Demand.rb +1 -1
- data/lib/Checked/Demand/File_Paths.rb +47 -54
- data/lib/Checked/Demand/Hashs.rb +9 -17
- data/lib/Checked/Demand/Strings.rb +51 -56
- data/lib/Checked/Demand/Symbols.rb +11 -18
- data/lib/Checked/Demand/Vars.rb +49 -97
- data/lib/Checked/version.rb +2 -4
- data/lib/Checked.rb +10 -33
- data/spec/tests/Ask.rb +3 -3
- data/spec/tests/Clean.rb +2 -2
- data/spec/tests/DSL.rb +3 -3
- data/spec/tests/Demand.rb +1 -1
- metadata +9 -19
data/Checked.gemspec
CHANGED
@@ -21,8 +21,6 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
22
22
|
s.require_paths = ["lib"]
|
23
23
|
|
24
|
-
s.add_runtime_dependency "Sin_Arch"
|
25
|
-
|
26
24
|
s.add_development_dependency 'rake'
|
27
25
|
s.add_development_dependency 'bacon'
|
28
26
|
s.add_development_dependency 'Bacon_Colored'
|
data/lib/Checked/All.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
|
2
|
+
class Checked
|
3
|
+
module All
|
4
|
+
|
5
|
+
include Checked::Arch
|
6
|
+
|
7
|
+
def be! *args
|
8
|
+
meth, vals = args
|
9
|
+
answer = return!.send meth, *vals
|
10
|
+
bool! answer
|
11
|
+
demand answer, "...failed #{meth} with #{vals.inspect}"
|
12
|
+
end
|
13
|
+
|
14
|
+
def not_be! *args
|
15
|
+
meth, vals = args
|
16
|
+
answer = return!.send(meth, *vals)
|
17
|
+
bool! answer
|
18
|
+
demand !answer, "...#{meth} should not be true with #{vals.inspect}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def empty!
|
22
|
+
demand return!.empty?, "...must be empty."
|
23
|
+
end
|
24
|
+
|
25
|
+
def not_empty! *args
|
26
|
+
if args.empty?
|
27
|
+
demand !return!.empty?, "...can't be empty."
|
28
|
+
else
|
29
|
+
super
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end # === class All
|
34
|
+
end # === module Checked
|
data/lib/Checked/Arch.rb
CHANGED
@@ -1,12 +1,41 @@
|
|
1
1
|
class Checked
|
2
2
|
|
3
3
|
module Arch
|
4
|
+
|
5
|
+
module Class_Methods
|
6
|
+
def map name
|
7
|
+
@map = name
|
8
|
+
end
|
9
|
+
end # === module Class_Methods
|
10
|
+
|
11
|
+
def self.included klass
|
12
|
+
klass.extend Class_Methods
|
13
|
+
end
|
14
|
+
|
4
15
|
include DSL::Racked
|
16
|
+
|
17
|
+
def initialize *args
|
18
|
+
@target = nil
|
19
|
+
super
|
20
|
+
end
|
21
|
+
|
22
|
+
def request
|
23
|
+
self
|
24
|
+
end
|
5
25
|
|
6
|
-
def
|
7
|
-
|
26
|
+
def env
|
27
|
+
@env ||= {}
|
28
|
+
end
|
29
|
+
|
30
|
+
def return! val = :return_it
|
31
|
+
return @target if val === :return_it
|
32
|
+
@target = val
|
8
33
|
end
|
9
34
|
|
35
|
+
def target_name= val
|
36
|
+
request.env['target_name'] = val
|
37
|
+
end
|
38
|
+
|
10
39
|
def target_name
|
11
40
|
request.env['target_name']
|
12
41
|
end
|
@@ -14,16 +43,6 @@ class Checked
|
|
14
43
|
def original_target
|
15
44
|
request.env['original_target']
|
16
45
|
end
|
17
|
-
|
18
|
-
def matcher
|
19
|
-
@matcher ||= begin
|
20
|
-
m = args_hash['args'].first
|
21
|
-
if !m
|
22
|
-
raise Sin_Arch::Missing_Argument, "Missing argument for matcher."
|
23
|
-
end
|
24
|
-
m
|
25
|
-
end
|
26
|
-
end
|
27
46
|
|
28
47
|
#
|
29
48
|
# ::Checked::Demand::Arrays => demand
|
@@ -43,8 +62,8 @@ class Checked
|
|
43
62
|
return! return!.strip
|
44
63
|
end
|
45
64
|
|
46
|
-
def not_empty_args!
|
47
|
-
not_empty!
|
65
|
+
def not_empty_args! *args
|
66
|
+
not_empty! args
|
48
67
|
end
|
49
68
|
|
50
69
|
def fail! raw_msg
|
data/lib/Checked/Ask/Arrays.rb
CHANGED
@@ -1,31 +1,22 @@
|
|
1
1
|
|
2
2
|
|
3
3
|
class Checked
|
4
|
-
|
5
|
-
|
4
|
+
|
5
|
+
class Arrays
|
6
6
|
|
7
|
-
|
7
|
+
def symbols?
|
8
|
+
return false if return!.empty?
|
9
|
+
return!.all? { |val| val.is_a? Symbol }
|
10
|
+
end
|
8
11
|
|
9
|
-
|
12
|
+
def include_all? *args
|
13
|
+
return!.include_all?(*args)
|
14
|
+
end
|
10
15
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
return!.all? { |val| val.is_a? Symbol }
|
15
|
-
end
|
16
|
-
|
17
|
-
get
|
18
|
-
def include?
|
19
|
-
return!.include?(*args_hash['args'])
|
20
|
-
end
|
16
|
+
def exclude_all? *args
|
17
|
+
!return!.detect { |v| args.include?(v) }
|
18
|
+
end
|
21
19
|
|
22
|
-
|
23
|
-
def exclude?
|
24
|
-
!return!.include?(*args_hash['args'])
|
25
|
-
end
|
26
|
-
|
27
|
-
end # === class Arrays
|
20
|
+
end # === class Arrays
|
28
21
|
|
29
|
-
|
30
|
-
end # === class Ask
|
31
22
|
end # === class Checked
|
data/lib/Checked/Ask/Strings.rb
CHANGED
data/lib/Checked/Ask/Vars.rb
CHANGED
@@ -1,30 +1,22 @@
|
|
1
1
|
|
2
2
|
class Checked
|
3
|
-
class
|
4
|
-
class Vars < Sinatra::Base
|
5
|
-
|
6
|
-
include Checked::Arch
|
3
|
+
class Vars
|
7
4
|
|
8
|
-
|
5
|
+
def respond_to_all? *args
|
6
|
+
arr = not_empty!( args.flatten )
|
7
|
+
|
8
|
+
arr.all? { |a|
|
9
|
+
return!.respond_to? a
|
10
|
+
}
|
11
|
+
end
|
9
12
|
|
10
|
-
|
11
|
-
|
12
|
-
a = not_empty_args!
|
13
|
+
def respond_to_any? *args
|
14
|
+
arr = not_empty!(args)
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
arr.any? { |a|
|
17
|
+
return!.respond_to? a
|
18
|
+
}
|
19
|
+
end
|
18
20
|
|
19
|
-
|
20
|
-
def respond_to_any?
|
21
|
-
a = not_empty_args!
|
22
|
-
|
23
|
-
a.any? { |a|
|
24
|
-
return!.respond_to? a
|
25
|
-
}
|
26
|
-
end
|
27
|
-
|
28
|
-
end # === class Vars
|
29
|
-
end # === class Ask
|
21
|
+
end # === class Vars
|
30
22
|
end # === class Checked
|
@@ -1,100 +1,69 @@
|
|
1
1
|
|
2
2
|
class Checked
|
3
|
-
class
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
def chop_slash_r
|
70
|
-
return!.gsub "\r", ''
|
71
|
-
end
|
72
|
-
|
73
|
-
get
|
74
|
-
def os_stardard
|
75
|
-
chop_slash_r
|
76
|
-
end
|
77
|
-
|
78
|
-
get
|
79
|
-
def to_single
|
80
|
-
return!.gsub( /s\Z/, '' )
|
81
|
-
end
|
82
|
-
|
83
|
-
get
|
84
|
-
def to_plural
|
85
|
-
return!.to_single + 's'
|
86
|
-
end
|
87
|
-
|
88
|
-
get
|
89
|
-
def to_class_name
|
90
|
-
return!.split('_').map(&:capitalize).join('_')
|
91
|
-
end
|
92
|
-
|
93
|
-
get
|
94
|
-
def to_camel_case
|
95
|
-
return!.split('_').map(&:capitalize).join
|
96
|
-
end
|
97
|
-
|
98
|
-
end # === class Strings
|
99
|
-
end # === class Clean
|
3
|
+
class Strings
|
4
|
+
|
5
|
+
def untar
|
6
|
+
return!
|
7
|
+
.sub(/\.tar\.gz$/, '')
|
8
|
+
.sub(/\.tar/, '')
|
9
|
+
end
|
10
|
+
|
11
|
+
def file_names matcher
|
12
|
+
( return!.split.select { |word| word[matcher] } )
|
13
|
+
end
|
14
|
+
|
15
|
+
def file_names_by_ext matcher
|
16
|
+
names = file_names(matcher)
|
17
|
+
bases = names.map { |s|
|
18
|
+
s.sub(%r!#{matcher}$!, '')
|
19
|
+
}
|
20
|
+
|
21
|
+
names.zip bases
|
22
|
+
end
|
23
|
+
|
24
|
+
def shell
|
25
|
+
return!
|
26
|
+
.split("\n")
|
27
|
+
.map(&:strip)
|
28
|
+
.reject { |line| line.empty? }
|
29
|
+
.join(' && ')
|
30
|
+
end
|
31
|
+
|
32
|
+
def chop_ext
|
33
|
+
return!.sub /\.[^\.]+$/, ''
|
34
|
+
end
|
35
|
+
|
36
|
+
def ruby_name
|
37
|
+
File.basename chop_rb
|
38
|
+
end
|
39
|
+
|
40
|
+
def chop_rb
|
41
|
+
return!.sub %r!\.rb$!, ''
|
42
|
+
end
|
43
|
+
|
44
|
+
def chop_slash_r
|
45
|
+
return!.gsub "\r", ''
|
46
|
+
end
|
47
|
+
|
48
|
+
def os_stardard
|
49
|
+
chop_slash_r
|
50
|
+
end
|
51
|
+
|
52
|
+
def to_single
|
53
|
+
return!.gsub( /s\Z/, '' )
|
54
|
+
end
|
55
|
+
|
56
|
+
def to_plural
|
57
|
+
return!.to_single + 's'
|
58
|
+
end
|
59
|
+
|
60
|
+
def to_class_name
|
61
|
+
return!.split('_').map(&:capitalize).join('_')
|
62
|
+
end
|
63
|
+
|
64
|
+
def to_camel_case
|
65
|
+
return!.split('_').map(&:capitalize).join
|
66
|
+
end
|
67
|
+
|
68
|
+
end # === class Strings
|
100
69
|
end # === class Checked
|
data/lib/Checked/DSL.rb
CHANGED
@@ -1,15 +1,18 @@
|
|
1
1
|
class Object
|
2
|
+
|
3
|
+
def Checked= val
|
4
|
+
@sin_arch = val
|
5
|
+
val.return! self
|
6
|
+
val
|
7
|
+
end
|
2
8
|
|
3
9
|
def Checked
|
4
|
-
|
5
|
-
|
6
|
-
o.value = self
|
7
|
-
o
|
8
|
-
end
|
10
|
+
raise "Not defined yet." unless Checked_applys?
|
11
|
+
@sin_arch
|
9
12
|
end
|
10
13
|
|
11
14
|
def Checked_applys?
|
12
|
-
|
15
|
+
instance_variable_defined?(:@sin_arch)
|
13
16
|
end
|
14
17
|
|
15
18
|
def method_missing meth_name, *args
|
@@ -22,69 +25,16 @@ class Object
|
|
22
25
|
return(super) if @count > 6
|
23
26
|
|
24
27
|
raise "Unknown block." if block_given?
|
25
|
-
|
26
|
-
|
27
|
-
rescue Sin_Arch::Not_Found
|
28
|
-
return super
|
29
|
-
end
|
28
|
+
return super unless Checked().respond_to?(meth_name)
|
29
|
+
result = Checked().send meth_name, *args
|
30
30
|
@count = 1
|
31
31
|
|
32
|
-
result.Checked
|
32
|
+
result.Checked= Checked() if meth_name.to_s['!'] && self.class == result.class
|
33
33
|
result
|
34
34
|
end
|
35
35
|
|
36
36
|
end # === class Object
|
37
37
|
|
38
|
-
class Checked
|
39
|
-
|
40
|
-
class Obj
|
41
|
-
|
42
|
-
module Base
|
43
|
-
|
44
|
-
attr_accessor :map, :name, :value, :app
|
45
|
-
|
46
|
-
def initialize
|
47
|
-
off!
|
48
|
-
self.map = nil
|
49
|
-
self.name = nil
|
50
|
-
end
|
51
|
-
|
52
|
-
def << checked
|
53
|
-
on! checked.map
|
54
|
-
self.name = checked.name
|
55
|
-
end
|
56
|
-
|
57
|
-
def on?
|
58
|
-
@on
|
59
|
-
end
|
60
|
-
|
61
|
-
def on! new_map
|
62
|
-
raise ArgumentError, "Map value unacceptable: #{new_map.inspect}" unless new_map
|
63
|
-
self.map = new_map
|
64
|
-
@on = true
|
65
|
-
end
|
66
|
-
|
67
|
-
def off?
|
68
|
-
!@on
|
69
|
-
end
|
70
|
-
|
71
|
-
def off!
|
72
|
-
@on = false
|
73
|
-
end
|
74
|
-
|
75
|
-
def get! meth_name, *args
|
76
|
-
self.app = Checked::App.new
|
77
|
-
app.get!("/#{map}/#{meth_name}", 'name'=>name, 'value'=>value, 'args'=>args)
|
78
|
-
end
|
79
|
-
|
80
|
-
end # === module Base
|
81
|
-
|
82
|
-
include Base
|
83
|
-
|
84
|
-
end # === class Obj
|
85
|
-
|
86
|
-
end # === class Checked
|
87
|
-
|
88
38
|
class Checked
|
89
39
|
module DSL
|
90
40
|
|
@@ -180,11 +130,11 @@ class Checked
|
|
180
130
|
%w{ Array Bool File_Path Hash String Symbol Var }.each { |name|
|
181
131
|
eval! %~
|
182
132
|
def #{name}!( *args )
|
183
|
-
Check!( '#{name
|
133
|
+
Check!( '#{name}s', *args ).check!
|
184
134
|
end
|
185
135
|
~
|
186
136
|
}
|
187
|
-
|
137
|
+
|
188
138
|
def demand *pars
|
189
139
|
if pars.size == 2
|
190
140
|
val = return!
|
@@ -203,7 +153,7 @@ class Checked
|
|
203
153
|
def Stripped! *args
|
204
154
|
v = String!(*args)
|
205
155
|
n = v.strip
|
206
|
-
n.Checked
|
156
|
+
n.Checked= v.Checked
|
207
157
|
n
|
208
158
|
end
|
209
159
|
|
@@ -217,9 +167,10 @@ class Checked
|
|
217
167
|
raise ArgumentError, "Unknown values for name/value: #{name_and_or_val.inspect}"
|
218
168
|
end
|
219
169
|
|
220
|
-
val.Checked.
|
221
|
-
val.Checked.
|
222
|
-
val.Checked.
|
170
|
+
val.Checked=Checked.const_get(ns.to_sym).new
|
171
|
+
val.Checked.target_name = name
|
172
|
+
val.Checked.return! val
|
173
|
+
val.Checked.check!
|
223
174
|
val
|
224
175
|
end
|
225
176
|
|
@@ -1,73 +1,61 @@
|
|
1
1
|
class Checked
|
2
|
-
class
|
3
|
-
class Arrays < Sinatra::Base
|
2
|
+
class Arrays
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
get
|
9
|
-
def check!
|
10
|
-
array! return!
|
11
|
-
end
|
4
|
+
def check!
|
5
|
+
array! return!
|
6
|
+
end
|
12
7
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
return!.include?(nil), \
|
8
|
+
def no_nils!
|
9
|
+
demand \
|
10
|
+
return!.include?(nil), \
|
17
11
|
"...can't contain nils."
|
18
|
-
|
12
|
+
end
|
19
13
|
|
20
|
-
|
21
|
-
|
22
|
-
return!.each { |memo,s|
|
14
|
+
def no_empty_strings!
|
15
|
+
return!.each { |memo,s|
|
23
16
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
17
|
+
final = if s.respond_to?(:readlines)
|
18
|
+
s.rewind
|
19
|
+
s.readlines
|
20
|
+
else
|
21
|
+
s
|
22
|
+
end
|
30
23
|
|
31
|
-
|
32
|
-
|
24
|
+
demand \
|
25
|
+
final.is_a?(::String), \
|
33
26
|
"...can't contain unknown class: #{final.inspect}"
|
34
|
-
|
35
|
-
|
27
|
+
|
28
|
+
demand \
|
36
29
|
final.is_a?(::String) && final.strip.empty?, \
|
37
30
|
"...can't contain empty strings."
|
38
|
-
|
39
|
-
|
31
|
+
|
32
|
+
}
|
40
33
|
return!
|
41
|
-
|
34
|
+
end
|
42
35
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
return!.all? { |v| v.is_a?(Symbol) }, \
|
36
|
+
def symbols!
|
37
|
+
not_empty!
|
38
|
+
demand \
|
39
|
+
return!.all? { |v| v.is_a?(Symbol) }, \
|
48
40
|
"...contains a non-symbol."
|
49
|
-
|
41
|
+
end
|
50
42
|
|
51
|
-
|
52
|
-
|
53
|
-
demand return!.include?(matcher), \
|
43
|
+
def include! matcher
|
44
|
+
demand return!.include?(matcher), \
|
54
45
|
"...must contain: #{matcher.inspect}"
|
55
|
-
|
46
|
+
end
|
56
47
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
end
|
48
|
+
def exclude! matcher
|
49
|
+
demand val.include?(matcher), "...can't contain #{matcher.inspect}"
|
50
|
+
end
|
61
51
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
return!.reject { |val| val == matcher }.empty?, \
|
52
|
+
def matches_only! matcher
|
53
|
+
demand \
|
54
|
+
return!.reject { |val| val == matcher }.empty?, \
|
66
55
|
"...invalid elements: #{arr.inspect}"
|
67
|
-
|
68
|
-
|
56
|
+
end
|
57
|
+
|
69
58
|
|
70
|
-
|
71
|
-
end # === class Demand
|
59
|
+
end # === class Arrays
|
72
60
|
end # === class Checked
|
73
61
|
|
data/lib/Checked/Demand/Bools.rb
CHANGED
@@ -1,30 +1,22 @@
|
|
1
1
|
class Checked
|
2
|
-
class
|
3
|
-
class Bools < Sinatra::Base
|
4
|
-
|
5
|
-
include Checked::Arch
|
6
|
-
map '/bool!'
|
2
|
+
class Bools
|
7
3
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
13
|
-
|
14
|
-
get
|
15
|
-
def true!
|
16
|
-
is_true = return!.class == TrueClass
|
17
|
-
demand is_true, "...must be true (TrueClass)."
|
18
|
-
end
|
19
|
-
|
20
|
-
get
|
21
|
-
def false!
|
22
|
-
is_false = return!.class == FalseClass
|
23
|
-
demand is_false, "...must be false (FalseClass)."
|
24
|
-
end
|
4
|
+
def check!
|
5
|
+
is_bool = [TrueClass, FalseClass].include?(return!.class)
|
6
|
+
demand is_bool, "...must be either of TrueClass or FalseClass."
|
7
|
+
end
|
25
8
|
|
26
|
-
|
27
|
-
|
9
|
+
def true!
|
10
|
+
is_true = return!.class == TrueClass
|
11
|
+
demand is_true, "...must be true (TrueClass)."
|
12
|
+
end
|
13
|
+
|
14
|
+
def false!
|
15
|
+
is_false = return!.class == FalseClass
|
16
|
+
demand is_false, "...must be false (FalseClass)."
|
17
|
+
end
|
18
|
+
|
19
|
+
end # === class Bools
|
28
20
|
end # === class Checked
|
29
|
-
|
21
|
+
|
30
22
|
|