Checked 1.2.3 → 2.0.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/lib/Checked.rb CHANGED
@@ -1,26 +1,62 @@
1
1
  require "Checked/version"
2
- require 'Uni_Arch'
2
+ require "Checked/DSL"
3
+ require "Checked/Arch"
3
4
 
4
- require "Checked/Base/DSL"
5
- require "Checked/Base/DSL_Obj"
6
- require "Checked/Base/Base"
7
- require "Checked/Base/Arch"
8
5
 
6
+ class Checked
7
+
8
+ class Check_Args < Sinatra::Base
9
+
10
+ include Checked::Arch
11
+
12
+ before
13
+ def set_target
14
+ keys! args_hash, 'name', 'value', 'args'
15
+ a = args_hash['args']
16
+ t = args_hash['value']
17
+
18
+ demand a, array?(a), ':args must be an array.'
19
+
20
+ request.env['original_target'] = t
21
+
22
+ # === target_name
23
+ request.env['target_name'] ||= begin
24
+ if t.respond_to?(:english_name)
25
+ t.english_name
26
+ elsif !args_hash['name'].to_s.strip.empty?
27
+ args_hash['name'].strip
28
+ else
29
+ t.class.name.gsub('_', ' ')
30
+ end
31
+ end
32
+
33
+ return! t
34
+ end
35
+
36
+ end # === class Check_Args < Sinatra::Base
9
37
 
10
- %w{ Demand Ask Clean }.each { |klass|
38
+ use Check_Args
39
+
40
+ class App
41
+ include Sin_Arch::App
42
+ end # === class App
43
+
44
+ end # === class Checked
45
+
46
+
47
+
48
+ %w{ Ask Clean Demand }.each { |klass|
49
+
11
50
  require "Checked/#{klass}/#{klass}"
12
51
 
13
52
  Dir.glob(File.join File.dirname(__FILE__), "Checked/#{klass}/*.rb").each { |path|
53
+ next if path["/#{klass}/#{klass}.rb"]
14
54
 
15
- # Require the file.
16
55
  path =~ %r!lib/Checked/(.+)/(.+)\.rb!
17
- require( "Checked/#{$1}/#{$2}" ) if $1 && $2
18
-
19
- # Set up routes.
20
- if klass != $2
21
- Checked::Arch.use Checked.const_get(:"#{klass}").const_get(:"#{$2}")
22
- end
56
+ require( "Checked/#{$1}/#{$2}" )
57
+ Checked.use eval("Checked::#{klass}::#{$2}")
23
58
  }
59
+
24
60
  }
25
61
 
26
62
 
data/spec/main.rb CHANGED
@@ -3,11 +3,15 @@ require File.expand_path('spec/helper')
3
3
  require "Bacon_Colored"
4
4
  require 'Checked'
5
5
 
6
- class Box
7
- include Checked::DSL
6
+
7
+ shared :ruby_dsl do
8
+ before { extend Checked::DSL::Ruby }
9
+ end
10
+
11
+ shared :racked_dsl do
12
+ before { extend Checked::DSL::Racked }
8
13
  end
9
14
 
10
- BOX = Box.new
11
15
 
12
16
  FOLDER = ("/tmp/Checked_Test")
13
17
  %x! mkdir -p #{FOLDER}!
data/spec/tests/Ask.rb CHANGED
@@ -6,13 +6,15 @@
6
6
 
7
7
  describe "array! :include?" do
8
8
 
9
+ behaves_like :racked_dsl
10
+
9
11
  it "returns true if array contains element." do
10
- BOX.array!([:a]).include?(:a)
12
+ Array!([:a]).include?(:a)
11
13
  .should.be == true
12
14
  end
13
15
 
14
16
  it "returns false if array does not contain element" do
15
- BOX.array!([:a]).include?(:b)
17
+ Array!([:a]).include?(:b)
16
18
  .should.be == false
17
19
  end
18
20
 
@@ -20,13 +22,15 @@ end # === describe Ask :includes
20
22
 
21
23
  describe "array! :exclude?" do
22
24
 
25
+ behaves_like :racked_dsl
26
+
23
27
  it "returns true if array excludes element." do
24
- BOX.array!([:a]).exclude?(:b)
28
+ Array!([:a]).exclude?(:b)
25
29
  .should.be == true
26
30
  end
27
31
 
28
32
  it "returns false if array does contains element" do
29
- BOX.array!([:a]).exclude?(:a)
33
+ Array!([:a]).exclude?(:a)
30
34
  .should.be == false
31
35
  end
32
36
 
@@ -34,8 +38,10 @@ end # === describe Ask :exclude
34
38
 
35
39
  describe "array! symbols?" do
36
40
 
41
+ behaves_like :racked_dsl
42
+
37
43
  it 'returns true if all elements are symbols' do
38
- BOX.array!([:a, :b]).symbols?
44
+ Array!([:a, :b]).symbols?
39
45
  .should.be == true
40
46
  end
41
47
 
@@ -65,67 +71,52 @@ end # === describe array! symbols?
65
71
  # ============================ STRINGS
66
72
  # ============================
67
73
 
68
- describe "string! :include?" do
69
-
70
- it "returns true if string contains regexp." do
71
- BOX.string!(": a").include?(/: a/)
72
- .should.be == true
73
- end
74
-
75
- it "returns false if string does not element" do
76
- BOX.string!(" :a ").include?(/ :b /)
77
- .should.be == false
78
- end
79
-
80
- end # === describe Ask :includes
81
74
 
82
- describe "string! :exclude?" do
75
+ # ============================
76
+ # ============================ VARS
77
+ # ============================
78
+
79
+ describe "Var! :respond_to_all?" do
83
80
 
84
- it "returns true if string excludes regexp." do
85
- BOX.string!(": a").exclude?(/: b/)
86
- .should.be == true
87
- end
81
+ behaves_like :racked_dsl
88
82
 
89
- it "returns false if string does not excludes element" do
90
- BOX.string!(" :a ").exclude?(/ :a /)
91
- .should.be == false
83
+ it 'returns true if it responds to methods' do
84
+ Var!( [] ).respond_to_all?(:[], :to_s, :pop)
85
+ .should == true
92
86
  end
93
87
 
94
- end # === describe Ask :excludes
95
-
96
-
97
- describe "ask empty?" do
98
-
99
- it "returns true if string is :empty? after applying :strip" do
100
- BOX.string!(" \n ").empty?.should.be === true
88
+ it 'returns false if it does not to at least one method' do
89
+ Var!( [] ).respond_to_all?(:[], :to_s, :keys)
90
+ .should == false
101
91
  end
102
92
 
103
- it "returns false if string is not :empty? after applying :strip" do
104
- BOX.string!(" n ").empty?.should.be === false
93
+ it 'raises Demand::Failed if arg list is empty' do
94
+ lambda{ Var!( [] ).respond_to_all? }
95
+ .should.raise(Checked::Demand::Failed)
96
+ .message.should.match %r!can't be empty!
105
97
  end
106
98
 
107
-
108
- end # === describe Ask Strings
99
+ end # === describe var! :respond_to?
109
100
 
110
- # ============================
111
- # ============================ VARS
112
- # ============================
113
101
 
114
- describe "var! :respond_to?" do
102
+ describe "Var! :respond_to_any?" do
115
103
 
116
- it 'returns true if it responds to methods' do
117
- BOX.var!( [] ).respond_to?(:[], :to_s, :pop)
104
+ behaves_like :racked_dsl
105
+
106
+ it 'returns true if it responds to any methods' do
107
+ Var!( [] ).respond_to_any?(:[], :jetsons, :jump_it)
118
108
  .should == true
119
109
  end
120
110
 
121
- it 'returns false if it does not to at least one method' do
122
- BOX.var!( [] ).respond_to?(:[], :to_s, :keys)
111
+ it 'returns false if it does not respond to all methods' do
112
+ Var!( [] ).respond_to_any?(:jetson, :to_flintstones, :thundar)
123
113
  .should == false
124
114
  end
125
115
 
126
- it 'returns false if arg list is empty' do
127
- BOX.var!( [] ).respond_to?
128
- .should == false
116
+ it 'raises Demand::Failed if arg list is empty' do
117
+ lambda{ Var!( [] ).respond_to_any? }
118
+ .should.raise(Checked::Demand::Failed)
119
+ .message.should.match %r!can't be empty!
129
120
  end
130
121
 
131
122
  end # === describe var! :respond_to?
data/spec/tests/Clean.rb CHANGED
@@ -6,50 +6,54 @@
6
6
 
7
7
  describe "Clean :chop_ext" do
8
8
 
9
+ behaves_like :racked_dsl
9
10
 
10
11
  it "should chop off the extension of a file string: /etc/something.txt" do
11
- BOX.string!("/etc/something.txt").chop_ext.should == '/etc/something'
12
+ String!("/etc/something.txt").chop_ext.should == '/etc/something'
12
13
  end
13
14
 
14
15
  it "should chop off the extension of a file string: /etc/something.rb" do
15
- BOX.string!("/etc/something.rb").chop_rb.should == '/etc/something'
16
+ String!("/etc/something.rb").chop_rb.should == '/etc/something'
16
17
  end
17
18
 
18
19
  it "should not chop off a non-.rb extension for :chop_rb" do
19
- BOX.string!("/etc/something.rbs").chop_rb.should == '/etc/something.rbs'
20
+ String!("/etc/something.rbs").chop_rb.should == '/etc/something.rbs'
20
21
  end
21
22
 
22
23
  it "should not chop off an extension if it has not" do
23
- BOX.string!("/etc/something").chop_rb.should == '/etc/something'
24
+ String!("/etc/something").chop_rb.should == '/etc/something'
24
25
  end
25
26
 
26
27
  it "should not chop off an extension if it includes '.' in a dir: /etc/rc.d/x-something" do
27
- BOX.string!("/etc/rc.d/x-something").chop_rb.should == '/etc/rc.d/x-something'
28
+ String!("/etc/rc.d/x-something").chop_rb.should == '/etc/rc.d/x-something'
28
29
  end
29
30
 
30
31
  end # === describe
31
32
 
32
33
  describe "Clean :ruby_name" do
33
34
 
35
+ behaves_like :racked_dsl
34
36
 
35
37
  it 'should return the basename without .rb' do
36
- BOX.string!("/dir/some.path/String.rb").ruby_name.should.be == 'String'
38
+ String!( "/dir/somepath/String.rb" ).ruby_name.should == 'String'
37
39
  end
38
40
 
39
41
  it 'should be the equivalent to :chop_rb if it is just a filename without a dir' do
40
- BOX.string!("String.rb").ruby_name.should.be == 'String'
42
+ String!("String.rb").ruby_name.should.be == 'String'
41
43
  end
42
44
 
43
45
  end # === describe :ruby_name
44
46
 
45
47
  describe "Clean :chop_slash_r" do
46
48
 
49
+ behaves_like :racked_dsl
50
+
47
51
  it "should remove all instances of \\r" do
48
52
  string = %@
49
53
  Hi\r\n
50
54
  Ok\r\n
51
55
  @
52
- BOX.string!(string).chop_slash_r.should.be == string.gsub("\r", '')
56
+ String!(string).chop_slash_r.should.be == string.gsub("\r", '')
53
57
  end
54
58
 
55
59
 
@@ -58,13 +62,14 @@ end # === describe :chop_slash_r
58
62
 
59
63
  describe "Clean :os_stardard" do
60
64
 
65
+ behaves_like :racked_dsl
61
66
 
62
67
  it "should remove all \\r and strip" do
63
68
  string = %@
64
69
  Hi\r\n
65
70
  Ok\r\n
66
71
  @
67
- BOX.string!(string).os_stardard.should.be == string.strip.gsub("\r", '')
72
+ String!(string).os_stardard.should.be == string.strip.gsub("\r", '')
68
73
  end
69
74
 
70
75
  end # === describe
data/spec/tests/DSL.rb CHANGED
@@ -1,15 +1,123 @@
1
+ # ============================
2
+ # ============================ Ruby
3
+ # ============================
4
+
5
+ describe "array! " do
6
+
7
+ behaves_like :ruby_dsl
8
+
9
+ it 'returns the array' do
10
+ array!([:a, :b]).should == [:a, :b]
11
+ end
12
+
13
+ it 'raises Demand::Failed if not an array' do
14
+ lambda { array!(:a) }
15
+ .should.raise(Checked::Demand::Failed)
16
+ .message.should.match %r!Symbol, :a, is not an array.!i
17
+ end
18
+
19
+ end # === describe array! check!
20
+
21
+ describe "hash! " do
22
+
23
+ behaves_like :ruby_dsl
24
+
25
+ it 'returns the hash' do
26
+ h = {:name=>:a, :val=>:b}
27
+ hash!(h).should == h
28
+ end
29
+
30
+ it 'raises Demand::Failed if not a hash' do
31
+ lambda { hash!(:a) }
32
+ .should.raise(Checked::Demand::Failed)
33
+ .message.should == "Symbol, :a, must be a hash."
34
+ end
35
+
36
+ end # === describe array! check!
37
+
38
+ describe "string! " do
39
+
40
+ behaves_like :ruby_dsl
41
+
42
+ it 'returns the string' do
43
+ s = 'str'
44
+ string!(s).should == s
45
+ end
46
+
47
+ it 'raises Demand::Failed if not a string' do
48
+ lambda { string!(:a) }
49
+ .should.raise(Checked::Demand::Failed)
50
+ .message.should == "Symbol, :a, must be a string."
51
+ end
52
+
53
+ end # === describe array! check!
54
+
55
+ describe "bool! " do
56
+
57
+ behaves_like :ruby_dsl
58
+
59
+ it 'returns the boolean' do
60
+ b = false
61
+ bool!(b).should == b
62
+ end
63
+
64
+ end # === describe array! check!
65
+
66
+ describe "true! " do
67
+
68
+ behaves_like :ruby_dsl
69
+
70
+ it 'returns true' do
71
+ true!(true).should == true
72
+ end
73
+
74
+ end # === describe array! check!
75
+
76
+ describe "false! " do
77
+
78
+ behaves_like :ruby_dsl
79
+
80
+ it 'returns false' do
81
+ false!(false).should == false
82
+ end
83
+
84
+ end # === describe array! check!
85
+
86
+
87
+
88
+ # ============================
89
+ # ============================ Racked
90
+ # ============================
91
+
92
+ describe "Stripped!" do
93
+
94
+ behaves_like :racked_dsl
95
+
96
+ it "returns true if string is :empty? after applying :strip" do
97
+ Stripped!(" \n ").empty?.should.be === true
98
+ end
99
+
100
+ it "returns false if string is not :empty? after applying :strip" do
101
+ Stripped!(" n ").empty?.should.be === false
102
+ end
103
+
104
+
105
+ end # === describe Stripped!
1
106
 
2
107
  describe "String!" do
3
108
 
4
- it 'returns a string' do
5
- BOX.String!('str').should.be == 'str'
109
+ behaves_like :racked_dsl
110
+
111
+ it 'returns the string' do
112
+ s = 'str'
113
+ String!( s ).object_id.should.be == s.object_id
6
114
  end
7
115
 
8
116
  it 'raises Demand::Failed if not a string' do
9
117
  lambda {
10
- BOX.String!([])
118
+ String!([])
11
119
  }.should.raise(Checked::Demand::Failed)
12
- .message.should.match %r!Array, \[\], must be a String!
120
+ .message.should.match %r!Array, \[\], must be a String!i
13
121
  end
14
122
 
15
123
  end # === describe String!
@@ -17,15 +125,18 @@ end # === describe String!
17
125
 
18
126
  describe "Array!" do
19
127
 
20
- it 'returns an array' do
21
- BOX.Array!([:arr]).should.be == [:arr]
128
+ behaves_like :racked_dsl
129
+
130
+ it 'returns the array' do
131
+ t = [:arr]
132
+ Array!( t ).object_id.should.be == t.object_id
22
133
  end
23
134
 
24
135
  it 'raises Demand::Failed if not an Array' do
25
136
  lambda {
26
- BOX.Array!(:a)
137
+ Array!(:a)
27
138
  }.should.raise(Checked::Demand::Failed)
28
- .message.should.match %r!Symbol, :a, is not an Array.!
139
+ .message.should.match %r!Symbol, :a, is not an array.!i
29
140
  end
30
141
 
31
142
  end # === describe Array!
@@ -33,15 +144,17 @@ end # === describe Array!
33
144
 
34
145
  describe "File_Path!" do
35
146
 
147
+ behaves_like :racked_dsl
148
+
36
149
  it 'returns a stripped string' do
37
- BOX.File_Path!(" ~/ ").should.be == File.expand_path("~/")
150
+ File_Path!(" ~/ ").should.be == File.expand_path("~/")
38
151
  end
39
152
 
40
153
  it 'raises Demand::Failed if not a string' do
41
154
  lambda {
42
- BOX.File_Path!(:something)
155
+ File_Path!(:something)
43
156
  }.should.raise(Checked::Demand::Failed)
44
- .message.should.match %r!Symbol, :something, must be a String!
157
+ .message.should.match %r!Symbol, :something, must be a String!i
45
158
  end
46
159
 
47
160
  end # === describe String!
@@ -49,15 +162,17 @@ end # === describe String!
49
162
 
50
163
  describe "Bool!" do
51
164
 
165
+ behaves_like :ruby_dsl
166
+
52
167
  it 'returns original value' do
53
- BOX.Bool!(true).should.be === true
54
- BOX.Bool!(false).should.be === false
168
+ bool!(true).should.be === true
169
+ bool!(false).should.be === false
55
170
  end
56
171
 
57
172
  it 'raises Demand::Failed if not a boolean' do
58
- lambda { BOX.Bool!(:true) }
173
+ lambda { bool!(:true) }
59
174
  .should.raise(Checked::Demand::Failed)
60
- .message.should.match %r!Symbol, :true, must be either of TrueClass or FalseClass!
175
+ .message.should == "Symbol, :true, must be either true (TrueClass) or false (FalseClass)."
61
176
  end
62
177
 
63
178
  end # === describe Bool!
@@ -65,12 +180,14 @@ end # === describe Bool!
65
180
 
66
181
  describe "True!" do
67
182
 
183
+ behaves_like :ruby_dsl
184
+
68
185
  it 'returns original value' do
69
- BOX.True!(true).should.be === true
186
+ true!(true).should.be === true
70
187
  end
71
188
 
72
189
  it 'raises Demand::Failed if not true' do
73
- lambda { BOX.True!(false) }
190
+ lambda { true!(false) }
74
191
  .should.raise(Checked::Demand::Failed)
75
192
  .message.should.match %r!FalseClass, false, must be true!
76
193
  end
@@ -80,12 +197,14 @@ end # === describe True!
80
197
 
81
198
  describe "False!" do
82
199
 
200
+ behaves_like :ruby_dsl
201
+
83
202
  it 'returns original value' do
84
- BOX.False!(false).should.be === false
203
+ false!(false).should.be === false
85
204
  end
86
205
 
87
206
  it 'raises Demand::Failed if not false' do
88
- lambda { BOX.False!(true) }
207
+ lambda { false!(true) }
89
208
  .should.raise(Checked::Demand::Failed)
90
209
  .message.should.match %r!TrueClass, true, must be false!
91
210
  end