Checked 0.1.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Checked.gemspec +2 -3
- data/lib/Checked.rb +21 -9
- data/lib/Checked/Ask/Arrays.rb +31 -0
- data/lib/Checked/Ask/Ask.rb +21 -0
- data/lib/Checked/Ask/Strings.rb +27 -0
- data/lib/Checked/Ask/Vars.rb +21 -0
- data/lib/Checked/Base/Arch.rb +20 -0
- data/lib/Checked/Base/Base.rb +110 -0
- data/lib/Checked/Base/DSL.rb +73 -0
- data/lib/Checked/Base/DSL_Obj.rb +35 -0
- data/lib/Checked/{Clean.rb → Clean/Clean.rb} +1 -4
- data/lib/Checked/Clean/Strings.rb +94 -0
- data/lib/Checked/Demand/Arrays.rb +78 -0
- data/lib/Checked/Demand/Bools.rb +28 -0
- data/lib/Checked/{Demand.rb → Demand/Demand.rb} +12 -11
- data/lib/Checked/Demand/File_Paths.rb +63 -0
- data/lib/Checked/Demand/Hashs.rb +29 -0
- data/lib/Checked/Demand/Strings.rb +66 -0
- data/lib/Checked/Demand/Symbols.rb +21 -0
- data/lib/Checked/Demand/Vars.rb +65 -0
- data/lib/Checked/version.rb +1 -1
- data/spec/main.rb +5 -1
- data/spec/tests/Ask.rb +126 -8
- data/spec/tests/Clean.rb +66 -8
- data/spec/tests/DSL.rb +31 -0
- data/spec/tests/Demand.rb +220 -29
- metadata +38 -32
- data/lib/Checked/Args.rb +0 -55
- data/lib/Checked/Ask.rb +0 -69
- data/lib/Checked/Ask/DSL.rb +0 -31
- data/lib/Checked/Ask/Mods/Arrays.rb +0 -25
- data/lib/Checked/Ask/Mods/Strings.rb +0 -26
- data/lib/Checked/Ask/Mods/Vars.rb +0 -12
- data/lib/Checked/Base.rb +0 -119
- data/lib/Checked/Clean/DSL.rb +0 -16
- data/lib/Checked/Clean/Mods/Strings.rb +0 -104
- data/lib/Checked/Demand/DSL.rb +0 -29
- data/lib/Checked/Demand/Mods/Arrays.rb +0 -72
- data/lib/Checked/Demand/Mods/Bools.rb +0 -37
- data/lib/Checked/Demand/Mods/File_Addresses.rb +0 -59
- data/lib/Checked/Demand/Mods/Strings.rb +0 -51
- data/lib/Checked/Demand/Mods/Symbols.rb +0 -20
- data/lib/Checked/Demand/Mods/Vars.rb +0 -91
- data/spec/tests/Ask_Strings.rb +0 -57
- data/spec/tests/Checked.rb +0 -43
- data/spec/tests/Clean_Strings.rb +0 -76
- data/spec/tests/Demand_Arrays.rb +0 -31
- data/spec/tests/Demand_File_Addresses.rb +0 -61
- data/spec/tests/Demand_Vars.rb +0 -19
data/lib/Checked/Demand/DSL.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
|
2
|
-
module Checked
|
3
|
-
class Demand
|
4
|
-
module DSL
|
5
|
-
|
6
|
-
def demand! target, *args
|
7
|
-
if block_given?
|
8
|
-
raise "No block allowed here."
|
9
|
-
end
|
10
|
-
|
11
|
-
Demand.new(target) { |d|
|
12
|
-
d.<< args
|
13
|
-
}.target
|
14
|
-
end
|
15
|
-
|
16
|
-
def named_demand! name, target, *args
|
17
|
-
if block_given?
|
18
|
-
raise "No block allowed here."
|
19
|
-
end
|
20
|
-
|
21
|
-
Demand.new(target) { |d|
|
22
|
-
d.* name
|
23
|
-
d.<< args
|
24
|
-
}.target
|
25
|
-
end
|
26
|
-
|
27
|
-
end # === module Dsl
|
28
|
-
end # === class Demand
|
29
|
-
end # === module Checked
|
@@ -1,72 +0,0 @@
|
|
1
|
-
|
2
|
-
module Checked
|
3
|
-
class Demand
|
4
|
-
module Mods
|
5
|
-
module Arrays
|
6
|
-
|
7
|
-
def self.before_apply d
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.apply? d
|
11
|
-
d.target.is_a?(Array)
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.after_apply d
|
15
|
-
end
|
16
|
-
|
17
|
-
def no_nils!
|
18
|
-
array!
|
19
|
-
if target.include?(nil)
|
20
|
-
fail!("...can't contain nils.")
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def no_empty_strings!
|
25
|
-
array!
|
26
|
-
target.each { |s|
|
27
|
-
|
28
|
-
if s.respond_to?(:rewind)
|
29
|
-
s.rewind
|
30
|
-
end
|
31
|
-
|
32
|
-
final = if s.respond_to?(:readlines)
|
33
|
-
s.readlines
|
34
|
-
else
|
35
|
-
s
|
36
|
-
end
|
37
|
-
|
38
|
-
if final.is_a?(String) && final.strip.empty?
|
39
|
-
fail!("...can't contain empty strings.")
|
40
|
-
end
|
41
|
-
}
|
42
|
-
end
|
43
|
-
|
44
|
-
def symbols!
|
45
|
-
array!
|
46
|
-
not_empty!
|
47
|
-
if !target.all? { |v| v.is_a?(Symbol) }
|
48
|
-
fail! "...contains a non-symbol."
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def include! matcher
|
53
|
-
included = target.include?(matcher)
|
54
|
-
return true if included
|
55
|
-
fail!("...must contain: #{matcher.inspect}")
|
56
|
-
end
|
57
|
-
|
58
|
-
def exclude! matcher
|
59
|
-
raise_e = val.include?(matcher)
|
60
|
-
return true unless raise_e
|
61
|
-
fail!("...can't contain #{matcher.inspect}")
|
62
|
-
end
|
63
|
-
|
64
|
-
def matches_only! matcher
|
65
|
-
arr = target.reject { |val| val == matcher }
|
66
|
-
fail!( "...invalid elements: #{arr.inspect}" ) if !arr.empty?
|
67
|
-
end
|
68
|
-
|
69
|
-
end # === module Arrays
|
70
|
-
end # === module Mods
|
71
|
-
end # === class Demand
|
72
|
-
end # === module Checked
|
@@ -1,37 +0,0 @@
|
|
1
|
-
|
2
|
-
module Checked
|
3
|
-
class Demand
|
4
|
-
module Mods
|
5
|
-
module Bools
|
6
|
-
|
7
|
-
def self.before_apply d
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.apply? d
|
11
|
-
target = d.target
|
12
|
-
target.is_a?( FalseClass ) ||
|
13
|
-
target.is_a?(TrueClass)
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.after_apply d
|
17
|
-
end
|
18
|
-
|
19
|
-
def be! meth, *args
|
20
|
-
answer = target.send meth, *args
|
21
|
-
demand answer, :bool!
|
22
|
-
return true if answer
|
23
|
-
fail!("...failed #{meth} with #{args.inspect}")
|
24
|
-
end
|
25
|
-
|
26
|
-
def not_be! meth, *args
|
27
|
-
bool!
|
28
|
-
pass = target.send(meth, *args)
|
29
|
-
demand pass, :bool!
|
30
|
-
return true unless pass
|
31
|
-
fail!("...#{meth} should not be true with #{args.inspect}")
|
32
|
-
end
|
33
|
-
|
34
|
-
end # === module Bools
|
35
|
-
end # === module Mods
|
36
|
-
end # === class Demand
|
37
|
-
end # === module Checked
|
@@ -1,59 +0,0 @@
|
|
1
|
-
|
2
|
-
module Checked
|
3
|
-
class Demand
|
4
|
-
module Mods
|
5
|
-
module File_Addresses
|
6
|
-
|
7
|
-
def self.apply? d
|
8
|
-
d.target.is_a?(String)
|
9
|
-
end
|
10
|
-
|
11
|
-
def hostname!
|
12
|
-
string!
|
13
|
-
not_empty!
|
14
|
-
matches_only! %r![\dA-Za-z_-]!
|
15
|
-
end
|
16
|
-
|
17
|
-
def not_dir!
|
18
|
-
string!
|
19
|
-
not_empty!
|
20
|
-
if File.directory?(target)
|
21
|
-
fail! "...can't be a directory."
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def not_file!
|
26
|
-
string!
|
27
|
-
not_empty!
|
28
|
-
if File.file?(target)
|
29
|
-
fail! "...can't be a file."
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def dir_address!
|
34
|
-
file_address!
|
35
|
-
end
|
36
|
-
|
37
|
-
def file_address!
|
38
|
-
self.target= target.strip
|
39
|
-
string!
|
40
|
-
not_empty!
|
41
|
-
if target[%r!([^a-zA-Z0-9\.\_\-\/~,]+)!]
|
42
|
-
fail! "...has invalid characters: #{$1.inspect}"
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def file_read!
|
47
|
-
self.target= target.gsub("\r\n", "\n")
|
48
|
-
end
|
49
|
-
|
50
|
-
def file_content!
|
51
|
-
string!
|
52
|
-
not_empty!
|
53
|
-
file_read!
|
54
|
-
end
|
55
|
-
|
56
|
-
end # === module File_Addresses
|
57
|
-
end # === module Mods
|
58
|
-
end # === class Demand
|
59
|
-
end # === module Checked
|
@@ -1,51 +0,0 @@
|
|
1
|
-
|
2
|
-
module Checked
|
3
|
-
class Demand
|
4
|
-
module Mods
|
5
|
-
module Strings
|
6
|
-
|
7
|
-
def self.before_apply d
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.apply? d
|
11
|
-
d.target.is_a?( String ) ||
|
12
|
-
d.target.is_a?(StringIO)
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.after_apply d
|
16
|
-
if d.target.is_a?(StringIO)
|
17
|
-
d.target.rewind
|
18
|
-
d.target= d.target.readlines
|
19
|
-
d.target.rewind
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def include! matcher
|
24
|
-
included = target[matcher]
|
25
|
-
return true if included
|
26
|
-
fail!("...must contain: #{matcher.inspect}")
|
27
|
-
end
|
28
|
-
|
29
|
-
def exclude! matcher
|
30
|
-
raise_e = val[matcher]
|
31
|
-
return true unless raise_e
|
32
|
-
fail!("...can't contain #{matcher.inspect}")
|
33
|
-
end
|
34
|
-
|
35
|
-
def matches_only! matcher
|
36
|
-
str = target.gsub(matcher, '')
|
37
|
-
if !str.empty?
|
38
|
-
fail!( "...has invalid characters: #{str.inspect}" )
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def not_empty!
|
43
|
-
if target.strip.empty?
|
44
|
-
fail!("...can't be empty.")
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
end # === module Strings
|
49
|
-
end # === module DSL
|
50
|
-
end # === class Demand
|
51
|
-
end # === module Checked
|
@@ -1,20 +0,0 @@
|
|
1
|
-
|
2
|
-
module Checked
|
3
|
-
class Demand
|
4
|
-
module Mods
|
5
|
-
module Symbols
|
6
|
-
|
7
|
-
def self.before_apply d
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.apply? d
|
11
|
-
d.target.is_a? Symbol
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.after_apply d
|
15
|
-
end
|
16
|
-
|
17
|
-
end # === module Symbols
|
18
|
-
end # === class DEMANDS
|
19
|
-
end # === class Demand
|
20
|
-
end # === module Checked
|
@@ -1,91 +0,0 @@
|
|
1
|
-
|
2
|
-
module Checked
|
3
|
-
class Demand
|
4
|
-
module Mods
|
5
|
-
module Vars
|
6
|
-
|
7
|
-
def array!
|
8
|
-
a! Array
|
9
|
-
end
|
10
|
-
|
11
|
-
def bool!
|
12
|
-
return true if [true, false].include?(target)
|
13
|
-
fail!("...has to be a boolean.")
|
14
|
-
end
|
15
|
-
|
16
|
-
def string!
|
17
|
-
a! String
|
18
|
-
end
|
19
|
-
|
20
|
-
def symbol!
|
21
|
-
a! Symbol
|
22
|
-
end
|
23
|
-
|
24
|
-
def no_block_given!
|
25
|
-
one_of! NilClass, FalseClass
|
26
|
-
if target
|
27
|
-
fail! "No block allowed."
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def no_block!
|
32
|
-
no_block_given!
|
33
|
-
end
|
34
|
-
|
35
|
-
def either! *meths
|
36
|
-
meths.flatten.detect { |m|
|
37
|
-
begin
|
38
|
-
send m
|
39
|
-
true
|
40
|
-
rescue Failed
|
41
|
-
false
|
42
|
-
end
|
43
|
-
}
|
44
|
-
end
|
45
|
-
|
46
|
-
def one_of! *klasses
|
47
|
-
return true if klasses.flatten.any? { |k| target.is_a?(k) }
|
48
|
-
fail! "...can only be of class/module: #{klasses.map(&:to_s).join(', ')}"
|
49
|
-
end
|
50
|
-
|
51
|
-
def a! klass
|
52
|
-
one_of! klass
|
53
|
-
end
|
54
|
-
|
55
|
-
def nil!
|
56
|
-
return true if target == nil
|
57
|
-
fail!("...must be nil.")
|
58
|
-
end
|
59
|
-
|
60
|
-
def not_nil!
|
61
|
-
fail!("...can't be nil.") if target.nil?
|
62
|
-
true
|
63
|
-
end
|
64
|
-
|
65
|
-
def respond_to! meth
|
66
|
-
return true if target.respond_to?(meth)
|
67
|
-
fail!("...must respond to #{meth.inspect}")
|
68
|
-
end
|
69
|
-
|
70
|
-
def not_empty!
|
71
|
-
respond_to! :empty?
|
72
|
-
is_empty = target.empty?
|
73
|
-
fail!("...can't be empty.") if is_empty
|
74
|
-
end
|
75
|
-
|
76
|
-
def exists!
|
77
|
-
respond_to! :exists?
|
78
|
-
return true if target.exists?
|
79
|
-
fail!("...must exist.")
|
80
|
-
end
|
81
|
-
|
82
|
-
def not_exists!
|
83
|
-
respond_to! :exists?
|
84
|
-
return true unless target.exists?
|
85
|
-
fail!("...must not exist.")
|
86
|
-
end
|
87
|
-
|
88
|
-
end # === module Var
|
89
|
-
end # === module Mods
|
90
|
-
end # === class Demand
|
91
|
-
end # === module Checked
|
data/spec/tests/Ask_Strings.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
|
2
|
-
shared 'Ask' do
|
3
|
-
before {
|
4
|
-
extend Checked::Ask::DSL
|
5
|
-
}
|
6
|
-
end
|
7
|
-
|
8
|
-
describe "ask empty?" do
|
9
|
-
|
10
|
-
behaves_like 'Ask'
|
11
|
-
|
12
|
-
it "returns true if string is :empty? after applying :strip" do
|
13
|
-
ask?(" \n ", :empty?).should.be === true
|
14
|
-
end
|
15
|
-
|
16
|
-
it "returns false if string is not :empty? after applying :strip" do
|
17
|
-
ask?(" n ", :empty?).should.be === false
|
18
|
-
end
|
19
|
-
|
20
|
-
|
21
|
-
end # === describe Ask Strings
|
22
|
-
|
23
|
-
describe "Ask :includes" do
|
24
|
-
|
25
|
-
behaves_like 'Ask'
|
26
|
-
|
27
|
-
it "returns true if string contains a Regexp matcher" do
|
28
|
-
Checked::Ask.new(" :a ") { |a|
|
29
|
-
a.< :includes?, / :a /
|
30
|
-
}.true?.should.be == true
|
31
|
-
end
|
32
|
-
|
33
|
-
it "returns false if string excludes a Regexp matcher" do
|
34
|
-
Checked::Ask.new(" :a ") { |a|
|
35
|
-
a.< :includes?, / :b /
|
36
|
-
}.true?.should.be == false
|
37
|
-
end
|
38
|
-
|
39
|
-
end # === describe Ask :includes
|
40
|
-
|
41
|
-
describe "Ask :excludes" do
|
42
|
-
|
43
|
-
behaves_like 'Ask'
|
44
|
-
|
45
|
-
it "returns true if string excludes a Regexp matcher" do
|
46
|
-
Checked::Ask.new(" :a ") { |a|
|
47
|
-
a.< :excludes?, / :b /
|
48
|
-
}.true?.should.be == true
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'returns false if string includes a Regexp matcher' do
|
52
|
-
Checked::Ask.new(" :a ") { |a|
|
53
|
-
a.< :excludes?, / :a /
|
54
|
-
}.true?.should.be == false
|
55
|
-
end
|
56
|
-
|
57
|
-
end # === describe Ask :excludes
|
data/spec/tests/Checked.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
|
2
|
-
describe "Checked::DSL" do
|
3
|
-
|
4
|
-
%w{ Ask Demand Clean }.each { |name|
|
5
|
-
klass = Checked.const_get(name)
|
6
|
-
|
7
|
-
it "includes #{name}::DSL" do
|
8
|
-
Checked::DSL.included_modules.should.include klass::DSL
|
9
|
-
end
|
10
|
-
|
11
|
-
}
|
12
|
-
|
13
|
-
end # === describe
|
14
|
-
|
15
|
-
|
16
|
-
describe "Checked.demand!" do
|
17
|
-
|
18
|
-
before {
|
19
|
-
@perf = Class.new { include Checked::DSL }.new
|
20
|
-
}
|
21
|
-
|
22
|
-
it 'must be equivalent to: Demand.new(target)' do
|
23
|
-
should.raise(Checked::Demand::Failed) {
|
24
|
-
@perf.demand! [], :not_empty!
|
25
|
-
}.message.should == "Array, [], can't be empty."
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
end # === describe Checked.demand!
|
30
|
-
|
31
|
-
describe "Checked.named_demand!" do
|
32
|
-
|
33
|
-
before {
|
34
|
-
@perf = Class.new { include Checked::DSL }.new
|
35
|
-
}
|
36
|
-
|
37
|
-
it 'must be equivalent to: Demand.new(target) { |d| d.* name; d << args}' do
|
38
|
-
should.raise(Checked::Demand::Failed) {
|
39
|
-
@perf.named_demand! "Test Val", [:a, 'c'], :symbols!
|
40
|
-
}.message.should == "Test Val, [:a, \"c\"], contains a non-symbol."
|
41
|
-
end
|
42
|
-
|
43
|
-
end # === describe Checked.named_demand!
|