dao 3.3.0 → 4.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +7 -0
- data/Rakefile +36 -17
- data/b.rb +38 -0
- data/dao.gemspec +41 -13
- data/lib/dao.rb +44 -13
- data/lib/dao/api.rb +1 -1
- data/lib/dao/api/context.rb +35 -45
- data/lib/dao/api/endpoints.rb +225 -91
- data/lib/dao/conducer.rb +437 -0
- data/lib/dao/conducer/attributes.rb +21 -0
- data/lib/dao/conducer/crud.rb +70 -0
- data/lib/dao/current.rb +66 -0
- data/lib/dao/db.rb +44 -5
- data/lib/dao/endpoint.rb +13 -1
- data/lib/dao/errors.rb +74 -59
- data/lib/dao/exceptions.rb +1 -2
- data/lib/dao/extractor.rb +68 -0
- data/lib/dao/form.rb +139 -46
- data/lib/dao/image_cache.rb +193 -0
- data/lib/dao/instance_exec.rb +1 -1
- data/lib/dao/name.rb +7 -0
- data/lib/dao/params.rb +16 -66
- data/lib/dao/rack.rb +3 -0
- data/lib/dao/rack/middleware.rb +5 -0
- data/lib/dao/rack/middleware/params_parser.rb +24 -0
- data/lib/dao/rails.rb +22 -5
- data/lib/dao/rails/lib/generators/dao/USAGE +2 -6
- data/lib/dao/rails/lib/generators/dao/dao_generator.rb +52 -7
- data/lib/dao/rails/lib/generators/dao/templates/api.rb +23 -7
- data/lib/dao/rails/lib/generators/dao/templates/api_controller.rb +24 -7
- data/lib/dao/rails/lib/generators/dao/templates/conducer.rb +64 -0
- data/lib/dao/rails/lib/generators/dao/templates/conducer_controller.rb +79 -0
- data/lib/dao/rails/lib/generators/dao/templates/dao.js +13 -6
- data/lib/dao/rails/lib/generators/dao/templates/dao_helper.rb +75 -11
- data/lib/dao/result.rb +1 -26
- data/lib/dao/slug.rb +37 -8
- data/lib/dao/status.rb +4 -0
- data/lib/dao/support.rb +155 -0
- data/lib/dao/validations.rb +48 -157
- data/lib/dao/validations/callback.rb +30 -0
- data/lib/dao/validations/common.rb +322 -320
- data/lib/dao/validations/validator.rb +219 -0
- data/test/active_model_conducer_lint_test.rb +19 -0
- data/test/api_test.rb +261 -0
- data/test/conducer_test.rb +205 -0
- data/test/db.yml +9 -0
- data/test/form_test.rb +42 -0
- data/test/support_test.rb +52 -0
- data/test/testing.rb +145 -24
- data/test/validations_test.rb +156 -0
- metadata +138 -21
- data/TODO +0 -33
- data/a.rb +0 -80
- data/db/dao.yml +0 -5
- data/lib/dao/api/interfaces.rb +0 -306
- data/lib/dao/interface.rb +0 -28
- data/lib/dao/presenter.rb +0 -129
- data/lib/dao/rails/lib/generators/dao/api_generator.rb +0 -3
- data/lib/dao/validations/base.rb +0 -68
- data/test/dao_test.rb +0 -506
data/README
CHANGED
@@ -114,3 +114,10 @@ INSTALL
|
|
114
114
|
vim -o app/api.rb app/controllers/api_controller.rb
|
115
115
|
curl --silent http://0.0.0.0:3000/api
|
116
116
|
curl --silent http://0.0.0.0:3000/api/ping
|
117
|
+
|
118
|
+
HISTORY
|
119
|
+
4.0.0
|
120
|
+
- dao depends has tied itself to rails, for better or worse...
|
121
|
+
- drop custom form encoding. just use a rack-like approach.
|
122
|
+
- dao form parameter encoding has changed slightly to 'dao[/api/path][x,y,z]=42'
|
123
|
+
- dao form paramters are now preparsed in a before filter
|
data/Rakefile
CHANGED
@@ -60,7 +60,7 @@ end
|
|
60
60
|
task :gemspec do
|
61
61
|
ignore_extensions = ['git', 'svn', 'tmp', /sw./, 'bak', 'gem']
|
62
62
|
ignore_directories = ['pkg']
|
63
|
-
ignore_files = ['test/log']
|
63
|
+
ignore_files = ['test/log', 'a.rb'] + Dir['db/*'] + %w'db'
|
64
64
|
|
65
65
|
shiteless =
|
66
66
|
lambda do |list|
|
@@ -87,7 +87,7 @@ task :gemspec do
|
|
87
87
|
files = shiteless[Dir::glob("**/**")]
|
88
88
|
executables = shiteless[Dir::glob("bin/*")].map{|exe| File.basename(exe)}
|
89
89
|
#has_rdoc = true #File.exist?('doc')
|
90
|
-
test_files = "test/#{ lib }.rb"
|
90
|
+
test_files = test(?e, "test/#{ lib }.rb") ? "test/#{ lib }.rb" : nil
|
91
91
|
summary = object.respond_to?(:summary) ? object.summary : "summary: #{ lib } kicks the ass"
|
92
92
|
description = object.respond_to?(:description) ? object.description : "description: #{ lib } kicks the ass"
|
93
93
|
|
@@ -100,38 +100,51 @@ task :gemspec do
|
|
100
100
|
end
|
101
101
|
extensions = [extensions].flatten.compact
|
102
102
|
|
103
|
+
# TODO
|
104
|
+
if This.dependencies.nil?
|
105
|
+
dependencies = []
|
106
|
+
else
|
107
|
+
case This.dependencies
|
108
|
+
when Hash
|
109
|
+
dependencies = This.dependencies.values
|
110
|
+
when Array
|
111
|
+
dependencies = This.dependencies
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
103
115
|
template =
|
104
116
|
if test(?e, 'gemspec.erb')
|
105
117
|
Template{ IO.read('gemspec.erb') }
|
106
118
|
else
|
107
119
|
Template {
|
108
120
|
<<-__
|
109
|
-
##
|
121
|
+
## <%= lib %>.gemspec
|
110
122
|
#
|
111
123
|
|
112
124
|
Gem::Specification::new do |spec|
|
113
|
-
spec.name =
|
114
|
-
spec.version =
|
125
|
+
spec.name = <%= lib.inspect %>
|
126
|
+
spec.version = <%= version.inspect %>
|
115
127
|
spec.platform = Gem::Platform::RUBY
|
116
|
-
spec.summary =
|
117
|
-
spec.description =
|
128
|
+
spec.summary = <%= lib.inspect %>
|
129
|
+
spec.description = <%= description.inspect %>
|
118
130
|
|
119
|
-
spec.files =\n
|
120
|
-
spec.executables =
|
131
|
+
spec.files =\n<%= files.sort.pretty_inspect %>
|
132
|
+
spec.executables = <%= executables.inspect %>
|
121
133
|
|
122
134
|
spec.require_path = "lib"
|
123
135
|
|
124
|
-
spec.test_files =
|
136
|
+
spec.test_files = <%= test_files.inspect %>
|
125
137
|
|
126
|
-
|
127
|
-
|
138
|
+
<% dependencies.each do |lib_version| %>
|
139
|
+
spec.add_dependency(*<%= Array(lib_version).flatten.inspect %>)
|
140
|
+
<% end %>
|
128
141
|
|
129
|
-
spec.extensions.push(
|
142
|
+
spec.extensions.push(*<%= extensions.inspect %>)
|
130
143
|
|
131
|
-
spec.rubyforge_project =
|
132
|
-
spec.author =
|
133
|
-
spec.email =
|
134
|
-
spec.homepage =
|
144
|
+
spec.rubyforge_project = <%= This.rubyforge_project.inspect %>
|
145
|
+
spec.author = <%= This.author.inspect %>
|
146
|
+
spec.email = <%= This.email.inspect %>
|
147
|
+
spec.homepage = <%= This.homepage.inspect %>
|
135
148
|
end
|
136
149
|
__
|
137
150
|
}
|
@@ -267,6 +280,12 @@ BEGIN {
|
|
267
280
|
end
|
268
281
|
This.version = version
|
269
282
|
|
283
|
+
# see if dependencies are export by the module
|
284
|
+
#
|
285
|
+
if This.object.respond_to?(:dependencies)
|
286
|
+
This.dependencies = This.object.dependencies
|
287
|
+
end
|
288
|
+
|
270
289
|
# we need to know the name of the lib an it's version
|
271
290
|
#
|
272
291
|
abort('no lib') unless This.lib
|
data/b.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
|
2
|
+
require 'dao'
|
3
|
+
|
4
|
+
|
5
|
+
|
6
|
+
class C < ::Map
|
7
|
+
include Dao::Validations
|
8
|
+
validates_presence_of :foo
|
9
|
+
end
|
10
|
+
|
11
|
+
c = C.new
|
12
|
+
|
13
|
+
p c.valid?
|
14
|
+
p c.errors
|
15
|
+
|
16
|
+
c.update(:foo => 42)
|
17
|
+
|
18
|
+
p c.valid?
|
19
|
+
p c.errors
|
20
|
+
|
21
|
+
#p 'c.validator.attributes' => c.validator.attributes
|
22
|
+
#p 'c' => c
|
23
|
+
|
24
|
+
__END__
|
25
|
+
|
26
|
+
p c.valid?
|
27
|
+
|
28
|
+
|
29
|
+
p c
|
30
|
+
|
31
|
+
p c.valid?
|
32
|
+
|
33
|
+
#c.validator
|
34
|
+
#p c.validator.object
|
35
|
+
#p c.valid?
|
36
|
+
#p c.errors
|
37
|
+
#p c.status
|
38
|
+
|
data/dao.gemspec
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
|
4
4
|
Gem::Specification::new do |spec|
|
5
5
|
spec.name = "dao"
|
6
|
-
spec.version = "
|
6
|
+
spec.version = "4.2.1"
|
7
7
|
spec.platform = Gem::Platform::RUBY
|
8
8
|
spec.summary = "dao"
|
9
9
|
spec.description = "description: dao kicks the ass"
|
@@ -11,11 +11,9 @@ Gem::Specification::new do |spec|
|
|
11
11
|
spec.files =
|
12
12
|
["README",
|
13
13
|
"Rakefile",
|
14
|
-
"
|
15
|
-
"a.rb",
|
14
|
+
"b.rb",
|
16
15
|
"dao.gemspec",
|
17
16
|
"db",
|
18
|
-
"db/dao.yml",
|
19
17
|
"lib",
|
20
18
|
"lib/dao",
|
21
19
|
"lib/dao.rb",
|
@@ -26,35 +24,46 @@ Gem::Specification::new do |spec|
|
|
26
24
|
"lib/dao/api/dsl.rb",
|
27
25
|
"lib/dao/api/endpoints.rb",
|
28
26
|
"lib/dao/api/initializers.rb",
|
29
|
-
"lib/dao/api/interfaces.rb",
|
30
27
|
"lib/dao/api/modes.rb",
|
31
28
|
"lib/dao/api/routes.rb",
|
32
29
|
"lib/dao/blankslate.rb",
|
30
|
+
"lib/dao/conducer",
|
31
|
+
"lib/dao/conducer.rb",
|
32
|
+
"lib/dao/conducer/attributes.rb",
|
33
|
+
"lib/dao/conducer/crud.rb",
|
34
|
+
"lib/dao/current.rb",
|
33
35
|
"lib/dao/data.rb",
|
34
36
|
"lib/dao/db.rb",
|
35
37
|
"lib/dao/endpoint.rb",
|
36
38
|
"lib/dao/engine.rb",
|
37
39
|
"lib/dao/errors.rb",
|
38
40
|
"lib/dao/exceptions.rb",
|
41
|
+
"lib/dao/extractor.rb",
|
39
42
|
"lib/dao/form.rb",
|
43
|
+
"lib/dao/image_cache.rb",
|
40
44
|
"lib/dao/instance_exec.rb",
|
41
|
-
"lib/dao/interface.rb",
|
42
45
|
"lib/dao/mode.rb",
|
43
46
|
"lib/dao/mongo_mapper.rb",
|
47
|
+
"lib/dao/name.rb",
|
44
48
|
"lib/dao/params.rb",
|
45
49
|
"lib/dao/path.rb",
|
46
|
-
"lib/dao/
|
50
|
+
"lib/dao/rack",
|
51
|
+
"lib/dao/rack.rb",
|
52
|
+
"lib/dao/rack/middleware",
|
53
|
+
"lib/dao/rack/middleware.rb",
|
54
|
+
"lib/dao/rack/middleware/params_parser.rb",
|
47
55
|
"lib/dao/rails",
|
48
56
|
"lib/dao/rails.rb",
|
49
57
|
"lib/dao/rails/lib",
|
50
58
|
"lib/dao/rails/lib/generators",
|
51
59
|
"lib/dao/rails/lib/generators/dao",
|
52
60
|
"lib/dao/rails/lib/generators/dao/USAGE",
|
53
|
-
"lib/dao/rails/lib/generators/dao/api_generator.rb",
|
54
61
|
"lib/dao/rails/lib/generators/dao/dao_generator.rb",
|
55
62
|
"lib/dao/rails/lib/generators/dao/templates",
|
56
63
|
"lib/dao/rails/lib/generators/dao/templates/api.rb",
|
57
64
|
"lib/dao/rails/lib/generators/dao/templates/api_controller.rb",
|
65
|
+
"lib/dao/rails/lib/generators/dao/templates/conducer.rb",
|
66
|
+
"lib/dao/rails/lib/generators/dao/templates/conducer_controller.rb",
|
58
67
|
"lib/dao/rails/lib/generators/dao/templates/dao.css",
|
59
68
|
"lib/dao/rails/lib/generators/dao/templates/dao.js",
|
60
69
|
"lib/dao/rails/lib/generators/dao/templates/dao_helper.rb",
|
@@ -66,14 +75,20 @@ Gem::Specification::new do |spec|
|
|
66
75
|
"lib/dao/support.rb",
|
67
76
|
"lib/dao/validations",
|
68
77
|
"lib/dao/validations.rb",
|
69
|
-
"lib/dao/validations/
|
78
|
+
"lib/dao/validations/callback.rb",
|
70
79
|
"lib/dao/validations/common.rb",
|
80
|
+
"lib/dao/validations/validator.rb",
|
71
81
|
"test",
|
72
|
-
"test/
|
82
|
+
"test/active_model_conducer_lint_test.rb",
|
83
|
+
"test/api_test.rb",
|
84
|
+
"test/conducer_test.rb",
|
85
|
+
"test/db.yml",
|
86
|
+
"test/form_test.rb",
|
73
87
|
"test/helper.rb",
|
74
88
|
"test/leak.rb",
|
89
|
+
"test/support_test.rb",
|
75
90
|
"test/testing.rb",
|
76
|
-
"test/
|
91
|
+
"test/validations_test.rb"]
|
77
92
|
|
78
93
|
spec.executables = []
|
79
94
|
|
@@ -81,8 +96,21 @@ Gem::Specification::new do |spec|
|
|
81
96
|
|
82
97
|
spec.test_files = nil
|
83
98
|
|
84
|
-
|
85
|
-
|
99
|
+
|
100
|
+
spec.add_dependency(*["rails", "~> 3.0"])
|
101
|
+
|
102
|
+
spec.add_dependency(*["uuidtools", "~> 2.1"])
|
103
|
+
|
104
|
+
spec.add_dependency(*["tagz", "~> 9.0"])
|
105
|
+
|
106
|
+
spec.add_dependency(*["fattr", "~> 2.2"])
|
107
|
+
|
108
|
+
spec.add_dependency(*["map", "~> 4.4"])
|
109
|
+
|
110
|
+
spec.add_dependency(*["unidecode", "~> 1.0"])
|
111
|
+
|
112
|
+
spec.add_dependency(*["yajl-ruby", "~> 0.8"])
|
113
|
+
|
86
114
|
|
87
115
|
spec.extensions.push(*[])
|
88
116
|
|
data/lib/dao.rb
CHANGED
@@ -2,15 +2,11 @@
|
|
2
2
|
#
|
3
3
|
require 'enumerator'
|
4
4
|
require 'set'
|
5
|
-
#require 'fileutils'
|
6
|
-
#require 'pathname'
|
7
|
-
#require 'yaml'
|
8
|
-
#require 'yaml/store'
|
9
5
|
|
10
6
|
# dao libs
|
11
7
|
#
|
12
8
|
module Dao
|
13
|
-
Version = '
|
9
|
+
Version = '4.2.1' unless defined?(Version)
|
14
10
|
|
15
11
|
def version
|
16
12
|
Dao::Version
|
@@ -18,9 +14,13 @@
|
|
18
14
|
|
19
15
|
def dependencies
|
20
16
|
{
|
21
|
-
'
|
22
|
-
'
|
23
|
-
'
|
17
|
+
'rails' => [ 'rails' , '~> 3.0' ],
|
18
|
+
'map' => [ 'map' , '~> 4.4' ],
|
19
|
+
'fattr' => [ 'fattr' , '~> 2.2' ],
|
20
|
+
'tagz' => [ 'tagz' , '~> 9.0' ],
|
21
|
+
'yajl' => [ 'yajl-ruby' , '~> 0.8' ],
|
22
|
+
'unidecode' => [ 'unidecode' , '~> 1.0' ],
|
23
|
+
'uuidtools' => [ 'uuidtools' , '~> 2.1' ]
|
24
24
|
}
|
25
25
|
end
|
26
26
|
|
@@ -61,16 +61,34 @@
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
+
#active_record
|
65
|
+
#action_mailer
|
66
|
+
#rails/test_unit
|
67
|
+
%w[
|
68
|
+
action_controller
|
69
|
+
active_resource
|
70
|
+
active_support
|
71
|
+
].each do |framework|
|
72
|
+
begin
|
73
|
+
require "#{ framework }/railtie"
|
74
|
+
rescue LoadError
|
75
|
+
end
|
76
|
+
end
|
77
|
+
#require 'rails/all'
|
78
|
+
|
79
|
+
|
64
80
|
require 'yajl/json_gem'
|
65
81
|
|
66
82
|
Dao.load %w[
|
67
83
|
blankslate.rb
|
68
84
|
instance_exec.rb
|
85
|
+
extractor.rb
|
69
86
|
exceptions.rb
|
70
87
|
support.rb
|
71
88
|
slug.rb
|
72
89
|
stdext.rb
|
73
90
|
|
91
|
+
name.rb
|
74
92
|
status.rb
|
75
93
|
errors.rb
|
76
94
|
form.rb
|
@@ -79,20 +97,33 @@
|
|
79
97
|
result.rb
|
80
98
|
params.rb
|
81
99
|
|
100
|
+
current.rb
|
101
|
+
|
82
102
|
mode.rb
|
83
103
|
route.rb
|
84
104
|
path.rb
|
85
|
-
|
105
|
+
endpoint.rb
|
86
106
|
api.rb
|
87
107
|
|
108
|
+
db.rb
|
88
109
|
|
89
110
|
rails.rb
|
90
111
|
active_record.rb
|
91
112
|
mongo_mapper.rb
|
92
|
-
]
|
93
113
|
|
94
|
-
|
114
|
+
conducer.rb
|
115
|
+
image_cache.rb
|
116
|
+
]
|
95
117
|
|
96
|
-
|
97
|
-
|
118
|
+
# protect against rails' too clever reloading
|
119
|
+
#
|
120
|
+
=begin
|
121
|
+
if defined?(Rails)
|
122
|
+
unless defined?(unloadable)
|
123
|
+
require 'active_support'
|
124
|
+
require 'active_support/dependencies'
|
125
|
+
end
|
126
|
+
unloadable(Dao)
|
98
127
|
end
|
128
|
+
BEGIN{ Object.send(:remove_const, :Dao) if defined?(Dao) }
|
129
|
+
=end
|
data/lib/dao/api.rb
CHANGED
data/lib/dao/api/context.rb
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
module Dao
|
2
2
|
class Context
|
3
|
-
Attrs = %w(
|
3
|
+
Attrs = %w(
|
4
|
+
api path route endpoint
|
5
|
+
params validator errors status form
|
6
|
+
result
|
7
|
+
data
|
8
|
+
args
|
9
|
+
)
|
4
10
|
|
5
11
|
Attrs.each{|a| attr_accessor(a)}
|
6
12
|
|
@@ -8,61 +14,45 @@ module Dao
|
|
8
14
|
Attrs
|
9
15
|
end
|
10
16
|
|
11
|
-
def Context.for(
|
12
|
-
|
13
|
-
|
14
|
-
options = Dao.options_for!(args)
|
15
|
-
|
16
|
-
parsed_params = Dao.parse(path, params, options)
|
17
|
+
def Context.for(*args, &block)
|
18
|
+
new(*args, &block)
|
19
|
+
end
|
17
20
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
+
def initialize(api, path, route, endpoint, params, *args)
|
22
|
+
@api = api
|
23
|
+
@path = path
|
24
|
+
@route = route
|
25
|
+
@endpoint = endpoint
|
21
26
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
27
|
+
@params = Params.new
|
28
|
+
@params.update(params)
|
29
|
+
@params.path = @path
|
30
|
+
@params.route = @route
|
31
|
+
@form = @params.form
|
28
32
|
|
29
|
-
|
30
|
-
|
31
|
-
context = new
|
32
|
-
context.api = api
|
33
|
-
context.interface = interface
|
34
|
-
context.route = route
|
35
|
-
context.path = path
|
36
|
-
context.args = args
|
37
|
-
context.status = Status.default
|
38
|
-
context.errors = Errors.new
|
33
|
+
@validator = Validator.new(@params)
|
34
|
+
@validator.validations_search_path.unshift(@api.class)
|
39
35
|
|
40
|
-
|
41
|
-
context.data = result.data
|
36
|
+
@validations = @validator.validations
|
42
37
|
|
43
|
-
|
44
|
-
|
45
|
-
|
38
|
+
@params.validator = @validator
|
39
|
+
@errors = @validator.errors
|
40
|
+
@status = @validator.status
|
46
41
|
|
47
|
-
|
48
|
-
|
49
|
-
result.route =
|
50
|
-
result.
|
51
|
-
result.
|
52
|
-
result.errors =
|
42
|
+
@result = Result.new
|
43
|
+
@result.path = @path
|
44
|
+
@result.route = @route
|
45
|
+
@result.mode = @api.mode
|
46
|
+
@result.params = @params
|
47
|
+
@result.errors = @params.errors
|
53
48
|
|
54
|
-
|
55
|
-
params.path = context.path
|
56
|
-
params.status = context.status
|
57
|
-
params.errors = context.errors
|
49
|
+
@data = @result.data
|
58
50
|
|
59
|
-
|
51
|
+
@args = @endpoint.arity < 1 ? [@params, @result] : [@params, @result].slice(0, @endpoint.arity)
|
60
52
|
end
|
61
53
|
|
62
|
-
include InstanceExec
|
63
|
-
|
64
54
|
def call
|
65
|
-
api.instance_exec(
|
55
|
+
@api.instance_exec(*@args, &@endpoint)
|
66
56
|
end
|
67
57
|
end
|
68
58
|
end
|