Checked 1.0.0 → 1.1.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/Ask/Arrays.rb +1 -0
- data/lib/Checked/Ask/Strings.rb +18 -17
- data/lib/Checked/Ask/Vars.rb +1 -0
- data/lib/Checked/Base/Arch.rb +14 -1
- data/lib/Checked/Base/Base.rb +0 -2
- data/lib/Checked/Base/DSL.rb +9 -1
- data/lib/Checked/Clean/Strings.rb +1 -0
- data/lib/Checked/Demand/Arrays.rb +3 -3
- data/lib/Checked/Demand/Bools.rb +3 -3
- data/lib/Checked/Demand/Demand.rb +2 -7
- data/lib/Checked/Demand/File_Paths.rb +5 -5
- data/lib/Checked/Demand/Hashs.rb +3 -3
- data/lib/Checked/Demand/Strings.rb +3 -3
- data/lib/Checked/Demand/Symbols.rb +3 -3
- data/lib/Checked/Demand/Vars.rb +1 -1
- data/lib/Checked/version.rb +1 -1
- data/spec/tests/DSL.rb +64 -2
- data/spec/tests/Demand.rb +1 -1
- metadata +9 -9
data/lib/Checked/Ask/Arrays.rb
CHANGED
data/lib/Checked/Ask/Strings.rb
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
1
1
|
|
|
2
2
|
module Checked
|
|
3
3
|
class Ask
|
|
4
|
-
|
|
4
|
+
class Strings
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
namespace '/string!'
|
|
6
|
+
include Uni_Arch::Base
|
|
7
|
+
include Ask::Base
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
def empty?
|
|
12
|
-
target.strip.empty?
|
|
13
|
-
end
|
|
9
|
+
namespace '/string!'
|
|
14
10
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
route
|
|
12
|
+
def empty?
|
|
13
|
+
target.strip.empty?
|
|
14
|
+
end
|
|
19
15
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
route
|
|
17
|
+
def include?
|
|
18
|
+
!!target[*args]
|
|
19
|
+
end
|
|
24
20
|
|
|
25
|
-
|
|
21
|
+
route
|
|
22
|
+
def exclude?
|
|
23
|
+
!target[*args]
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
end # === class Strings
|
|
26
27
|
end # === class Ask
|
|
27
28
|
end # === module Checked
|
data/lib/Checked/Ask/Vars.rb
CHANGED
data/lib/Checked/Base/Arch.rb
CHANGED
|
@@ -1,13 +1,26 @@
|
|
|
1
1
|
|
|
2
2
|
module Checked
|
|
3
3
|
class Arch
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
include Uni_Arch::Base
|
|
5
6
|
|
|
6
7
|
before
|
|
7
8
|
def save_key
|
|
8
9
|
request.response.body= request.headers.check_target
|
|
9
10
|
end
|
|
10
11
|
|
|
12
|
+
before
|
|
13
|
+
def run_check
|
|
14
|
+
return if request.path['/var!/']
|
|
15
|
+
return if request.path['/check!/']
|
|
16
|
+
request.response.body= begin
|
|
17
|
+
path = request.path.split('/')[0,2].join('/') + "/check!/"
|
|
18
|
+
app = Checked::Arch.new( path, :check_name => request.headers.check_name, :check_target => request.response.body )
|
|
19
|
+
app.fulfill_request
|
|
20
|
+
app.request.response.body
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
11
24
|
after_method
|
|
12
25
|
def save_last_response
|
|
13
26
|
unless request.path[%r@!/\Z@]
|
data/lib/Checked/Base/Base.rb
CHANGED
data/lib/Checked/Base/DSL.rb
CHANGED
|
@@ -4,7 +4,7 @@ module Checked
|
|
|
4
4
|
|
|
5
5
|
# ============ Demand ==============
|
|
6
6
|
|
|
7
|
-
%w{ String Array Hash }.each { |name|
|
|
7
|
+
%w{ String Array File_Path Hash Bool }.each { |name|
|
|
8
8
|
eval %~
|
|
9
9
|
def #{name}!( *args )
|
|
10
10
|
#{name.downcase}!(*args).check!
|
|
@@ -12,6 +12,14 @@ module Checked
|
|
|
12
12
|
~
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
%w{ True False }.each { |bool|
|
|
16
|
+
eval %~
|
|
17
|
+
def #{bool}! *args
|
|
18
|
+
bool!(*args).#{bool.downcase}!
|
|
19
|
+
end
|
|
20
|
+
~
|
|
21
|
+
}
|
|
22
|
+
|
|
15
23
|
%w{ var array bool file_path string symbol hash }.each { |klass|
|
|
16
24
|
eval %~
|
|
17
25
|
def #{klass}! *args
|
data/lib/Checked/Demand/Bools.rb
CHANGED
|
@@ -2,12 +2,12 @@ module Checked
|
|
|
2
2
|
class Demand
|
|
3
3
|
class Bools
|
|
4
4
|
|
|
5
|
+
include Uni_Arch::Base
|
|
5
6
|
include Demand::Base
|
|
6
|
-
|
|
7
7
|
namespace '/bool!'
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
def
|
|
9
|
+
route
|
|
10
|
+
def check!
|
|
11
11
|
fail!("...must be either of TrueClass or FalseClass.") unless [TrueClass, FalseClass].include?(target.class)
|
|
12
12
|
end
|
|
13
13
|
|
|
@@ -4,16 +4,11 @@ module Checked
|
|
|
4
4
|
class Demand
|
|
5
5
|
|
|
6
6
|
Failed = Class.new(RuntimeError)
|
|
7
|
-
|
|
7
|
+
|
|
8
8
|
module Base
|
|
9
9
|
|
|
10
10
|
include Checked::Base
|
|
11
|
-
|
|
12
|
-
route "/!w!!/check!/"
|
|
13
|
-
def check!
|
|
14
|
-
# do nothing
|
|
15
|
-
end
|
|
16
|
-
|
|
11
|
+
|
|
17
12
|
def err_msg msg = "...is invalid."
|
|
18
13
|
message = if msg.strip[ %r!^\.\.\.! ]
|
|
19
14
|
msg.sub('...', '').strip
|
|
@@ -2,12 +2,12 @@ module Checked
|
|
|
2
2
|
class Demand
|
|
3
3
|
class File_Paths
|
|
4
4
|
|
|
5
|
+
include Uni_Arch::Base
|
|
5
6
|
include Demand::Base
|
|
6
|
-
|
|
7
7
|
namespace '/file_path!'
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
def
|
|
9
|
+
route
|
|
10
|
+
def check!
|
|
11
11
|
fail!('...must be a String.') unless target.is_a?(String)
|
|
12
12
|
|
|
13
13
|
strip_target
|
|
@@ -18,7 +18,7 @@ module Checked
|
|
|
18
18
|
|
|
19
19
|
route
|
|
20
20
|
def hostname!
|
|
21
|
-
|
|
21
|
+
fail!("...has invalid characters: #{$1.inspect}") if target[ %r!([^\dA-Za-z_-]+)! ]
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
route
|
|
@@ -54,7 +54,7 @@ module Checked
|
|
|
54
54
|
# fs_path => File system object path
|
|
55
55
|
#
|
|
56
56
|
def fs_path?
|
|
57
|
-
request.path[%r!(_|/)(dir|file)[^a-zA-Z]+\Z!]
|
|
57
|
+
request.path[%r!(_|/)(dir|file|check)[^a-zA-Z]+\Z!]
|
|
58
58
|
end
|
|
59
59
|
|
|
60
60
|
end # === class File_Addresses
|
data/lib/Checked/Demand/Hashs.rb
CHANGED
data/lib/Checked/Demand/Vars.rb
CHANGED
data/lib/Checked/version.rb
CHANGED
data/spec/tests/DSL.rb
CHANGED
|
@@ -5,7 +5,7 @@ describe "String!" do
|
|
|
5
5
|
BOX.String!('str').should.be == 'str'
|
|
6
6
|
end
|
|
7
7
|
|
|
8
|
-
it '
|
|
8
|
+
it 'raises Demand::Failed if not a string' do
|
|
9
9
|
lambda {
|
|
10
10
|
BOX.String!([])
|
|
11
11
|
}.should.raise(Checked::Demand::Failed)
|
|
@@ -21,11 +21,73 @@ describe "Array!" do
|
|
|
21
21
|
BOX.Array!([:arr]).should.be == [:arr]
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
-
it '
|
|
24
|
+
it 'raises Demand::Failed if not an Array' do
|
|
25
25
|
lambda {
|
|
26
26
|
BOX.Array!(:a)
|
|
27
27
|
}.should.raise(Checked::Demand::Failed)
|
|
28
28
|
.message.should.match %r!Symbol, :a, is not an Array.!
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
+
end # === describe Array!
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
describe "File_Path!" do
|
|
35
|
+
|
|
36
|
+
it 'returns a stripped string' do
|
|
37
|
+
BOX.File_Path!(" ~/ ").should.be == File.expand_path("~/")
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it 'raises Demand::Failed if not a string' do
|
|
41
|
+
lambda {
|
|
42
|
+
BOX.File_Path!(:something)
|
|
43
|
+
}.should.raise(Checked::Demand::Failed)
|
|
44
|
+
.message.should.match %r!Symbol, :something, must be a String!
|
|
45
|
+
end
|
|
46
|
+
|
|
31
47
|
end # === describe String!
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
describe "Bool!" do
|
|
51
|
+
|
|
52
|
+
it 'returns original value' do
|
|
53
|
+
BOX.Bool!(true).should.be === true
|
|
54
|
+
BOX.Bool!(false).should.be === false
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it 'raises Demand::Failed if not a boolean' do
|
|
58
|
+
lambda { BOX.Bool!(:true) }
|
|
59
|
+
.should.raise(Checked::Demand::Failed)
|
|
60
|
+
.message.should.match %r!Symbol, :true, must be either of TrueClass or FalseClass!
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
end # === describe Bool!
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
describe "True!" do
|
|
67
|
+
|
|
68
|
+
it 'returns original value' do
|
|
69
|
+
BOX.True!(true).should.be === true
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it 'raises Demand::Failed if not true' do
|
|
73
|
+
lambda { BOX.True!(false) }
|
|
74
|
+
.should.raise(Checked::Demand::Failed)
|
|
75
|
+
.message.should.match %r!FalseClass, false, must be true!
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
end # === describe True!
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
describe "False!" do
|
|
82
|
+
|
|
83
|
+
it 'returns original value' do
|
|
84
|
+
BOX.False!(false).should.be === false
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it 'raises Demand::Failed if not false' do
|
|
88
|
+
lambda { BOX.False!(true) }
|
|
89
|
+
.should.raise(Checked::Demand::Failed)
|
|
90
|
+
.message.should.match %r!TrueClass, true, must be false!
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
end # === describe False!
|
data/spec/tests/Demand.rb
CHANGED
|
@@ -107,7 +107,7 @@ describe "Demand file_path! not_file!" do
|
|
|
107
107
|
.message.should.match %r!bashrc", can't be a file!
|
|
108
108
|
end
|
|
109
109
|
|
|
110
|
-
it 'must return
|
|
110
|
+
it 'must return expanded path' do
|
|
111
111
|
path = "~/,RANDOM"
|
|
112
112
|
target = File.expand_path(path)
|
|
113
113
|
BOX.file_path!(path).not_file!.should.be == target
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: Checked
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -13,7 +13,7 @@ date: 2012-01-09 00:00:00.000000000Z
|
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: Uni_Arch
|
|
16
|
-
requirement: &
|
|
16
|
+
requirement: &19092720 !ruby/object:Gem::Requirement
|
|
17
17
|
none: false
|
|
18
18
|
requirements:
|
|
19
19
|
- - ! '>='
|
|
@@ -21,10 +21,10 @@ dependencies:
|
|
|
21
21
|
version: '0'
|
|
22
22
|
type: :runtime
|
|
23
23
|
prerelease: false
|
|
24
|
-
version_requirements: *
|
|
24
|
+
version_requirements: *19092720
|
|
25
25
|
- !ruby/object:Gem::Dependency
|
|
26
26
|
name: rake
|
|
27
|
-
requirement: &
|
|
27
|
+
requirement: &19091320 !ruby/object:Gem::Requirement
|
|
28
28
|
none: false
|
|
29
29
|
requirements:
|
|
30
30
|
- - ! '>='
|
|
@@ -32,10 +32,10 @@ dependencies:
|
|
|
32
32
|
version: '0'
|
|
33
33
|
type: :development
|
|
34
34
|
prerelease: false
|
|
35
|
-
version_requirements: *
|
|
35
|
+
version_requirements: *19091320
|
|
36
36
|
- !ruby/object:Gem::Dependency
|
|
37
37
|
name: bacon
|
|
38
|
-
requirement: &
|
|
38
|
+
requirement: &19089240 !ruby/object:Gem::Requirement
|
|
39
39
|
none: false
|
|
40
40
|
requirements:
|
|
41
41
|
- - ! '>='
|
|
@@ -43,10 +43,10 @@ dependencies:
|
|
|
43
43
|
version: '0'
|
|
44
44
|
type: :development
|
|
45
45
|
prerelease: false
|
|
46
|
-
version_requirements: *
|
|
46
|
+
version_requirements: *19089240
|
|
47
47
|
- !ruby/object:Gem::Dependency
|
|
48
48
|
name: Bacon_Colored
|
|
49
|
-
requirement: &
|
|
49
|
+
requirement: &19088080 !ruby/object:Gem::Requirement
|
|
50
50
|
none: false
|
|
51
51
|
requirements:
|
|
52
52
|
- - ! '>='
|
|
@@ -54,7 +54,7 @@ dependencies:
|
|
|
54
54
|
version: '0'
|
|
55
55
|
type: :development
|
|
56
56
|
prerelease: false
|
|
57
|
-
version_requirements: *
|
|
57
|
+
version_requirements: *19088080
|
|
58
58
|
description: ! "\n Various DSLs to clean, question (Ask), and validate (Demand)
|
|
59
59
|
your objects,\n their classes (data types), and their properties.\n "
|
|
60
60
|
email:
|