dao 2.1.0 → 2.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +1 -0
- data/TODO +39 -0
- data/dao.gemspec +4 -4
- data/lib/dao.rb +8 -4
- data/lib/dao/active_record.rb +46 -4
- data/lib/dao/api/interfaces.rb +19 -4
- data/lib/dao/data.rb +3 -53
- data/lib/dao/errors.rb +26 -19
- data/lib/dao/exceptions.rb +23 -1
- data/lib/dao/form.rb +55 -11
- data/lib/dao/params.rb +41 -51
- data/lib/dao/presenter.rb +129 -0
- data/lib/dao/rails.rb +49 -1
- data/lib/dao/rails/lib/generators/dao/dao_generator.rb +1 -2
- data/lib/dao/rails/lib/generators/dao/templates/api.rb +1 -1
- data/lib/dao/rails/lib/generators/dao/templates/api_controller.rb +25 -31
- data/lib/dao/rails/lib/generators/dao/templates/dao.js +34 -25
- data/lib/dao/rails/lib/generators/dao/templates/dao_helper.rb +2 -1
- data/lib/dao/result.rb +27 -2
- data/lib/dao/status.rb +10 -2
- data/lib/dao/support.rb +1 -1
- data/lib/dao/validations.rb +143 -8
- data/test/dao_test.rb +56 -1
- metadata +15 -13
data/README
CHANGED
@@ -105,6 +105,7 @@ READING
|
|
105
105
|
http://www.codefutures.com/data-access-object/
|
106
106
|
http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html
|
107
107
|
http://www.paperplanes.de/2010/5/7/activerecord_callbacks_ruined_my_life.html
|
108
|
+
http://google-styleguide.googlecode.com/svn/trunk/jsoncstyleguide.xml
|
108
109
|
|
109
110
|
INSTALL
|
110
111
|
gem 'dao', :path => File.expand_path('..') ### Gemfile
|
data/TODO
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
todo:
|
2
|
+
|
3
|
+
- auto apply?
|
4
|
+
|
5
|
+
- pre-condition and parameter code
|
6
|
+
|
7
|
+
|
8
|
+
- class level nested AR conversions
|
9
|
+
to_dao(:a, :b => [:foo, :bar])
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
done:
|
14
|
+
- engine-ify the rails stuff? or what
|
15
|
+
- generator api
|
16
|
+
- controller
|
17
|
+
- helper
|
18
|
+
- json/pretty fix baked in? (yajl might simply this...)
|
19
|
+
- description/doc logic
|
20
|
+
- api.index
|
21
|
+
- to_alpo -> to_dao
|
22
|
+
- tests!
|
23
|
+
- #call auto parses data iff appropriate
|
24
|
+
@result = api.read.call('/posts/new(', params) ### check keys for '/posts/new'
|
25
|
+
- re-visit how parameters are parsed, perhaps we just use rack?
|
26
|
+
- next 'data' => {}
|
27
|
+
- check the db layer
|
28
|
+
- make sure one can call route based method (/foo/:bar) methods with params...
|
29
|
+
- Path==Route ??
|
30
|
+
- add result.rb, params.rb
|
31
|
+
- name -> path
|
32
|
+
- tagz for html methods?
|
33
|
+
- data aquires the name/path of the method?
|
34
|
+
- interfaces are objects that respond to call. namespaces respond to call.
|
35
|
+
api responds to call
|
36
|
+
- nested namespaces
|
37
|
+
- routing for path_info + mode
|
38
|
+
route(path_info, :mode => mode, :params => params)
|
39
|
+
- call() on namespaces AND interfaces... why?
|
data/dao.gemspec
CHANGED
@@ -3,12 +3,12 @@
|
|
3
3
|
|
4
4
|
Gem::Specification::new do |spec|
|
5
5
|
spec.name = "dao"
|
6
|
-
spec.version = "2.
|
6
|
+
spec.version = "2.2.3"
|
7
7
|
spec.platform = Gem::Platform::RUBY
|
8
8
|
spec.summary = "dao"
|
9
9
|
spec.description = "description: dao kicks the ass"
|
10
10
|
|
11
|
-
spec.files = ["dao.gemspec", "lib", "lib/dao", "lib/dao/active_record.rb", "lib/dao/api", "lib/dao/api/context.rb", "lib/dao/api/dsl.rb", "lib/dao/api/endpoints.rb", "lib/dao/api/initializers.rb", "lib/dao/api/interfaces.rb", "lib/dao/api/modes.rb", "lib/dao/api.rb", "lib/dao/blankslate.rb", "lib/dao/data.rb", "lib/dao/db.rb", "lib/dao/endpoint.rb", "lib/dao/engine.rb", "lib/dao/errors.rb", "lib/dao/exceptions.rb", "lib/dao/form.rb", "lib/dao/instance_exec.rb", "lib/dao/interface.rb", "lib/dao/mode.rb", "lib/dao/mongo_mapper.rb", "lib/dao/params.rb", "lib/dao/path.rb", "lib/dao/rails", "lib/dao/rails/app", "lib/dao/rails/app/api.rb", "lib/dao/rails/app/controllers", "lib/dao/rails/app/controllers/api_controller.rb", "lib/dao/rails/
|
11
|
+
spec.files = ["dao.gemspec", "lib", "lib/dao", "lib/dao/active_record.rb", "lib/dao/api", "lib/dao/api/context.rb", "lib/dao/api/dsl.rb", "lib/dao/api/endpoints.rb", "lib/dao/api/initializers.rb", "lib/dao/api/interfaces.rb", "lib/dao/api/modes.rb", "lib/dao/api.rb", "lib/dao/blankslate.rb", "lib/dao/data.rb", "lib/dao/db.rb", "lib/dao/endpoint.rb", "lib/dao/engine.rb", "lib/dao/errors.rb", "lib/dao/exceptions.rb", "lib/dao/form.rb", "lib/dao/instance_exec.rb", "lib/dao/interface.rb", "lib/dao/mode.rb", "lib/dao/mongo_mapper.rb", "lib/dao/params.rb", "lib/dao/path.rb", "lib/dao/presenter.rb", "lib/dao/rails", "lib/dao/rails/app", "lib/dao/rails/app/api.rb", "lib/dao/rails/app/controllers", "lib/dao/rails/app/controllers/api_controller.rb", "lib/dao/rails/lib", "lib/dao/rails/lib/generators", "lib/dao/rails/lib/generators/dao", "lib/dao/rails/lib/generators/dao/api_generator.rb", "lib/dao/rails/lib/generators/dao/dao_generator.rb", "lib/dao/rails/lib/generators/dao/templates", "lib/dao/rails/lib/generators/dao/templates/api.rb", "lib/dao/rails/lib/generators/dao/templates/api_controller.rb", "lib/dao/rails/lib/generators/dao/templates/dao.css", "lib/dao/rails/lib/generators/dao/templates/dao.js", "lib/dao/rails/lib/generators/dao/templates/dao_helper.rb", "lib/dao/rails/lib/generators/dao/USAGE", "lib/dao/rails.rb", "lib/dao/result.rb", "lib/dao/slug.rb", "lib/dao/status.rb", "lib/dao/stdext.rb", "lib/dao/support.rb", "lib/dao/validations.rb", "lib/dao.rb", "Rakefile", "README", "sample", "sample/rails_app", "sample/rails_app/app", "sample/rails_app/app/api.rb", "sample/rails_app/app/controllers", "sample/rails_app/app/controllers/api_controller.rb", "sample/rails_app/app/controllers/application_controller.rb", "sample/rails_app/app/helpers", "sample/rails_app/app/helpers/application_helper.rb", "sample/rails_app/app/mailers", "sample/rails_app/app/models", "sample/rails_app/app/views", "sample/rails_app/app/views/layouts", "sample/rails_app/app/views/layouts/application.html.erb", "sample/rails_app/config", "sample/rails_app/config/application.rb", "sample/rails_app/config/boot.rb", "sample/rails_app/config/database.yml", "sample/rails_app/config/environment.rb", "sample/rails_app/config/environments", "sample/rails_app/config/environments/development.rb", "sample/rails_app/config/environments/production.rb", "sample/rails_app/config/environments/test.rb", "sample/rails_app/config/initializers", "sample/rails_app/config/initializers/backtrace_silencers.rb", "sample/rails_app/config/initializers/inflections.rb", "sample/rails_app/config/initializers/mime_types.rb", "sample/rails_app/config/initializers/secret_token.rb", "sample/rails_app/config/initializers/session_store.rb", "sample/rails_app/config/locales", "sample/rails_app/config/locales/en.yml", "sample/rails_app/config/routes.rb", "sample/rails_app/config.ru", "sample/rails_app/db", "sample/rails_app/db/development.sqlite3", "sample/rails_app/db/seeds.rb", "sample/rails_app/doc", "sample/rails_app/doc/README_FOR_APP", "sample/rails_app/Gemfile", "sample/rails_app/Gemfile.lock", "sample/rails_app/lib", "sample/rails_app/lib/tasks", "sample/rails_app/log", "sample/rails_app/log/development.log", "sample/rails_app/log/production.log", "sample/rails_app/log/server.log", "sample/rails_app/log/test.log", "sample/rails_app/pubic", "sample/rails_app/pubic/javascripts", "sample/rails_app/pubic/javascripts/dao.js", "sample/rails_app/public", "sample/rails_app/public/404.html", "sample/rails_app/public/422.html", "sample/rails_app/public/500.html", "sample/rails_app/public/favicon.ico", "sample/rails_app/public/images", "sample/rails_app/public/images/rails.png", "sample/rails_app/public/index.html", "sample/rails_app/public/javascripts", "sample/rails_app/public/javascripts/application.js", "sample/rails_app/public/javascripts/controls.js", "sample/rails_app/public/javascripts/dragdrop.js", "sample/rails_app/public/javascripts/effects.js", "sample/rails_app/public/javascripts/prototype.js", "sample/rails_app/public/javascripts/rails.js", "sample/rails_app/public/robots.txt", "sample/rails_app/public/stylesheets", "sample/rails_app/Rakefile", "sample/rails_app/README", "sample/rails_app/script", "sample/rails_app/script/rails", "sample/rails_app/test", "sample/rails_app/test/fixtures", "sample/rails_app/test/functional", "sample/rails_app/test/integration", "sample/rails_app/test/performance", "sample/rails_app/test/performance/browsing_test.rb", "sample/rails_app/test/test_helper.rb", "sample/rails_app/test/unit", "sample/rails_app/tmp/cache", "sample/rails_app/tmp/pids", "sample/rails_app/tmp/sessions", "sample/rails_app/tmp/sockets", "sample/rails_app/vendor", "sample/rails_app/vendor/plugins", "test", "test/dao_test.rb", "test/helper.rb", "test/testing.rb", "test/units", "TODO"]
|
12
12
|
spec.executables = []
|
13
13
|
|
14
14
|
spec.require_path = "lib"
|
@@ -20,9 +20,9 @@ Gem::Specification::new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_dependency(*["tagz", "~> 8.2.0"])
|
22
22
|
|
23
|
-
spec.add_dependency(*["map", "~> 2.
|
23
|
+
spec.add_dependency(*["map", "~> 2.7.0"])
|
24
24
|
|
25
|
-
spec.add_dependency(*["yajl-ruby", "~> 0.
|
25
|
+
spec.add_dependency(*["yajl-ruby", "~> 0.8.1"])
|
26
26
|
|
27
27
|
|
28
28
|
spec.extensions.push(*[])
|
data/lib/dao.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# built-ins
|
2
2
|
#
|
3
3
|
require 'enumerator'
|
4
|
+
require 'set'
|
4
5
|
#require 'fileutils'
|
5
6
|
#require 'pathname'
|
6
7
|
#require 'yaml'
|
@@ -9,7 +10,7 @@
|
|
9
10
|
# dao libs
|
10
11
|
#
|
11
12
|
module Dao
|
12
|
-
Version = '2.
|
13
|
+
Version = '2.2.3' unless defined?(Version)
|
13
14
|
|
14
15
|
def version
|
15
16
|
Dao::Version
|
@@ -17,9 +18,9 @@
|
|
17
18
|
|
18
19
|
def dependencies
|
19
20
|
{
|
20
|
-
'map'
|
21
|
-
'tagz' => ['tagz', '~> 8.2.0'],
|
22
|
-
'yajl' => ['yajl-ruby', '~> 0.
|
21
|
+
'map' => ['map' , '~> 2.7.0'],
|
22
|
+
'tagz' => ['tagz' , '~> 8.2.0'],
|
23
|
+
'yajl' => ['yajl-ruby' , '~> 0.8.1']
|
23
24
|
}
|
24
25
|
end
|
25
26
|
|
@@ -60,6 +61,8 @@
|
|
60
61
|
end
|
61
62
|
end
|
62
63
|
|
64
|
+
require 'yajl/json_gem'
|
65
|
+
|
63
66
|
Dao.load %w[
|
64
67
|
blankslate.rb
|
65
68
|
instance_exec.rb
|
@@ -75,6 +78,7 @@
|
|
75
78
|
form.rb
|
76
79
|
errors.rb
|
77
80
|
validations.rb
|
81
|
+
presenter.rb
|
78
82
|
|
79
83
|
mode.rb
|
80
84
|
path.rb
|
data/lib/dao/active_record.rb
CHANGED
@@ -26,24 +26,66 @@ if defined?(ActiveRecord)
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def Base.record_to_dao(record, *args)
|
29
|
+
# setup for eff'ing madness
|
30
|
+
#
|
29
31
|
model = record.class
|
30
32
|
map = Dao.map
|
31
33
|
map[:model] = model.name.underscore
|
32
34
|
map[:id] = record.id
|
33
35
|
|
36
|
+
# yank out options if they are patently obvious...
|
37
|
+
#
|
38
|
+
if args.size == 2 and args.first.is_a?(Array) and args.last.is_a?(Hash)
|
39
|
+
options = Dao.map(args.last)
|
40
|
+
args = args.first
|
41
|
+
else
|
42
|
+
options = nil
|
43
|
+
end
|
44
|
+
|
45
|
+
# search for options inside args...
|
46
|
+
#
|
47
|
+
if options.nil?
|
48
|
+
last = args.last
|
49
|
+
options = Dao.map
|
50
|
+
|
51
|
+
if last.is_a?(Hash)
|
52
|
+
last = Dao.map(last)
|
53
|
+
keys = %w( include includes with )
|
54
|
+
if keys.any?{|key| last.has_key?(key)}
|
55
|
+
options.update(last)
|
56
|
+
args.pop
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# refine the list with includes iff passed as options
|
62
|
+
#
|
63
|
+
if options.has_key?(:include) or options.has_key?(:includes) or options.has_key?(:with)
|
64
|
+
args.replace(model.to_dao) if args.empty?
|
65
|
+
args.push(options[:include]) if options[:include]
|
66
|
+
args.push(options[:includes]) if options[:includes]
|
67
|
+
args.push(options[:with]) if options[:with]
|
68
|
+
end
|
69
|
+
|
70
|
+
# take passed in args or model defaults
|
71
|
+
#
|
34
72
|
list = args.empty? ? model.to_dao : args
|
35
73
|
|
74
|
+
# okay - go!
|
75
|
+
#
|
36
76
|
list.each do |attr|
|
37
77
|
if attr.is_a?(Array)
|
38
78
|
related, *argv = attr
|
39
|
-
|
79
|
+
v = record.send(related)
|
80
|
+
value = v.respond_to?(:to_dao) ? v.to_dao(*argv) : v
|
40
81
|
map[related] = value
|
41
82
|
next
|
42
83
|
end
|
43
84
|
|
44
85
|
if attr.is_a?(Hash)
|
45
86
|
attr.each do |related, argv|
|
46
|
-
|
87
|
+
v = record.send(related)
|
88
|
+
value = v.respond_to?(:to_dao) ? v.to_dao(*argv) : v
|
47
89
|
map[related] = value
|
48
90
|
end
|
49
91
|
next
|
@@ -76,8 +118,8 @@ if defined?(ActiveRecord)
|
|
76
118
|
model = record.class
|
77
119
|
model.record_to_dao(record, *args)
|
78
120
|
end
|
79
|
-
alias_method('to_h', 'to_dao')
|
80
|
-
alias_method('to_map', 'to_dao') ### HACK
|
121
|
+
### alias_method('to_h', 'to_dao')
|
122
|
+
### alias_method('to_map', 'to_dao') ### HACK
|
81
123
|
end
|
82
124
|
end
|
83
125
|
|
data/lib/dao/api/interfaces.rb
CHANGED
@@ -26,6 +26,8 @@ module Dao
|
|
26
26
|
interfaces[path] = interface
|
27
27
|
end
|
28
28
|
|
29
|
+
alias_method('call', 'interface')
|
30
|
+
|
29
31
|
def description(string)
|
30
32
|
doc(:description => Dao.unindent(string))
|
31
33
|
end
|
@@ -55,13 +57,19 @@ module Dao
|
|
55
57
|
end
|
56
58
|
end
|
57
59
|
|
58
|
-
def call(path = '/index', params = {})
|
60
|
+
def call(path = '/index', params = {}, options = {})
|
59
61
|
api = self
|
60
62
|
path = Path.new(path)
|
61
63
|
interface = interfaces[path]
|
62
|
-
raise(NameError, "NO SUCH INTERFACE: #{ path }") unless interface
|
63
64
|
|
64
|
-
|
65
|
+
unless interface
|
66
|
+
return index if path == '/index'
|
67
|
+
raise(NameError, "NO SUCH INTERFACE: #{ path }")
|
68
|
+
end
|
69
|
+
|
70
|
+
options = Map.options(options || {})
|
71
|
+
|
72
|
+
params = Dao.parse(path, params, options)
|
65
73
|
|
66
74
|
context = Context.new(
|
67
75
|
:api => api,
|
@@ -77,7 +85,9 @@ module Dao
|
|
77
85
|
end
|
78
86
|
|
79
87
|
def index
|
80
|
-
|
88
|
+
result = Result.new('/index')
|
89
|
+
result.data.update(self.class.index)
|
90
|
+
result
|
81
91
|
end
|
82
92
|
|
83
93
|
def interfaces
|
@@ -122,6 +132,11 @@ module Dao
|
|
122
132
|
result.status(*args, &block)
|
123
133
|
end
|
124
134
|
|
135
|
+
def status!(*args, &block)
|
136
|
+
status(*args, &block)
|
137
|
+
return!
|
138
|
+
end
|
139
|
+
|
125
140
|
def data(*args)
|
126
141
|
if args.empty?
|
127
142
|
result.data
|
data/lib/dao/data.rb
CHANGED
@@ -5,61 +5,11 @@ module Dao
|
|
5
5
|
|
6
6
|
def update(*args, &block)
|
7
7
|
if args.size==1 and args.first.respond_to?(:to_dao)
|
8
|
-
|
8
|
+
to_dao = args.first.to_dao
|
9
|
+
update(to_dao)
|
10
|
+
return(to_dao)
|
9
11
|
end
|
10
12
|
super
|
11
13
|
end
|
12
14
|
end
|
13
15
|
end
|
14
|
-
|
15
|
-
|
16
|
-
=begin
|
17
|
-
%w( to_dao as_dao ).each do |method|
|
18
|
-
module_eval <<-__, __FILE__, __LINE__
|
19
|
-
def #{ method }(object, *args, &block)
|
20
|
-
case object
|
21
|
-
when Array
|
22
|
-
object.map{|element| Data.#{ method }(element)}
|
23
|
-
|
24
|
-
else
|
25
|
-
if object.respond_to?(:#{ method })
|
26
|
-
object.send(:#{ method }, *args, &block)
|
27
|
-
else
|
28
|
-
object
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
__
|
33
|
-
end
|
34
|
-
=end
|
35
|
-
|
36
|
-
=begin
|
37
|
-
IdKeys =
|
38
|
-
%w( id uuid guid ).map{|key| [key, key.to_sym, "_#{ key }", "_#{ key }".to_sym]}.flatten
|
39
|
-
|
40
|
-
def id
|
41
|
-
IdKeys.each{|key| return self[key] if has_key?(key)}
|
42
|
-
return nil
|
43
|
-
end
|
44
|
-
|
45
|
-
def has_id?
|
46
|
-
IdKeys.each{|key| return true if has_key?(key)}
|
47
|
-
return false
|
48
|
-
end
|
49
|
-
|
50
|
-
def new?
|
51
|
-
!has_id?
|
52
|
-
end
|
53
|
-
|
54
|
-
def new_record?
|
55
|
-
!has_id?
|
56
|
-
end
|
57
|
-
|
58
|
-
def model_name
|
59
|
-
path.to_s
|
60
|
-
end
|
61
|
-
|
62
|
-
def slug
|
63
|
-
Slug.for(path)
|
64
|
-
end
|
65
|
-
=end
|
data/lib/dao/errors.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Dao
|
2
2
|
class Errors < ::Map
|
3
3
|
include Tagz.globally
|
4
|
+
|
4
5
|
class << Errors
|
5
6
|
include Tagz.globally
|
6
7
|
end
|
@@ -21,6 +22,10 @@ module Dao
|
|
21
22
|
@sticky ||= nil
|
22
23
|
!!@sticky
|
23
24
|
end
|
25
|
+
|
26
|
+
def to_s
|
27
|
+
self
|
28
|
+
end
|
24
29
|
end
|
25
30
|
|
26
31
|
class << Errors
|
@@ -67,8 +72,12 @@ module Dao
|
|
67
72
|
else
|
68
73
|
errors[keys] = Message.new(message, :sticky => sticky)
|
69
74
|
end
|
75
|
+
else
|
76
|
+
raise(ArgumentError, 'no message!')
|
70
77
|
end
|
71
78
|
|
79
|
+
message = Message.new(message) unless message.is_a?(Message)
|
80
|
+
|
72
81
|
result = []
|
73
82
|
|
74
83
|
errors.each do |keys, message|
|
@@ -84,7 +93,15 @@ module Dao
|
|
84
93
|
|
85
94
|
result
|
86
95
|
end
|
87
|
-
alias_method
|
96
|
+
alias_method('add_to_base', 'add')
|
97
|
+
|
98
|
+
def add!(*args)
|
99
|
+
options = Dao.map_for(args.last.is_a?(Hash) ? args.pop : {})
|
100
|
+
options[:sticky] = true
|
101
|
+
args.push(options)
|
102
|
+
add(*args)
|
103
|
+
end
|
104
|
+
alias_method('add_to_base!', 'add!')
|
88
105
|
|
89
106
|
def clone
|
90
107
|
clone = Errors.new
|
@@ -96,15 +113,6 @@ module Dao
|
|
96
113
|
clone
|
97
114
|
end
|
98
115
|
|
99
|
-
def add!(*args)
|
100
|
-
options = Dao.map_for(args.last.is_a?(Hash) ? args.pop : {})
|
101
|
-
options[:sticky] = true
|
102
|
-
args.push(options)
|
103
|
-
add(*args)
|
104
|
-
end
|
105
|
-
alias_method 'add_to_base!', 'add!'
|
106
|
-
|
107
|
-
alias_method 'clear!', 'clear' unless instance_methods.include?('clear!')
|
108
116
|
|
109
117
|
def update(other, options = {})
|
110
118
|
options = Dao.map_for(options)
|
@@ -121,6 +129,7 @@ module Dao
|
|
121
129
|
end
|
122
130
|
end
|
123
131
|
|
132
|
+
alias_method('clear!', 'clear') unless instance_methods.include?('clear!')
|
124
133
|
def clear
|
125
134
|
keep = []
|
126
135
|
depth_first_each do |keys, message|
|
@@ -136,19 +145,19 @@ module Dao
|
|
136
145
|
def invalid?(*keys)
|
137
146
|
has?(keys) and !get(keys).nil?
|
138
147
|
end
|
148
|
+
alias_method('on?', 'invalid?')
|
139
149
|
|
140
|
-
|
141
|
-
|
142
|
-
|
150
|
+
def on(*args, &block)
|
151
|
+
get(*args, &block)
|
152
|
+
end
|
143
153
|
|
144
154
|
def size
|
145
155
|
size = 0
|
146
156
|
depth_first_each{ size += 1 }
|
147
157
|
size
|
148
158
|
end
|
149
|
-
|
150
|
-
alias_method
|
151
|
-
alias_method 'length', 'size'
|
159
|
+
alias_method('count', 'size')
|
160
|
+
alias_method('length', 'size')
|
152
161
|
|
153
162
|
def full_messages
|
154
163
|
global_messages = []
|
@@ -173,7 +182,6 @@ module Dao
|
|
173
182
|
depth_first_each do |keys, message|
|
174
183
|
index = keys.pop
|
175
184
|
message = message.to_s.strip
|
176
|
-
next if message.empty?
|
177
185
|
yield(keys, message)
|
178
186
|
end
|
179
187
|
end
|
@@ -181,8 +189,7 @@ module Dao
|
|
181
189
|
def each_full_message
|
182
190
|
full_messages.each{|msg| yield msg}
|
183
191
|
end
|
184
|
-
|
185
|
-
alias_method 'each_full', 'each_full_message'
|
192
|
+
alias_method('each_full', 'each_full_message')
|
186
193
|
|
187
194
|
def messages
|
188
195
|
messages =
|
data/lib/dao/exceptions.rb
CHANGED
@@ -1,2 +1,24 @@
|
|
1
|
-
|
1
|
+
module Dao
|
2
|
+
class Dao::Error < ::StandardError
|
3
|
+
end
|
4
|
+
|
5
|
+
class Dao::Error::Result < Error
|
6
|
+
attr_accessor :result
|
7
|
+
|
8
|
+
def self.for(result, *args, &block)
|
9
|
+
error = new(*args, &block)
|
10
|
+
error.result = result
|
11
|
+
error
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class Dao::Error::Status < Error
|
16
|
+
attr_accessor :status
|
17
|
+
|
18
|
+
def self.for(status, *args, &block)
|
19
|
+
error = new(*args, &block)
|
20
|
+
error.status = status
|
21
|
+
error
|
22
|
+
end
|
23
|
+
end
|
2
24
|
end
|