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.
@@ -4,6 +4,7 @@ module Checked
4
4
  class Ask
5
5
  class Arrays
6
6
 
7
+ include Uni_Arch::Base
7
8
  include Ask::Base
8
9
 
9
10
  namespace '/array!'
@@ -1,27 +1,28 @@
1
1
 
2
2
  module Checked
3
3
  class Ask
4
- class Strings
4
+ class Strings
5
5
 
6
- include Ask::Base
7
-
8
- namespace '/string!'
6
+ include Uni_Arch::Base
7
+ include Ask::Base
9
8
 
10
- route
11
- def empty?
12
- target.strip.empty?
13
- end
9
+ namespace '/string!'
14
10
 
15
- route
16
- def include?
17
- !!target[*args]
18
- end
11
+ route
12
+ def empty?
13
+ target.strip.empty?
14
+ end
19
15
 
20
- route
21
- def exclude?
22
- !target[*args]
23
- end
16
+ route
17
+ def include?
18
+ !!target[*args]
19
+ end
24
20
 
25
- end # === class Strings
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
@@ -3,6 +3,7 @@ module Checked
3
3
  class Ask
4
4
  class Vars
5
5
 
6
+ include Uni_Arch::Base
6
7
  include Ask::Base
7
8
 
8
9
  namespace '/var!'
@@ -1,13 +1,26 @@
1
1
 
2
2
  module Checked
3
3
  class Arch
4
- include ::Checked::Base
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@]
@@ -2,8 +2,6 @@ module Checked
2
2
 
3
3
  module Base
4
4
 
5
- include Uni_Arch::Base
6
-
7
5
  CHECK = begin
8
6
  o = Object.new
9
7
  o.extend Checked::DSL
@@ -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
@@ -3,6 +3,7 @@ module Checked
3
3
  class Clean
4
4
  class Strings
5
5
 
6
+ include Uni_Arch::Base
6
7
  include Clean::Base
7
8
 
8
9
  namespace '/string!'
@@ -2,12 +2,12 @@ module Checked
2
2
  class Demand
3
3
  class Arrays
4
4
 
5
+ include Uni_Arch::Base
5
6
  include Demand::Base
6
-
7
7
  namespace '/array!'
8
8
 
9
- before
10
- def validate_target_class
9
+ route
10
+ def check!
11
11
  fail! "...is not an Array." unless array?(target)
12
12
  end
13
13
 
@@ -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
- before
10
- def validate
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
- before
10
- def validate
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
- matches_only! %r![\dA-Za-z_-]!
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
@@ -2,12 +2,12 @@ module Checked
2
2
  class Demand
3
3
  class Hashs
4
4
 
5
+ include Uni_Arch::Base
5
6
  include Demand::Base
6
-
7
7
  namespace '/hash!'
8
8
 
9
- before
10
- def validate_target_class
9
+ route
10
+ def check!
11
11
  fail!("...must be a Hash") unless hash?(target)
12
12
  end
13
13
 
@@ -3,12 +3,12 @@ module Checked
3
3
  class Demand
4
4
  class Strings
5
5
 
6
+ include Uni_Arch::Base
6
7
  include Demand::Base
7
-
8
8
  namespace '/string!'
9
9
 
10
- before
11
- def validate
10
+ route
11
+ def check!
12
12
  case target
13
13
  when String
14
14
  when StringIO
@@ -3,12 +3,12 @@ module Checked
3
3
  class Demand
4
4
  class Symbols
5
5
 
6
+ include Uni_Arch::Base
6
7
  include Demand::Base
7
-
8
8
  namespace '/symbol!'
9
9
 
10
- before
11
- def validate
10
+ route
11
+ def check!
12
12
  case target
13
13
  when Symbol
14
14
  else
@@ -2,8 +2,8 @@ module Checked
2
2
  class Demand
3
3
  class Vars
4
4
 
5
+ include Uni_Arch::Base
5
6
  include Demand::Base
6
-
7
7
  namespace '/var!'
8
8
 
9
9
  route
@@ -1,3 +1,3 @@
1
1
  module Checked
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
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 'raise Demand::Failed if not a string' do
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 'raise Demand::Failed if not an Array' do
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 expand path' do
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.0.0
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: &12169680 !ruby/object:Gem::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: *12169680
24
+ version_requirements: *19092720
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &12168560 !ruby/object:Gem::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: *12168560
35
+ version_requirements: *19091320
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bacon
38
- requirement: &12167360 !ruby/object:Gem::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: *12167360
46
+ version_requirements: *19089240
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: Bacon_Colored
49
- requirement: &12166240 !ruby/object:Gem::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: *12166240
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: