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
data/lib/dao/db.rb
CHANGED
data/lib/dao/errors.rb
CHANGED
@@ -106,13 +106,13 @@ module Dao
|
|
106
106
|
list.clear if clear
|
107
107
|
list.push(message)
|
108
108
|
list.uniq!
|
109
|
-
list
|
110
109
|
self
|
111
110
|
end
|
112
111
|
alias_method('add!', 'add')
|
113
112
|
alias_method('add_to_base', 'add')
|
114
113
|
alias_method('add_to_base!', 'add!')
|
115
114
|
|
115
|
+
# FIXME - this should accept an errors object
|
116
116
|
def relay(*args)
|
117
117
|
options = args.size > 1 ? Map.options_for!(args) : Map.new
|
118
118
|
|
@@ -123,7 +123,15 @@ module Dao
|
|
123
123
|
|
124
124
|
errors.each do |*argv|
|
125
125
|
msgs = Array(argv.pop)
|
126
|
+
|
127
|
+
# ref: support for key-style of https://github.com/glooko/mongoid-embedded-errors
|
128
|
+
#key = Array(argv.pop).flatten.compact.join('.')
|
129
|
+
#key = key.to_s.split('.')
|
130
|
+
#key.map!{|k| k =~ /\[(\d+)\]/ ? $1 : k}
|
131
|
+
#key = prefix + key
|
132
|
+
|
126
133
|
key = prefix + Array(argv.pop)
|
134
|
+
|
127
135
|
msgs.each{|msg| add(Array(options[:key] || key), msg, options)}
|
128
136
|
end
|
129
137
|
end
|
@@ -168,7 +176,7 @@ module Dao
|
|
168
176
|
full_messages = []
|
169
177
|
|
170
178
|
depth_first_each do |keys, value|
|
171
|
-
|
179
|
+
_ = keys.pop
|
172
180
|
key = keys
|
173
181
|
value = value.to_s
|
174
182
|
|
@@ -186,7 +194,7 @@ module Dao
|
|
186
194
|
|
187
195
|
def each_message
|
188
196
|
depth_first_each do |keys, message|
|
189
|
-
|
197
|
+
_ = keys.pop
|
190
198
|
message = message.to_s.strip
|
191
199
|
yield(keys, message)
|
192
200
|
end
|
@@ -196,7 +204,7 @@ module Dao
|
|
196
204
|
hash = Hash.new
|
197
205
|
|
198
206
|
depth_first_each do |keys, value|
|
199
|
-
|
207
|
+
_ = keys.pop
|
200
208
|
hash[keys] ||= []
|
201
209
|
hash[keys].push("#{ value }")
|
202
210
|
end
|
@@ -211,9 +219,8 @@ module Dao
|
|
211
219
|
alias_method('each_full', 'each_full_message')
|
212
220
|
|
213
221
|
def messages
|
214
|
-
|
215
|
-
|
216
|
-
select{|message| not message.strip.empty?}
|
222
|
+
(self[Global] || []).map{|message| message}
|
223
|
+
.select{|message| not message.strip.empty?}
|
217
224
|
end
|
218
225
|
|
219
226
|
def global
|
@@ -227,7 +234,7 @@ module Dao
|
|
227
234
|
# html generation methods
|
228
235
|
#
|
229
236
|
def to_html(*args)
|
230
|
-
Errors.to_html(
|
237
|
+
Errors.to_html(self, *args)
|
231
238
|
end
|
232
239
|
|
233
240
|
def Errors.to_html(*args, &block)
|
@@ -239,7 +246,7 @@ module Dao
|
|
239
246
|
end
|
240
247
|
|
241
248
|
def Errors.errors_to_html(*args)
|
242
|
-
|
249
|
+
Errors2Html.to_html(*args)
|
243
250
|
end
|
244
251
|
|
245
252
|
def to_s(format = :html, *args, &block)
|
@@ -254,7 +261,6 @@ module Dao
|
|
254
261
|
|
255
262
|
class KeyPrefixer
|
256
263
|
attr_accessor :object
|
257
|
-
attr_accessor :prefix
|
258
264
|
attr_accessor :global
|
259
265
|
|
260
266
|
def initialize(object)
|
@@ -299,7 +305,7 @@ module Dao
|
|
299
305
|
|
300
306
|
def Errors.to_hash(*args)
|
301
307
|
error = args.shift
|
302
|
-
|
308
|
+
Map.options_for!(args)
|
303
309
|
errors = [error, *args].flatten.compact
|
304
310
|
|
305
311
|
map = Map.new
|
@@ -0,0 +1,128 @@
|
|
1
|
+
module Dao
|
2
|
+
module Errors2Html
|
3
|
+
class View
|
4
|
+
def View.controller(&block)
|
5
|
+
controller = ::Current.controller ? ::Current.controller.dup : ::Current.mock_controller
|
6
|
+
block ? controller.instance_eval(&block) : controller
|
7
|
+
end
|
8
|
+
|
9
|
+
def View.render(*args)
|
10
|
+
options = args.extract_options!.to_options!
|
11
|
+
args.push(options)
|
12
|
+
|
13
|
+
unless options.has_key?(:layout)
|
14
|
+
options[:layout] = false
|
15
|
+
end
|
16
|
+
|
17
|
+
Array(View.controller{ render(*args) }).join.html_safe
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def Errors2Html.to_html(*args)
|
22
|
+
if args.size == 1
|
23
|
+
case args.first
|
24
|
+
when Array, String, Symbol
|
25
|
+
messages = Array(args.first)
|
26
|
+
args = [{:base => messages}]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
args.flatten!
|
31
|
+
args.compact!
|
32
|
+
|
33
|
+
at_least_one_error = false
|
34
|
+
|
35
|
+
errors = Map.new
|
36
|
+
errors[:global] = []
|
37
|
+
errors[:fields] = {}
|
38
|
+
|
39
|
+
args.each do |e|
|
40
|
+
flatten(e).each do |key, messages|
|
41
|
+
Array(messages).each do |message|
|
42
|
+
at_least_one_error = true
|
43
|
+
message = message.to_s.html_safe
|
44
|
+
|
45
|
+
if Array(key).join =~ /\A(?:[*]|base)\Z/iomx
|
46
|
+
errors.global.push(message).uniq!
|
47
|
+
else
|
48
|
+
(errors.fields[key] ||= []).push(message).uniq!
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
return "" unless at_least_one_error
|
55
|
+
|
56
|
+
locals = {
|
57
|
+
:errors => errors,
|
58
|
+
:global_errors => errors.global,
|
59
|
+
:fields_errors => errors.fields
|
60
|
+
}
|
61
|
+
|
62
|
+
if template
|
63
|
+
View.render(:template => template, :locals => locals, :layout => false)
|
64
|
+
else
|
65
|
+
View.render(:inline => inline, :locals => locals, :layout => false)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def Errors2Html.flatten(hashlike)
|
70
|
+
case hashlike
|
71
|
+
when Map
|
72
|
+
hash = Hash.new
|
73
|
+
hashlike.depth_first_each do |key, value|
|
74
|
+
_ = key.pop if key.last.is_a?(Integer)
|
75
|
+
(hash[key] ||= []).push(value)
|
76
|
+
end
|
77
|
+
hash
|
78
|
+
else
|
79
|
+
hashlike.respond_to?(:to_hash) ? hashlike.to_hash : hashlike
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
Fattr(:inline) do
|
84
|
+
<<-erb
|
85
|
+
<div class="errors2html errors-summary">
|
86
|
+
<h4 class="errors-caption">Sorry, we encountered some errors:</h4>
|
87
|
+
|
88
|
+
<% unless errors.global.empty? %>
|
89
|
+
|
90
|
+
<ul class="errors-global-list">
|
91
|
+
<% errors.global.each do |message| %>
|
92
|
+
<li class="errors-message">
|
93
|
+
<%= message %>
|
94
|
+
</li>
|
95
|
+
<% end %>
|
96
|
+
</ul>
|
97
|
+
<% end %>
|
98
|
+
|
99
|
+
<% unless errors.fields.empty? %>
|
100
|
+
|
101
|
+
<dl class="errors-fields-list">
|
102
|
+
<%
|
103
|
+
errors.fields.each do |key, messages|
|
104
|
+
title = Array(key).join(" ").titleize
|
105
|
+
%>
|
106
|
+
<dt class="errors-title">
|
107
|
+
<%= title %>
|
108
|
+
</dt>
|
109
|
+
<% Array(messages).each do |message| %>
|
110
|
+
<dd class="errors-message">
|
111
|
+
<%= message %>
|
112
|
+
</dd>
|
113
|
+
|
114
|
+
<% end %>
|
115
|
+
<% end %>
|
116
|
+
</dl>
|
117
|
+
<% end %>
|
118
|
+
</div>
|
119
|
+
erb
|
120
|
+
end
|
121
|
+
|
122
|
+
Fattr(:template){ nil }
|
123
|
+
end
|
124
|
+
|
125
|
+
##
|
126
|
+
#
|
127
|
+
Errors2HTML = Errors2Html
|
128
|
+
end
|
data/lib/dao/form.rb
CHANGED
@@ -12,7 +12,7 @@ module Dao
|
|
12
12
|
# builder stuff for compatibity with rails' form_for()
|
13
13
|
#
|
14
14
|
class Builder < Form
|
15
|
-
def Builder.new(object_name, object, view, options, block)
|
15
|
+
def Builder.new(object_name, object, view, options, block=:rails_3_4_5)
|
16
16
|
if object.respond_to?(:form)
|
17
17
|
|
18
18
|
html = options[:html] || {}
|
@@ -40,7 +40,6 @@ module Dao
|
|
40
40
|
#
|
41
41
|
attr_accessor :object
|
42
42
|
attr_accessor :unscoped
|
43
|
-
attr_accessor :scope
|
44
43
|
|
45
44
|
def initialize(*args)
|
46
45
|
@object = args.shift
|
@@ -173,7 +172,7 @@ module Dao
|
|
173
172
|
if block.nil? and !options.has_key?(:content)
|
174
173
|
''
|
175
174
|
else
|
176
|
-
block ? block.call(
|
175
|
+
block ? block.call(self) : options.delete(:content)
|
177
176
|
end
|
178
177
|
|
179
178
|
form_(options_for(options, :action => action, :method => method, :class => klass, :id => id, :data_error => error)){ content }
|
@@ -275,7 +274,7 @@ module Dao
|
|
275
274
|
options[:checked] = checked if checked
|
276
275
|
end
|
277
276
|
|
278
|
-
input_(options_for(options, :type =>
|
277
|
+
input_(options_for(options, :type => type, :name => name, :class => klass, :id => id, :data_error => error)){}
|
279
278
|
end
|
280
279
|
|
281
280
|
def checkbox(*args, &block)
|
@@ -303,14 +302,14 @@ module Dao
|
|
303
302
|
values.map{|k, v| h[ k =~ /t|1|on|yes/ ? true : false ] = v}
|
304
303
|
h
|
305
304
|
else
|
306
|
-
t, f, *
|
305
|
+
t, f, *_ = Array(values).flatten.compact
|
307
306
|
{true => t, false => f}
|
308
307
|
end
|
309
308
|
value_for[true] ||= '1'
|
310
309
|
value_for[false] ||= '0'
|
311
310
|
|
312
311
|
hidden_options =
|
313
|
-
options.dup.tap{|o| o.delete(
|
312
|
+
options.dup.tap{|o| [:checked, :required, :disabled].each{|k| o.delete(k)}}
|
314
313
|
|
315
314
|
tagz{
|
316
315
|
input_(options_for(hidden_options, :type => :hidden, :name => name, :value => value_for[false])){}
|
@@ -320,7 +319,7 @@ module Dao
|
|
320
319
|
input_(
|
321
320
|
options_for(
|
322
321
|
options,
|
323
|
-
:type =>
|
322
|
+
:type => type,
|
324
323
|
:name => name,
|
325
324
|
:value => value_for[true],
|
326
325
|
:class => klass,
|
@@ -367,7 +366,7 @@ module Dao
|
|
367
366
|
end
|
368
367
|
|
369
368
|
def select(*args, &block)
|
370
|
-
options = args.extract_options!.to_options!
|
369
|
+
options = args.extract_options!.to_options!
|
371
370
|
keys = scope(args)
|
372
371
|
|
373
372
|
name = options.delete(:name) || name_for(keys)
|
@@ -381,7 +380,7 @@ module Dao
|
|
381
380
|
error = error_for(keys, options.delete(:error))
|
382
381
|
|
383
382
|
if values.nil?
|
384
|
-
key = keys.map{|
|
383
|
+
key = keys.map{|k| "#{k}"}
|
385
384
|
key.last << "_options"
|
386
385
|
values = attributes.get(*key) if attributes.has?(*key)
|
387
386
|
end
|
@@ -442,7 +441,7 @@ module Dao
|
|
442
441
|
|
443
442
|
case returned
|
444
443
|
when Array
|
445
|
-
content, value, selected, *
|
444
|
+
content, value, selected, *_ = returned
|
446
445
|
if value.is_a?(Hash)
|
447
446
|
map = Map.for(value)
|
448
447
|
value = map.delete(:value)
|
@@ -506,7 +505,7 @@ module Dao
|
|
506
505
|
# html generation support methods
|
507
506
|
#
|
508
507
|
def id_for(keys)
|
509
|
-
id = [name, keys.join('-')].compact.join('
|
508
|
+
id = [name, keys.join('-')].compact.join('--')
|
510
509
|
slug_for(id)
|
511
510
|
end
|
512
511
|
|
@@ -641,7 +640,7 @@ module Dao
|
|
641
640
|
end
|
642
641
|
|
643
642
|
def attr_for(string)
|
644
|
-
slug_for(string)
|
643
|
+
slug_for(string)
|
645
644
|
end
|
646
645
|
|
647
646
|
def data_attr_for(string)
|
@@ -650,10 +649,8 @@ module Dao
|
|
650
649
|
|
651
650
|
def slug_for(string)
|
652
651
|
string = string.to_s
|
653
|
-
words = string.
|
654
|
-
words.
|
655
|
-
words.delete_if{|word| word.nil? or word.strip.empty?}
|
656
|
-
words.join('-').downcase.sub(/_+$/, '')
|
652
|
+
words = string.scan(%r/[^\s]+/)
|
653
|
+
words.join('--').downcase
|
657
654
|
end
|
658
655
|
|
659
656
|
def titleize(string)
|
data/lib/dao/messages.rb
CHANGED
data/lib/dao/path.rb
CHANGED
data/lib/dao/route.rb
CHANGED
@@ -54,7 +54,7 @@ module Dao
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def match(path)
|
57
|
-
|
57
|
+
pattern.match(path).to_a
|
58
58
|
end
|
59
59
|
|
60
60
|
def params_for(path)
|
@@ -62,7 +62,7 @@ module Dao
|
|
62
62
|
|
63
63
|
unless match.empty?
|
64
64
|
map = Map.new
|
65
|
-
|
65
|
+
_ = match.shift
|
66
66
|
@keys.each_with_index do |key, index|
|
67
67
|
map[key] = match[index]
|
68
68
|
end
|
data/lib/dao/status.rb
CHANGED
@@ -181,7 +181,6 @@ module Dao
|
|
181
181
|
arg = args.shift
|
182
182
|
case arg
|
183
183
|
when Result
|
184
|
-
result = arg
|
185
184
|
if arg.errors.nil? or arg.errors.empty? or arg.valid?
|
186
185
|
new(200)
|
187
186
|
else
|
@@ -189,7 +188,7 @@ module Dao
|
|
189
188
|
end
|
190
189
|
when Status
|
191
190
|
arg
|
192
|
-
when
|
191
|
+
when Integer
|
193
192
|
code = arg
|
194
193
|
message = Code2Message[code]
|
195
194
|
new(code, message)
|
@@ -276,7 +275,7 @@ module Dao
|
|
276
275
|
end
|
277
276
|
|
278
277
|
Groups.each do |code, group|
|
279
|
-
module_eval
|
278
|
+
module_eval(<<-__, __FILE__, __LINE__ - 1)
|
280
279
|
def Status.#{ group }
|
281
280
|
@status_group_#{ group } ||= Status.for(#{ code })
|
282
281
|
end
|
@@ -316,7 +315,7 @@ module Dao
|
|
316
315
|
end
|
317
316
|
|
318
317
|
def clone
|
319
|
-
|
318
|
+
Status.for(code)
|
320
319
|
end
|
321
320
|
|
322
321
|
def to_json(*args, &block)
|
data/lib/dao/support.rb
CHANGED
@@ -120,6 +120,9 @@ module Dao
|
|
120
120
|
|
121
121
|
paths_and_values.each do |path, value|
|
122
122
|
keys = keys_for(path)
|
123
|
+
if map.has?(keys)
|
124
|
+
inc_keys!(keys)
|
125
|
+
end
|
123
126
|
map.set(keys => value)
|
124
127
|
end
|
125
128
|
|
@@ -141,9 +144,24 @@ module Dao
|
|
141
144
|
digity ? stringy ? String(digits) : Integer(digits) : key
|
142
145
|
end
|
143
146
|
end
|
144
|
-
|
145
147
|
alias_method(:key_for, :keys_for)
|
146
148
|
|
149
|
+
def inc_keys!(keys)
|
150
|
+
last_number_index = nil
|
151
|
+
|
152
|
+
keys.each_with_index do |k, i|
|
153
|
+
if k.is_a?(Numeric)
|
154
|
+
last_number_index = i
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
if last_number_index
|
159
|
+
keys[last_number_index] = keys[last_number_index] + 1
|
160
|
+
end
|
161
|
+
|
162
|
+
keys
|
163
|
+
end
|
164
|
+
|
147
165
|
def render_json(object, options = {})
|
148
166
|
options = options.to_options!
|
149
167
|
controller = options[:controller] || Dao.current_controller
|
@@ -165,12 +183,13 @@ module Dao
|
|
165
183
|
def json_for(object, options = {})
|
166
184
|
object = object.as_json if object.respond_to?(:as_json)
|
167
185
|
|
168
|
-
|
169
|
-
|
186
|
+
pretty = (options.delete(:pretty) || json_pretty?)
|
187
|
+
|
188
|
+
generate = pretty ? :pretty_generate : :generate
|
170
189
|
|
171
190
|
begin
|
172
|
-
|
173
|
-
rescue Object =>
|
191
|
+
JSON.send(generate, object, options)
|
192
|
+
rescue Object => _
|
174
193
|
YAML.load( object.to_yaml ).to_json
|
175
194
|
end
|
176
195
|
end
|
@@ -213,21 +232,9 @@ module Dao
|
|
213
232
|
end
|
214
233
|
end
|
215
234
|
|
216
|
-
|
217
|
-
|
218
|
-
'ffi-uuid' => proc{|*args| FFI::UUID.generate_time.to_s},
|
219
|
-
'uuidtools' => proc{|*args| UUIDTools::UUID.timestamp_create.to_s},
|
220
|
-
'uuid' => proc{|*args| UUID.generate.to_s},
|
221
|
-
}.each do |lib, implementation|
|
222
|
-
begin
|
223
|
-
require(lib)
|
224
|
-
define_method(:uuid, &implementation)
|
225
|
-
break
|
226
|
-
rescue LoadError
|
227
|
-
nil
|
228
|
-
end
|
235
|
+
def uuid
|
236
|
+
SecureRandom.uuid
|
229
237
|
end
|
230
|
-
abort 'no suitable uuid generation library detected' unless method_defined?(:uuid)
|
231
238
|
|
232
239
|
def ensure_interface!(object, *interface)
|
233
240
|
interface.flatten.compact.each do |method|
|