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 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'
@@ -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 self.included klass
7
- klass.send :include, Sin_Arch::Arch
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! args_hash['args']
65
+ def not_empty_args! *args
66
+ not_empty! args
48
67
  end
49
68
 
50
69
  def fail! raw_msg
@@ -1,31 +1,22 @@
1
1
 
2
2
 
3
3
  class Checked
4
- class Ask
5
- class Arrays < Sinatra::Base
4
+
5
+ class Arrays
6
6
 
7
- include Checked::Arch
7
+ def symbols?
8
+ return false if return!.empty?
9
+ return!.all? { |val| val.is_a? Symbol }
10
+ end
8
11
 
9
- map '/array!'
12
+ def include_all? *args
13
+ return!.include_all?(*args)
14
+ end
10
15
 
11
- get
12
- def symbols?
13
- return false if return!.empty?
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
- get
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
@@ -1,12 +1,6 @@
1
1
 
2
2
  class Checked
3
- class Ask
4
- class Strings < Sinatra::Base
3
+ class Strings
5
4
 
6
- include Checked::Arch
7
-
8
- map '/string!'
9
-
10
- end # === class Strings
11
- end # === class Ask
5
+ end # === class Strings
12
6
  end # === class Checked
@@ -1,30 +1,22 @@
1
1
 
2
2
  class Checked
3
- class Ask
4
- class Vars < Sinatra::Base
5
-
6
- include Checked::Arch
3
+ class Vars
7
4
 
8
- map '/var!'
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
- get
11
- def respond_to_all?
12
- a = not_empty_args!
13
+ def respond_to_any? *args
14
+ arr = not_empty!(args)
13
15
 
14
- a.all? { |a|
15
- return!.respond_to? a
16
- }
17
- end
16
+ arr.any? { |a|
17
+ return!.respond_to? a
18
+ }
19
+ end
18
20
 
19
- get
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 Clean
4
- class Strings < Sinatra::Base
5
-
6
- include Checked::Arch
7
-
8
- private
9
- def strippable_route?
10
- params['name'][%r![^\?\!]\Z!] && !%w{chop_slash_r}.include?(params['name'])
11
- end
12
-
13
- public
14
-
15
- map '/string!'
16
-
17
- before '/:name'
18
- def strip_val
19
- return!( return!.strip ) if strippable_route?
20
- end
21
-
22
- get
23
- def untar
24
- return!
25
- .sub(/\.tar\.gz$/, '')
26
- .sub(/\.tar/, '')
27
- end
28
-
29
- get
30
- def file_names
31
- ( return!.split.select { |word| word[matcher] } )
32
- end
33
-
34
- get
35
- def file_names_by_ext
36
- names = file_names
37
- bases = file_names.map { |s|
38
- s.sub(%r!#{matcher}$!, '')
39
- }
40
-
41
- names.zip bases
42
- end
43
-
44
- get
45
- def shell
46
- return!
47
- .split("\n")
48
- .map(&:strip)
49
- .reject { |line| line.empty? }
50
- .join(' && ')
51
- end
52
-
53
- get
54
- def chop_ext
55
- return!.sub /\.[^\.]+$/, ''
56
- end
57
-
58
- get
59
- def ruby_name
60
- File.basename chop_rb
61
- end
62
-
63
- get
64
- def chop_rb
65
- return!.sub %r!\.rb$!, ''
66
- end
67
-
68
- get
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
- @sin_arch ||= begin
5
- o = ::Checked::Obj.new
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
- (instance_variable_defined?(:@sin_arch) && Checked().on?)
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
- begin
26
- result = Checked().get!(meth_name, *args)
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.<< 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.downcase}!', *args ).check!
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<< v.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.on! ns
221
- val.Checked.name = name
222
- val.Checked.get! 'check!'
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 Demand
3
- class Arrays < Sinatra::Base
2
+ class Arrays
4
3
 
5
- include Checked::Arch
6
- map '/array!'
7
-
8
- get
9
- def check!
10
- array! return!
11
- end
4
+ def check!
5
+ array! return!
6
+ end
12
7
 
13
- get
14
- def no_nils!
15
- demand \
16
- return!.include?(nil), \
8
+ def no_nils!
9
+ demand \
10
+ return!.include?(nil), \
17
11
  "...can't contain nils."
18
- end
12
+ end
19
13
 
20
- get
21
- def no_empty_strings!
22
- return!.each { |memo,s|
14
+ def no_empty_strings!
15
+ return!.each { |memo,s|
23
16
 
24
- final = if s.respond_to?(:readlines)
25
- s.rewind
26
- s.readlines
27
- else
28
- s
29
- end
17
+ final = if s.respond_to?(:readlines)
18
+ s.rewind
19
+ s.readlines
20
+ else
21
+ s
22
+ end
30
23
 
31
- demand \
32
- final.is_a?(::String), \
24
+ demand \
25
+ final.is_a?(::String), \
33
26
  "...can't contain unknown class: #{final.inspect}"
34
-
35
- demand \
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
- end
34
+ end
42
35
 
43
- get
44
- def symbols!
45
- Checked::App.new.get!("/array!/not_empty!", 'name'=>target_name, 'value'=>return!, 'args'=>[])
46
- demand \
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
- end
41
+ end
50
42
 
51
- get
52
- def include!
53
- demand return!.include?(matcher), \
43
+ def include! matcher
44
+ demand return!.include?(matcher), \
54
45
  "...must contain: #{matcher.inspect}"
55
- end
46
+ end
56
47
 
57
- get
58
- def exclude!
59
- demand val.include?(matcher), "...can't contain #{matcher.inspect}"
60
- end
48
+ def exclude! matcher
49
+ demand val.include?(matcher), "...can't contain #{matcher.inspect}"
50
+ end
61
51
 
62
- get
63
- def matches_only!
64
- demand \
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
- end
68
-
56
+ end
57
+
69
58
 
70
- end # === class Arrays
71
- end # === class Demand
59
+ end # === class Arrays
72
60
  end # === class Checked
73
61
 
@@ -1,30 +1,22 @@
1
1
  class Checked
2
- class Demand
3
- class Bools < Sinatra::Base
4
-
5
- include Checked::Arch
6
- map '/bool!'
2
+ class Bools
7
3
 
8
- get
9
- def check!
10
- is_bool = [TrueClass, FalseClass].include?(return!.class)
11
- demand is_bool, "...must be either of TrueClass or FalseClass."
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
- end # === class Bools
27
- end # === class Demand
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
 
@@ -2,7 +2,7 @@
2
2
  class Checked
3
3
  class Demand
4
4
  Failed = Class.new(RuntimeError)
5
-
5
+
6
6
  def initialize *args
7
7
  raise "Demand not allowed to be used."
8
8
  end