dao 5.5.0 → 8.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +6 -14
- data/README.md +258 -0
- data/Rakefile +4 -5
- data/coerce-0.0.8/README +28 -0
- data/coerce-0.0.8/Rakefile +392 -0
- data/coerce-0.0.8/coerce.gemspec +31 -0
- data/coerce-0.0.8/lib/coerce.rb +210 -0
- data/dao.gemspec +38 -25
- data/lib/dao.rb +18 -81
- data/lib/dao/_lib.rb +42 -0
- data/lib/dao/active_record.rb +8 -8
- data/lib/dao/api/call.rb +19 -4
- data/lib/dao/api/dsl.rb +1 -1
- data/lib/dao/coerce.rb +211 -0
- data/lib/dao/conducer.rb +10 -14
- data/lib/dao/conducer/controller_support.rb +5 -0
- data/lib/dao/conducer/view_support.rb +0 -2
- data/lib/dao/db.rb +0 -1
- data/lib/dao/errors.rb +17 -11
- data/lib/dao/errors2html.rb +128 -0
- data/lib/dao/form.rb +13 -16
- data/lib/dao/messages.rb +0 -4
- data/lib/dao/path.rb +1 -1
- data/lib/dao/route.rb +2 -2
- data/lib/dao/status.rb +3 -4
- data/lib/dao/support.rb +26 -19
- data/lib/dao/upload.rb +0 -1
- data/lib/dao/validations/common.rb +6 -6
- data/lib/dao/validations/validator.rb +3 -3
- data/lib/dao/wrap.rb +259 -0
- data/tasks/default.rake +207 -0
- data/tasks/this.rb +207 -0
- data/test/active_model_conducer_lint_test.rb +3 -11
- data/test/api_test.rb +24 -35
- data/test/conducer_test.rb +37 -47
- data/test/errors_test.rb +29 -13
- data/test/form_test.rb +24 -34
- data/test/rake_rerun_reporter.rb +74 -0
- data/test/support_test.rb +9 -14
- data/test/test_helper.rb +220 -0
- data/test/{helper.rb → util.rb} +0 -0
- data/test/validations_test.rb +14 -28
- data/wrap-1.5.2/README +57 -0
- data/wrap-1.5.2/Rakefile +394 -0
- data/wrap-1.5.2/lib/wrap.rb +295 -0
- data/{test → wrap-1.5.2/test}/testing.rb +0 -1
- data/wrap-1.5.2/test/wrap_test.rb +397 -0
- data/wrap-1.5.2/wrap.gemspec +38 -0
- metadata +47 -103
- data/Gemfile +0 -16
- data/Gemfile.lock +0 -118
- data/README +0 -256
@@ -0,0 +1,31 @@
|
|
1
|
+
## coerce.gemspec
|
2
|
+
#
|
3
|
+
|
4
|
+
Gem::Specification::new do |spec|
|
5
|
+
spec.name = "coerce"
|
6
|
+
spec.version = "0.0.8"
|
7
|
+
spec.platform = Gem::Platform::RUBY
|
8
|
+
spec.summary = "coerce"
|
9
|
+
spec.description = "description: coerce kicks the ass"
|
10
|
+
spec.license = "same as ruby's"
|
11
|
+
|
12
|
+
spec.files =
|
13
|
+
["README", "Rakefile", "coerce.gemspec", "lib", "lib/coerce.rb"]
|
14
|
+
|
15
|
+
spec.executables = []
|
16
|
+
|
17
|
+
spec.require_path = "lib"
|
18
|
+
|
19
|
+
spec.test_files = nil
|
20
|
+
|
21
|
+
|
22
|
+
spec.add_dependency(*["chronic", ">= 0.6.2"])
|
23
|
+
|
24
|
+
|
25
|
+
spec.extensions.push(*[])
|
26
|
+
|
27
|
+
spec.rubyforge_project = "codeforpeople"
|
28
|
+
spec.author = "Ara T. Howard"
|
29
|
+
spec.email = "ara.t.howard@gmail.com"
|
30
|
+
spec.homepage = "https://github.com/ahoward/coerce"
|
31
|
+
end
|
@@ -0,0 +1,210 @@
|
|
1
|
+
module Coerce
|
2
|
+
## built-in
|
3
|
+
#
|
4
|
+
require 'uri'
|
5
|
+
require 'time'
|
6
|
+
require 'date'
|
7
|
+
require 'pathname'
|
8
|
+
require 'chronic'
|
9
|
+
|
10
|
+
## version
|
11
|
+
#
|
12
|
+
Coerce::Version = '0.0.8'
|
13
|
+
|
14
|
+
def self.version
|
15
|
+
Coerce::Version
|
16
|
+
end
|
17
|
+
|
18
|
+
## dependencies
|
19
|
+
#
|
20
|
+
def self.dependencies
|
21
|
+
{
|
22
|
+
'chronic' => [ 'chronic' , '>= 0.6.2' ]
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
begin
|
27
|
+
require 'rubygems'
|
28
|
+
rescue LoadError
|
29
|
+
nil
|
30
|
+
end
|
31
|
+
|
32
|
+
if defined?(gem)
|
33
|
+
self.dependencies.each do |lib, dependency|
|
34
|
+
gem(*dependency)
|
35
|
+
require(lib)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
##
|
40
|
+
#
|
41
|
+
def self.export m
|
42
|
+
module_function m
|
43
|
+
public m
|
44
|
+
end
|
45
|
+
|
46
|
+
List = []
|
47
|
+
|
48
|
+
def self.coerce m, &b
|
49
|
+
define_method m, &b
|
50
|
+
export m
|
51
|
+
List << m.to_s
|
52
|
+
end
|
53
|
+
|
54
|
+
coerce :boolean do |obj|
|
55
|
+
case obj.to_s
|
56
|
+
when %r/^(true|t|1|yes|y|on)$/i
|
57
|
+
true
|
58
|
+
when %r/^(false|f|0|no|n|off)$/i
|
59
|
+
false
|
60
|
+
else
|
61
|
+
!!obj
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
coerce :integer do |obj|
|
66
|
+
Float(obj).to_i
|
67
|
+
end
|
68
|
+
|
69
|
+
coerce :float do |obj|
|
70
|
+
Float obj
|
71
|
+
end
|
72
|
+
|
73
|
+
coerce :number do |obj|
|
74
|
+
Float obj rescue Integer obj
|
75
|
+
end
|
76
|
+
|
77
|
+
coerce :string do |obj|
|
78
|
+
String obj
|
79
|
+
end
|
80
|
+
|
81
|
+
coerce :symbol do |obj|
|
82
|
+
String(obj).to_sym
|
83
|
+
end
|
84
|
+
|
85
|
+
coerce :uri do |obj|
|
86
|
+
::URI.parse obj.to_s
|
87
|
+
end
|
88
|
+
|
89
|
+
coerce :url do |obj|
|
90
|
+
::URI.parse(obj.to_s).to_s
|
91
|
+
end
|
92
|
+
|
93
|
+
coerce :time do |obj|
|
94
|
+
::Chronic.parse(obj.to_s)
|
95
|
+
end
|
96
|
+
|
97
|
+
coerce :date do |obj|
|
98
|
+
begin
|
99
|
+
::Date.parse(::Chronic.parse(obj.to_s).to_s)
|
100
|
+
rescue
|
101
|
+
::Date.parse(obj.to_s)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
coerce :pathname do |obj|
|
106
|
+
Pathname.new(obj.to_s)
|
107
|
+
end
|
108
|
+
|
109
|
+
coerce :path do |obj|
|
110
|
+
File.expand_path(obj.to_s)
|
111
|
+
end
|
112
|
+
|
113
|
+
coerce :input do |obj|
|
114
|
+
case obj.to_s
|
115
|
+
when '-'
|
116
|
+
io = STDIN.dup
|
117
|
+
io.fattr(:path){ '/dev/stdin' }
|
118
|
+
io
|
119
|
+
else
|
120
|
+
io = open(obj.to_s, 'r+')
|
121
|
+
at_exit{ io.close }
|
122
|
+
io
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
coerce :output do |obj|
|
127
|
+
case obj.to_s
|
128
|
+
when '-'
|
129
|
+
io = STDOUT.dup
|
130
|
+
io.fattr(:path){ '/dev/stdout' }
|
131
|
+
io
|
132
|
+
else
|
133
|
+
io = open(obj.to_s, 'w+')
|
134
|
+
at_exit{ io.close }
|
135
|
+
io
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
coerce :slug do |obj|
|
140
|
+
string = [obj].flatten.compact.join('-')
|
141
|
+
words = string.to_s.scan(%r/\w+/)
|
142
|
+
words.map!{|word| word.gsub %r/[^0-9a-zA-Z_-]/, ''}
|
143
|
+
words.delete_if{|word| word.nil? or word.strip.empty?}
|
144
|
+
String(words.join('-').downcase)
|
145
|
+
end
|
146
|
+
|
147
|
+
coerce :list do |*objs|
|
148
|
+
[*objs].flatten.join(',').split(/[\n,]/).map{|item| item.strip}.delete_if{|item| item.strip.empty?}
|
149
|
+
end
|
150
|
+
|
151
|
+
coerce :array do |*objs|
|
152
|
+
[*objs].flatten.join(',').split(/[\n,]/).map{|item| item.strip}.delete_if{|item| item.strip.empty?}
|
153
|
+
end
|
154
|
+
|
155
|
+
coerce :hash do |*objs|
|
156
|
+
list = Coerce.list(*objs)
|
157
|
+
hash = Hash.new
|
158
|
+
list.each do |pair|
|
159
|
+
k, v = pair.split(/[=:]+/, 2)
|
160
|
+
key = k.to_s.strip
|
161
|
+
val = v.to_s.strip
|
162
|
+
hash[key] = val
|
163
|
+
end
|
164
|
+
hash
|
165
|
+
end
|
166
|
+
|
167
|
+
# add list_of_xxx methods
|
168
|
+
#
|
169
|
+
List.dup.each do |type|
|
170
|
+
next if type.to_s =~ %r/list/
|
171
|
+
%W" list_of_#{ type } list_of_#{ type }s ".each do |m|
|
172
|
+
define_method m do |*objs|
|
173
|
+
list(*objs).map{|obj| send type, obj}
|
174
|
+
end
|
175
|
+
export m
|
176
|
+
List << m
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
# add list_of_xxx_from_file
|
181
|
+
#
|
182
|
+
List.dup.each do |type|
|
183
|
+
next if type.to_s =~ %r/list/
|
184
|
+
%W" list_of_#{ type }_from_file list_of_#{ type }s_from_file ".each do |m|
|
185
|
+
define_method m do |*args|
|
186
|
+
buf = nil
|
187
|
+
if args.size == 1 and args.first.respond_to?(:read)
|
188
|
+
buf = args.first.read
|
189
|
+
else
|
190
|
+
open(*args){|io| buf = io.read}
|
191
|
+
end
|
192
|
+
send(m.sub(/_from_file/, ''), buf)
|
193
|
+
end
|
194
|
+
export m
|
195
|
+
List << m
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
def self.[] sym
|
200
|
+
prefix = sym.to_s.downcase.to_sym
|
201
|
+
candidates = List.select{|m| m =~ %r/^#{ prefix }/i}
|
202
|
+
m = candidates.shift
|
203
|
+
raise ArgumentError, "unsupported coercion: #{ sym.inspect } (#{ List.join ',' })" unless
|
204
|
+
m
|
205
|
+
raise ArgumentError, "ambiguous coercion: #{ sym.inspect } (#{ List.join ',' })" unless
|
206
|
+
candidates.empty? or m.to_s == sym.to_s
|
207
|
+
this = self
|
208
|
+
lambda{|obj| method(m).call obj}
|
209
|
+
end
|
210
|
+
end
|
data/dao.gemspec
CHANGED
@@ -3,21 +3,26 @@
|
|
3
3
|
|
4
4
|
Gem::Specification::new do |spec|
|
5
5
|
spec.name = "dao"
|
6
|
-
spec.version = "
|
6
|
+
spec.version = "8.0.0"
|
7
7
|
spec.platform = Gem::Platform::RUBY
|
8
8
|
spec.summary = "dao"
|
9
|
-
spec.description = "presenter,
|
10
|
-
spec.license = "
|
9
|
+
spec.description = "presenter, conductor, api, and better form objects for you rails' pleasure"
|
10
|
+
spec.license = "Ruby"
|
11
11
|
|
12
12
|
spec.files =
|
13
|
-
["
|
14
|
-
"Gemfile.lock",
|
15
|
-
"README",
|
13
|
+
["README.md",
|
16
14
|
"Rakefile",
|
15
|
+
"coerce-0.0.8",
|
16
|
+
"coerce-0.0.8/README",
|
17
|
+
"coerce-0.0.8/Rakefile",
|
18
|
+
"coerce-0.0.8/coerce.gemspec",
|
19
|
+
"coerce-0.0.8/lib",
|
20
|
+
"coerce-0.0.8/lib/coerce.rb",
|
17
21
|
"dao.gemspec",
|
18
22
|
"lib",
|
19
23
|
"lib/dao",
|
20
24
|
"lib/dao.rb",
|
25
|
+
"lib/dao/_lib.rb",
|
21
26
|
"lib/dao/active_record.rb",
|
22
27
|
"lib/dao/api",
|
23
28
|
"lib/dao/api.rb",
|
@@ -28,6 +33,7 @@ Gem::Specification::new do |spec|
|
|
28
33
|
"lib/dao/api/modes.rb",
|
29
34
|
"lib/dao/api/routes.rb",
|
30
35
|
"lib/dao/blankslate.rb",
|
36
|
+
"lib/dao/coerce.rb",
|
31
37
|
"lib/dao/conducer",
|
32
38
|
"lib/dao/conducer.rb",
|
33
39
|
"lib/dao/conducer/active_model.rb",
|
@@ -42,6 +48,7 @@ Gem::Specification::new do |spec|
|
|
42
48
|
"lib/dao/endpoint.rb",
|
43
49
|
"lib/dao/engine.rb",
|
44
50
|
"lib/dao/errors.rb",
|
51
|
+
"lib/dao/errors2html.rb",
|
45
52
|
"lib/dao/exceptions.rb",
|
46
53
|
"lib/dao/extractor.rb",
|
47
54
|
"lib/dao/form.rb",
|
@@ -85,6 +92,13 @@ Gem::Specification::new do |spec|
|
|
85
92
|
"lib/dao/validations/common.rb",
|
86
93
|
"lib/dao/validations/instance.rb",
|
87
94
|
"lib/dao/validations/validator.rb",
|
95
|
+
"lib/dao/wrap.rb",
|
96
|
+
"public",
|
97
|
+
"public/system",
|
98
|
+
"public/system/uploads",
|
99
|
+
"tasks",
|
100
|
+
"tasks/default.rake",
|
101
|
+
"tasks/this.rb",
|
88
102
|
"test",
|
89
103
|
"test/active_model_conducer_lint_test.rb",
|
90
104
|
"test/api_test.rb",
|
@@ -93,11 +107,21 @@ Gem::Specification::new do |spec|
|
|
93
107
|
"test/data/han-solo.jpg",
|
94
108
|
"test/errors_test.rb",
|
95
109
|
"test/form_test.rb",
|
96
|
-
"test/helper.rb",
|
97
110
|
"test/leak.rb",
|
111
|
+
"test/rake_rerun_reporter.rb",
|
98
112
|
"test/support_test.rb",
|
99
|
-
"test/
|
100
|
-
"test/
|
113
|
+
"test/test_helper.rb",
|
114
|
+
"test/util.rb",
|
115
|
+
"test/validations_test.rb",
|
116
|
+
"wrap-1.5.2",
|
117
|
+
"wrap-1.5.2/README",
|
118
|
+
"wrap-1.5.2/Rakefile",
|
119
|
+
"wrap-1.5.2/lib",
|
120
|
+
"wrap-1.5.2/lib/wrap.rb",
|
121
|
+
"wrap-1.5.2/test",
|
122
|
+
"wrap-1.5.2/test/testing.rb",
|
123
|
+
"wrap-1.5.2/test/wrap_test.rb",
|
124
|
+
"wrap-1.5.2/wrap.gemspec"]
|
101
125
|
|
102
126
|
spec.executables = []
|
103
127
|
|
@@ -106,30 +130,19 @@ Gem::Specification::new do |spec|
|
|
106
130
|
spec.test_files = nil
|
107
131
|
|
108
132
|
|
109
|
-
spec.add_dependency(*["rails", " ~>
|
133
|
+
spec.add_dependency(*["rails", " ~> 6.0"])
|
110
134
|
|
111
|
-
spec.add_dependency(*["map", "
|
135
|
+
spec.add_dependency(*["map", " ~> 6.6"])
|
112
136
|
|
113
|
-
spec.add_dependency(*["fattr", "
|
137
|
+
spec.add_dependency(*["fattr", " ~> 2.4"])
|
114
138
|
|
115
|
-
spec.add_dependency(*["
|
139
|
+
spec.add_dependency(*["tagz", " ~> 9.10"])
|
116
140
|
|
117
|
-
spec.add_dependency(*["
|
118
|
-
|
119
|
-
spec.add_dependency(*["multi_json", " >= 1.0.3"])
|
120
|
-
|
121
|
-
spec.add_dependency(*["uuidtools", " >= 2.1.2"])
|
122
|
-
|
123
|
-
spec.add_dependency(*["wrap", " >= 1.5.0"])
|
124
|
-
|
125
|
-
spec.add_dependency(*["rails_current", " >= 1.8.0"])
|
126
|
-
|
127
|
-
spec.add_dependency(*["rails_errors2html", " >= 1.3.0"])
|
141
|
+
spec.add_dependency(*["rails_current", " ~> 2.2"])
|
128
142
|
|
129
143
|
|
130
144
|
spec.extensions.push(*[])
|
131
145
|
|
132
|
-
spec.rubyforge_project = "codeforpeople"
|
133
146
|
spec.author = "Ara T. Howard"
|
134
147
|
spec.email = "ara.t.howard@gmail.com"
|
135
148
|
spec.homepage = "https://github.com/ahoward/dao"
|
data/lib/dao.rb
CHANGED
@@ -7,86 +7,42 @@
|
|
7
7
|
require 'cgi'
|
8
8
|
require 'tmpdir'
|
9
9
|
require 'yaml'
|
10
|
+
require 'securerandom'
|
11
|
+
require 'json'
|
10
12
|
|
11
13
|
# dao libs
|
12
14
|
#
|
13
|
-
|
14
|
-
|
15
|
+
require 'map'
|
16
|
+
require 'fattr'
|
17
|
+
require 'tagz'
|
18
|
+
require 'rails_current'
|
15
19
|
|
16
|
-
def version
|
17
|
-
Dao::Version
|
18
|
-
end
|
19
|
-
|
20
|
-
def dependencies
|
21
|
-
{
|
22
|
-
'rails' => [ 'rails' , ' ~> 3.1' ] ,
|
23
|
-
'map' => [ 'map' , ' >= 6.0.0' ] ,
|
24
|
-
'fattr' => [ 'fattr' , ' >= 2.2' ] ,
|
25
|
-
'coerce' => [ 'coerce' , ' >= 0.0.3' ] ,
|
26
|
-
'tagz' => [ 'tagz' , ' >= 9.9.2' ] ,
|
27
|
-
'multi_json' => [ 'multi_json' , ' >= 1.0.3' ] ,
|
28
|
-
'uuidtools' => [ 'uuidtools' , ' >= 2.1.2' ] ,
|
29
|
-
'wrap' => [ 'wrap' , ' >= 1.5.0' ] ,
|
30
|
-
'rails_current' => [ 'rails_current' , ' >= 1.8.0' ] ,
|
31
|
-
'rails_errors2html' => [ 'rails_errors2html' , ' >= 1.3.0' ] ,
|
32
|
-
}
|
33
|
-
end
|
34
|
-
|
35
|
-
def description
|
36
|
-
"presenter, conducer, api, and better form objects for you rails' pleasure"
|
37
|
-
end
|
38
|
-
|
39
|
-
def libdir(*args, &block)
|
40
|
-
@libdir ||= File.expand_path(__FILE__).sub(/\.rb$/,'')
|
41
|
-
args.empty? ? @libdir : File.join(@libdir, *args)
|
42
|
-
ensure
|
43
|
-
if block
|
44
|
-
begin
|
45
|
-
$LOAD_PATH.unshift(@libdir)
|
46
|
-
block.call()
|
47
|
-
ensure
|
48
|
-
$LOAD_PATH.shift()
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def load(*libs)
|
54
|
-
libs = libs.join(' ').scan(/[^\s+]+/)
|
55
|
-
Dao.libdir{ libs.each{|lib| Kernel.load(lib) } }
|
56
|
-
end
|
57
|
-
|
58
|
-
extend(Dao)
|
59
|
-
end
|
60
|
-
|
61
|
-
# gems
|
62
20
|
#
|
63
|
-
|
64
|
-
require 'rubygems'
|
65
|
-
rescue LoadError
|
66
|
-
nil
|
67
|
-
end
|
68
|
-
|
69
|
-
if defined?(gem)
|
70
|
-
Dao.dependencies.each do |lib, dependency|
|
71
|
-
gem(*dependency)
|
72
|
-
require(lib)
|
73
|
-
end
|
74
|
-
end
|
21
|
+
require_relative 'dao/_lib.rb'
|
75
22
|
|
23
|
+
#
|
76
24
|
%w[
|
77
25
|
action_controller
|
78
|
-
active_resource
|
79
26
|
active_support
|
27
|
+
active_model
|
80
28
|
].each do |framework|
|
81
29
|
begin
|
82
30
|
require "#{ framework }/railtie"
|
83
31
|
rescue LoadError
|
32
|
+
begin
|
33
|
+
require "#{ framework }"
|
34
|
+
rescue LoadError
|
35
|
+
raise
|
36
|
+
end
|
84
37
|
end
|
85
38
|
end
|
86
39
|
|
87
40
|
|
41
|
+
#
|
88
42
|
Dao.load %w[
|
89
43
|
blankslate.rb
|
44
|
+
coerce.rb
|
45
|
+
wrap.rb
|
90
46
|
instance_exec.rb
|
91
47
|
extractor.rb
|
92
48
|
exceptions.rb
|
@@ -97,6 +53,7 @@
|
|
97
53
|
name.rb
|
98
54
|
status.rb
|
99
55
|
path_map.rb
|
56
|
+
errors2html.rb
|
100
57
|
errors.rb
|
101
58
|
messages.rb
|
102
59
|
form.rb
|
@@ -120,23 +77,3 @@
|
|
120
77
|
conducer.rb
|
121
78
|
upload.rb
|
122
79
|
]
|
123
|
-
|
124
|
-
|
125
|
-
unless defined?(::UUIDTools::Config)
|
126
|
-
::UUIDTools.module_eval do
|
127
|
-
Config = ::RbConfig # shuts up warnings...
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
# protect against rails' too clever reloading
|
132
|
-
#
|
133
|
-
=begin
|
134
|
-
if defined?(Rails)
|
135
|
-
unless defined?(unloadable)
|
136
|
-
require 'active_support'
|
137
|
-
require 'active_support/dependencies'
|
138
|
-
end
|
139
|
-
unloadable(Dao)
|
140
|
-
end
|
141
|
-
BEGIN{ Object.send(:remove_const, :Dao) if defined?(Dao) }
|
142
|
-
=end
|