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/Args.rb
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
|
2
|
-
module Checked
|
3
|
-
|
4
|
-
class Args
|
5
|
-
|
6
|
-
Unknown_Class = Class.new(RuntimeError)
|
7
|
-
|
8
|
-
module Base
|
9
|
-
|
10
|
-
def initialize *arr
|
11
|
-
arr.flatten.each { |var|
|
12
|
-
case var
|
13
|
-
when Array
|
14
|
-
var.each { |k|
|
15
|
-
define k
|
16
|
-
}
|
17
|
-
when Hash
|
18
|
-
var.each { |k,v|
|
19
|
-
define k
|
20
|
-
send("#{k}=", v)
|
21
|
-
}
|
22
|
-
else
|
23
|
-
raise Unknown_Class, var.inspect
|
24
|
-
end
|
25
|
-
}
|
26
|
-
end
|
27
|
-
|
28
|
-
def define *raw
|
29
|
-
raw.flatten.each { |k|
|
30
|
-
eval %~
|
31
|
-
|
32
|
-
def #{k}
|
33
|
-
@#{k}
|
34
|
-
end
|
35
|
-
|
36
|
-
def #{k}= v
|
37
|
-
@#{k} = v
|
38
|
-
end
|
39
|
-
|
40
|
-
~
|
41
|
-
}
|
42
|
-
end
|
43
|
-
|
44
|
-
def defined? key
|
45
|
-
respond_to?( key ) &&
|
46
|
-
respond_to?( :"#{key}=" )
|
47
|
-
end
|
48
|
-
|
49
|
-
end # === module Base
|
50
|
-
|
51
|
-
include Base
|
52
|
-
|
53
|
-
end # === module Args
|
54
|
-
|
55
|
-
end # === module Checked
|
data/lib/Checked/Ask.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
require 'Checked/Base'
|
2
|
-
require 'Checked/Ask/DSL'
|
3
|
-
|
4
|
-
module Checked
|
5
|
-
class Ask
|
6
|
-
module Base
|
7
|
-
|
8
|
-
private # ==============================
|
9
|
-
|
10
|
-
include ::Checked::Base
|
11
|
-
|
12
|
-
#
|
13
|
-
# Demand::DSL is not used here
|
14
|
-
# because it uses the Questioner.
|
15
|
-
# It would cause an stack level/infinite loop
|
16
|
-
# error.
|
17
|
-
#
|
18
|
-
def valid! target, *args
|
19
|
-
v = Demand.new(target)
|
20
|
-
if args.empty?
|
21
|
-
yield v
|
22
|
-
else
|
23
|
-
raise "No block allowed with arguments: #{args.inspect}" if block_given?
|
24
|
-
v << args
|
25
|
-
end
|
26
|
-
|
27
|
-
v.target
|
28
|
-
end
|
29
|
-
|
30
|
-
public # ==============================
|
31
|
-
|
32
|
-
attr_reader :records
|
33
|
-
|
34
|
-
def before_init
|
35
|
-
@records = []
|
36
|
-
end
|
37
|
-
|
38
|
-
def < name, *args, &blok
|
39
|
-
a = super
|
40
|
-
valid!(a, :bool!)
|
41
|
-
records << a
|
42
|
-
a
|
43
|
-
end
|
44
|
-
|
45
|
-
def << *methods
|
46
|
-
valid! block_given?, :no_block!
|
47
|
-
super(*methods) { |name|
|
48
|
-
self.< name
|
49
|
-
}
|
50
|
-
end
|
51
|
-
|
52
|
-
def true?
|
53
|
-
return false if records.empty?
|
54
|
-
records.all?
|
55
|
-
end
|
56
|
-
|
57
|
-
def any?
|
58
|
-
return false if records.empty?
|
59
|
-
records.any?
|
60
|
-
end
|
61
|
-
|
62
|
-
private # ==============================
|
63
|
-
|
64
|
-
|
65
|
-
end # === module Base
|
66
|
-
|
67
|
-
include Base
|
68
|
-
end # === class Ask
|
69
|
-
end # === module Checked
|
data/lib/Checked/Ask/DSL.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'Checked/Demand/DSL'
|
2
|
-
|
3
|
-
module Checked
|
4
|
-
class Ask
|
5
|
-
module DSL
|
6
|
-
|
7
|
-
include Demand::DSL
|
8
|
-
|
9
|
-
def ask? target, *args
|
10
|
-
Checked::Ask.new(target) { |a|
|
11
|
-
a.<< args
|
12
|
-
}.true?
|
13
|
-
end
|
14
|
-
|
15
|
-
def true? target, *args
|
16
|
-
demand! block_given?, :no_block!
|
17
|
-
q = Ask.new(target)
|
18
|
-
q << args
|
19
|
-
q.true?
|
20
|
-
end
|
21
|
-
|
22
|
-
def any? target, *args
|
23
|
-
demand! block_given?, :no_block!
|
24
|
-
q = Ask.new(target)
|
25
|
-
q << args
|
26
|
-
q.any?
|
27
|
-
end
|
28
|
-
|
29
|
-
end # === module DSL
|
30
|
-
end # === class Ask
|
31
|
-
end # === module Checked
|
@@ -1,25 +0,0 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module Checked
|
4
|
-
class Ask
|
5
|
-
module Mods
|
6
|
-
module Arrays
|
7
|
-
|
8
|
-
def self.apply?(d)
|
9
|
-
d.target.is_a?(Array)
|
10
|
-
end
|
11
|
-
|
12
|
-
def symbols?
|
13
|
-
valid! target, :array!
|
14
|
-
return false if target.empty?
|
15
|
-
target.all? { |val| val.is_a? Symbol }
|
16
|
-
end
|
17
|
-
|
18
|
-
def excludes? matcher
|
19
|
-
!target.includes?(matcher)
|
20
|
-
end
|
21
|
-
|
22
|
-
end # === module Arrays
|
23
|
-
end # === module Mods
|
24
|
-
end # === class Ask
|
25
|
-
end # === class Checked
|
@@ -1,26 +0,0 @@
|
|
1
|
-
|
2
|
-
module Checked
|
3
|
-
class Ask
|
4
|
-
module Mods
|
5
|
-
module Strings
|
6
|
-
|
7
|
-
def self.apply? d
|
8
|
-
d.target.is_a?(String)
|
9
|
-
end
|
10
|
-
|
11
|
-
def empty?
|
12
|
-
target.strip.empty?
|
13
|
-
end
|
14
|
-
|
15
|
-
def includes? matcher
|
16
|
-
!!target[matcher]
|
17
|
-
end
|
18
|
-
|
19
|
-
def excludes? matcher
|
20
|
-
!includes?(matcher)
|
21
|
-
end
|
22
|
-
|
23
|
-
end # === module Strings
|
24
|
-
end # === module Mods
|
25
|
-
end # === class Ask
|
26
|
-
end # === module Checked
|
data/lib/Checked/Base.rb
DELETED
@@ -1,119 +0,0 @@
|
|
1
|
-
|
2
|
-
module Checked
|
3
|
-
module Base
|
4
|
-
|
5
|
-
def self.included var
|
6
|
-
klass_name = var.to_s.gsub(/::Base$/, '').split('::').last
|
7
|
-
klass = Checked.const_get(klass_name)
|
8
|
-
|
9
|
-
files = Dir.glob(File.join File.dirname(__FILE__), "#{klass_name}/Mods/*.rb")
|
10
|
-
raise "No Mods found for #{klass}" if files.empty?
|
11
|
-
|
12
|
-
files.each { |path|
|
13
|
-
name = File.basename(path).sub('.rb', '')
|
14
|
-
require "Checked/#{klass_name}/Mods/#{name}"
|
15
|
-
if name == 'Vars'
|
16
|
-
klass.class_eval {
|
17
|
-
include klass::Mods::Vars
|
18
|
-
}
|
19
|
-
else
|
20
|
-
klass.const_set(:Mod_List, []) unless klass.const_defined?(:Mod_List)
|
21
|
-
klass::Mod_List << klass::Mods.const_get(name)
|
22
|
-
end
|
23
|
-
}
|
24
|
-
end
|
25
|
-
|
26
|
-
attr_accessor :target
|
27
|
-
attr_reader :target_name
|
28
|
-
|
29
|
-
def initialize target, &blok
|
30
|
-
|
31
|
-
if respond_to? :before_init
|
32
|
-
if method(:before_init).parameters === []
|
33
|
-
before_init
|
34
|
-
else
|
35
|
-
before_init target, &blok
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
@target = target
|
40
|
-
@target_name = target.respond_to?(:english_name) ?
|
41
|
-
target.english_name :
|
42
|
-
"#{target.class.name.gsub('_', ' ')}, #{target.inspect},"
|
43
|
-
|
44
|
-
self.class.const_get(:Mod_List).each { |mod|
|
45
|
-
if mod.apply?(self)
|
46
|
-
extend mod
|
47
|
-
end
|
48
|
-
}
|
49
|
-
|
50
|
-
if respond_to? :after_init
|
51
|
-
if method(:after_init).parameters === []
|
52
|
-
after_init
|
53
|
-
else
|
54
|
-
after_init target, &blok
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
yield(self) if block_given?
|
59
|
-
end
|
60
|
-
|
61
|
-
#
|
62
|
-
# Sets the name.
|
63
|
-
#
|
64
|
-
def * name
|
65
|
-
@target_name = "#{name}, #{target.inspect},"
|
66
|
-
self
|
67
|
-
end
|
68
|
-
|
69
|
-
#
|
70
|
-
# ::Checked::Demand => demand
|
71
|
-
# ::Checked::Clean => clean
|
72
|
-
# ::Checked::Ask => ask
|
73
|
-
#
|
74
|
-
def purpose
|
75
|
-
@purpose ||= self.class.name.split('::').last.downcase.sub(/er$/, '')
|
76
|
-
end
|
77
|
-
|
78
|
-
def < name, *args, &blok
|
79
|
-
send(name, *args, &blok)
|
80
|
-
end
|
81
|
-
|
82
|
-
def << *methods
|
83
|
-
meths = begin
|
84
|
-
::Checked::Demand.new(methods.flatten) { |d|
|
85
|
-
d.* "(Originally: #{target_name})"
|
86
|
-
d.instance_eval { not_empty!; symbols! }
|
87
|
-
}.target
|
88
|
-
end
|
89
|
-
|
90
|
-
|
91
|
-
meths.each { |name|
|
92
|
-
|
93
|
-
begin
|
94
|
-
if block_given?
|
95
|
-
yield name
|
96
|
-
else
|
97
|
-
send name
|
98
|
-
end
|
99
|
-
rescue NoMethodError => e
|
100
|
-
raise e if !e.message[/undefined method `#{name.to_s}' for/]
|
101
|
-
to_name = lambda { |m| m.to_s.split('::').last }
|
102
|
-
mods = self.class::Mod_List.select { |m| m.instance_methods.include?(name.to_sym) }
|
103
|
-
all = self.class::Mod_List
|
104
|
-
|
105
|
-
if mods.empty?
|
106
|
-
e_msg = e.message
|
107
|
-
raise NoMethodError, "#{e_msg} using mods: #{all.map(&to_name).join(', ')}"
|
108
|
-
else
|
109
|
-
raise NoMethodError, err_msg(
|
110
|
-
"...can not #{purpose} #{name}, which is found in: #{mods.map(&to_name).join(', ')}"
|
111
|
-
)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
}
|
115
|
-
self
|
116
|
-
end
|
117
|
-
|
118
|
-
end # === module Base
|
119
|
-
end # === module Checked
|
data/lib/Checked/Clean/DSL.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
|
2
|
-
module Checked
|
3
|
-
class Clean
|
4
|
-
module DSL
|
5
|
-
|
6
|
-
def clean target, *args
|
7
|
-
raise "No block allowed here." if block_given?
|
8
|
-
|
9
|
-
c = Clean.new(target)
|
10
|
-
c.<(*args)
|
11
|
-
c.target
|
12
|
-
end
|
13
|
-
|
14
|
-
end # === module DSL
|
15
|
-
end # === class Clean
|
16
|
-
end # === module Checked
|
@@ -1,104 +0,0 @@
|
|
1
|
-
|
2
|
-
module Checked
|
3
|
-
class Clean
|
4
|
-
module Mods
|
5
|
-
module Strings
|
6
|
-
|
7
|
-
def self.apply? d
|
8
|
-
d.target.is_a?(String) ||
|
9
|
-
d.target.is_a?(StringIO)
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.on_apply d
|
13
|
-
case d.target
|
14
|
-
when StringIO
|
15
|
-
d.target.rewind
|
16
|
-
d.target= d.target.readlines
|
17
|
-
else
|
18
|
-
# Do nothing.
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def untar
|
23
|
-
target
|
24
|
-
.sub(/\.tar\.gz$/, '')
|
25
|
-
.sub(/\.tar/, '')
|
26
|
-
end
|
27
|
-
|
28
|
-
def file_names matcher
|
29
|
-
target.strip.split.select { |word| word[matcher] }
|
30
|
-
end
|
31
|
-
|
32
|
-
def file_names_by_ext ext
|
33
|
-
names = file_names(ext)
|
34
|
-
bases = names.map { |s|
|
35
|
-
s.sub(%r!#{ext}$!, '')
|
36
|
-
}
|
37
|
-
|
38
|
-
names.zip bases
|
39
|
-
end
|
40
|
-
|
41
|
-
def shell
|
42
|
-
target
|
43
|
-
.strip
|
44
|
-
.split("\n")
|
45
|
-
.map(&:strip)
|
46
|
-
.reject { |line| line.empty? }
|
47
|
-
.join(' && ')
|
48
|
-
end
|
49
|
-
|
50
|
-
def chop_ext
|
51
|
-
target.sub /\.[^\.]+$/, ''
|
52
|
-
end
|
53
|
-
|
54
|
-
def ruby_name
|
55
|
-
c = ::Checked::Clean.new( File.basename( target ) )
|
56
|
-
c.< :chop_rb
|
57
|
-
c.target
|
58
|
-
end
|
59
|
-
|
60
|
-
def chop_rb
|
61
|
-
target.sub %r!\.rb$!, ''
|
62
|
-
end
|
63
|
-
|
64
|
-
def chop_slash_r
|
65
|
-
target.gsub "\r", ''
|
66
|
-
end
|
67
|
-
|
68
|
-
def os_stardard
|
69
|
-
chop_slash_r.strip
|
70
|
-
end
|
71
|
-
|
72
|
-
def file_names matcher
|
73
|
-
strip.split.select { |word| word[matcher] }
|
74
|
-
end
|
75
|
-
|
76
|
-
def file_names_by_ext ext
|
77
|
-
names = file_names(ext)
|
78
|
-
bases = names.map { |s|
|
79
|
-
s.sub(%r!#{ext}$!, '')
|
80
|
-
}
|
81
|
-
|
82
|
-
names.zip bases
|
83
|
-
end
|
84
|
-
|
85
|
-
def to_single
|
86
|
-
target.gsub( /s\Z/, '' )
|
87
|
-
end
|
88
|
-
|
89
|
-
def to_plural
|
90
|
-
target.to_single + 's'
|
91
|
-
end
|
92
|
-
|
93
|
-
def to_class_name
|
94
|
-
target.split('_').map(&:capitalize).join('_')
|
95
|
-
end
|
96
|
-
|
97
|
-
def to_camel_case
|
98
|
-
target.split('_').map(&:capitalize).join
|
99
|
-
end
|
100
|
-
|
101
|
-
end # === module Strings
|
102
|
-
end # === module Mods
|
103
|
-
end # === class Clean
|
104
|
-
end # === module Checked
|