dao 2.2.3 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +68 -113
- data/TODO +3 -9
- data/a.rb +25 -0
- data/dao.gemspec +70 -14
- data/lib/dao.rb +8 -8
- data/lib/dao/api.rb +1 -0
- data/lib/dao/api/context.rb +48 -23
- data/lib/dao/api/dsl.rb +1 -1
- data/lib/dao/api/interfaces.rb +149 -117
- data/lib/dao/api/modes.rb +24 -23
- data/lib/dao/api/routes.rb +9 -0
- data/lib/dao/data.rb +9 -2
- data/lib/dao/errors.rb +15 -11
- data/lib/dao/form.rb +46 -37
- data/lib/dao/interface.rb +1 -1
- data/lib/dao/mode.rb +45 -20
- data/lib/dao/params.rb +35 -53
- data/lib/dao/path.rb +6 -9
- data/lib/dao/rails/lib/generators/dao/templates/api.rb +1 -1
- data/lib/dao/rails/lib/generators/dao/templates/dao_helper.rb +16 -0
- data/lib/dao/result.rb +26 -133
- data/lib/dao/route.rb +87 -0
- data/lib/dao/status.rb +96 -94
- data/lib/dao/support.rb +5 -3
- data/lib/dao/validations.rb +46 -442
- data/lib/dao/validations/base.rb +68 -0
- data/lib/dao/validations/common.rb +463 -0
- data/test/dao_test.rb +214 -33
- metadata +20 -112
- data/lib/dao/rails/app/api.rb +0 -55
- data/lib/dao/rails/app/controllers/api_controller.rb +0 -99
- data/sample/rails_app/Gemfile +0 -33
- data/sample/rails_app/Gemfile.lock +0 -88
- data/sample/rails_app/README +0 -1
- data/sample/rails_app/Rakefile +0 -7
- data/sample/rails_app/app/api.rb +0 -55
- data/sample/rails_app/app/controllers/api_controller.rb +0 -99
- data/sample/rails_app/app/controllers/application_controller.rb +0 -3
- data/sample/rails_app/app/helpers/application_helper.rb +0 -2
- data/sample/rails_app/app/views/layouts/application.html.erb +0 -14
- data/sample/rails_app/config.ru +0 -4
- data/sample/rails_app/config/application.rb +0 -51
- data/sample/rails_app/config/boot.rb +0 -13
- data/sample/rails_app/config/database.yml +0 -22
- data/sample/rails_app/config/environment.rb +0 -5
- data/sample/rails_app/config/environments/development.rb +0 -26
- data/sample/rails_app/config/environments/production.rb +0 -49
- data/sample/rails_app/config/environments/test.rb +0 -35
- data/sample/rails_app/config/initializers/backtrace_silencers.rb +0 -7
- data/sample/rails_app/config/initializers/inflections.rb +0 -10
- data/sample/rails_app/config/initializers/mime_types.rb +0 -5
- data/sample/rails_app/config/initializers/secret_token.rb +0 -7
- data/sample/rails_app/config/initializers/session_store.rb +0 -8
- data/sample/rails_app/config/locales/en.yml +0 -5
- data/sample/rails_app/config/routes.rb +0 -62
- data/sample/rails_app/db/development.sqlite3 +0 -0
- data/sample/rails_app/db/seeds.rb +0 -7
- data/sample/rails_app/doc/README_FOR_APP +0 -2
- data/sample/rails_app/log/development.log +0 -27
- data/sample/rails_app/log/production.log +0 -0
- data/sample/rails_app/log/server.log +0 -0
- data/sample/rails_app/log/test.log +0 -0
- data/sample/rails_app/pubic/javascripts/dao.js +0 -148
- data/sample/rails_app/public/404.html +0 -26
- data/sample/rails_app/public/422.html +0 -26
- data/sample/rails_app/public/500.html +0 -26
- data/sample/rails_app/public/favicon.ico +0 -0
- data/sample/rails_app/public/images/rails.png +0 -0
- data/sample/rails_app/public/index.html +0 -239
- data/sample/rails_app/public/javascripts/application.js +0 -2
- data/sample/rails_app/public/javascripts/controls.js +0 -965
- data/sample/rails_app/public/javascripts/dragdrop.js +0 -974
- data/sample/rails_app/public/javascripts/effects.js +0 -1123
- data/sample/rails_app/public/javascripts/prototype.js +0 -6001
- data/sample/rails_app/public/javascripts/rails.js +0 -175
- data/sample/rails_app/public/robots.txt +0 -5
- data/sample/rails_app/script/rails +0 -6
- data/sample/rails_app/test/performance/browsing_test.rb +0 -9
- data/sample/rails_app/test/test_helper.rb +0 -13
data/lib/dao/rails/app/api.rb
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
Api =
|
2
|
-
Dao.api do
|
3
|
-
|
4
|
-
description 'ping!'
|
5
|
-
interface('/ping'){
|
6
|
-
data.update :time => Time.now
|
7
|
-
}
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
## this is simply a suggest way to model your api. it is not required.
|
13
|
-
#
|
14
|
-
attr_accessor :effective_user
|
15
|
-
attr_accessor :real_user
|
16
|
-
|
17
|
-
def initialize(*args)
|
18
|
-
options = args.extract_options!.to_options!
|
19
|
-
effective_user = args.shift || options[:effective_user] || options[:user]
|
20
|
-
real_user = args.shift || options[:real_user] || effective_user
|
21
|
-
@effective_user = user_for(effective_user) if effective_user
|
22
|
-
@real_user = user_for(real_user) if real_user
|
23
|
-
@real_user ||= @effective_user
|
24
|
-
end
|
25
|
-
|
26
|
-
def user_for(arg)
|
27
|
-
User.find(arg)
|
28
|
-
end
|
29
|
-
|
30
|
-
alias_method('user', 'effective_user')
|
31
|
-
alias_method('user=', 'effective_user=')
|
32
|
-
|
33
|
-
def api
|
34
|
-
self
|
35
|
-
end
|
36
|
-
|
37
|
-
def logged_in?
|
38
|
-
@effective_user and @real_user
|
39
|
-
end
|
40
|
-
|
41
|
-
def user?
|
42
|
-
logged_in?
|
43
|
-
end
|
44
|
-
|
45
|
-
def current_user
|
46
|
-
effective_user
|
47
|
-
end
|
48
|
-
|
49
|
-
def current_user?
|
50
|
-
!!effective_user
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
|
55
|
-
unloadable(Api)
|
@@ -1,99 +0,0 @@
|
|
1
|
-
class APIController < ApplicationController
|
2
|
-
layout false
|
3
|
-
|
4
|
-
skip_before_filter true
|
5
|
-
skip_before_filter :verify_authenticity_token
|
6
|
-
|
7
|
-
before_filter :setup_api
|
8
|
-
|
9
|
-
### skip_before_filter :set_current_user if Rails.env.production?
|
10
|
-
|
11
|
-
##
|
12
|
-
# /api/foo/2/bar/4 -> api.call('/foo/2/bar/4')
|
13
|
-
#
|
14
|
-
def call
|
15
|
-
path = params[:path]
|
16
|
-
mode = params['mode'] || (request.get? ? 'read' : 'write')
|
17
|
-
|
18
|
-
result = api.mode(mode).call(path, params)
|
19
|
-
|
20
|
-
respond_with(result)
|
21
|
-
end
|
22
|
-
|
23
|
-
##
|
24
|
-
#
|
25
|
-
def index
|
26
|
-
json = json_for(api.index)
|
27
|
-
|
28
|
-
respond_to do |wants|
|
29
|
-
wants.json{ render(:json => json) }
|
30
|
-
wants.html{ render(:text => json, :content_type => 'text/plain') }
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
protected
|
35
|
-
|
36
|
-
def respond_with(result)
|
37
|
-
json = json_for(result)
|
38
|
-
|
39
|
-
respond_to do |wants|
|
40
|
-
wants.json{ render :json => json, :status => result.status.code }
|
41
|
-
wants.html{ render :text => json, :status => result.status.code, :content_type => 'text/plain' }
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
# if you don't have yajl-ruby and yajl/json_gem loaded your json will suck
|
46
|
-
#
|
47
|
-
def json_for(object)
|
48
|
-
if Rails.env.production?
|
49
|
-
::JSON.generate(object)
|
50
|
-
else
|
51
|
-
::JSON.pretty_generate(object, :max_nesting => 0)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def setup_api
|
56
|
-
email, password = http_basic_auth_info
|
57
|
-
|
58
|
-
if !email.blank? and !password.blank?
|
59
|
-
user = User.find_by_email(email)
|
60
|
-
if user.password == password
|
61
|
-
@api = Api.new(user)
|
62
|
-
else
|
63
|
-
render(:nothing => true, :status => :unauthorized)
|
64
|
-
return
|
65
|
-
end
|
66
|
-
else
|
67
|
-
if defined?(current_user)
|
68
|
-
if current_user
|
69
|
-
@api = Api.new(current_user)
|
70
|
-
else
|
71
|
-
render(:nothing => true, :status => :unauthorized)
|
72
|
-
end
|
73
|
-
else
|
74
|
-
@api = Api.new
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
def api
|
80
|
-
@api
|
81
|
-
end
|
82
|
-
|
83
|
-
def http_basic_auth
|
84
|
-
@http_basic_auth ||= (
|
85
|
-
request.env['HTTP_AUTHORIZATION'] ||
|
86
|
-
request.env['X-HTTP_AUTHORIZATION'] ||
|
87
|
-
request.env['X_HTTP_AUTHORIZATION'] ||
|
88
|
-
request.env['REDIRECT_X_HTTP_AUTHORIZATION'] ||
|
89
|
-
''
|
90
|
-
)
|
91
|
-
end
|
92
|
-
|
93
|
-
def http_basic_auth_info
|
94
|
-
username, password =
|
95
|
-
ActiveSupport::Base64.decode64(http_basic_auth.split.last.to_s).split(/:/, 2)
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
ApiController = APIController ### rails is a bitch - shut her up
|
data/sample/rails_app/Gemfile
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
source 'http://rubygems.org'
|
2
|
-
|
3
|
-
gem 'rails', '3.0.3'
|
4
|
-
|
5
|
-
# Bundle edge Rails instead:
|
6
|
-
# gem 'rails', :git => 'git://github.com/rails/rails.git'
|
7
|
-
|
8
|
-
gem 'sqlite3-ruby', :require => 'sqlite3'
|
9
|
-
gem 'dao', :path => File.expand_path('../..')
|
10
|
-
|
11
|
-
# Use unicorn as the web server
|
12
|
-
# gem 'unicorn'
|
13
|
-
|
14
|
-
# Deploy with Capistrano
|
15
|
-
# gem 'capistrano'
|
16
|
-
|
17
|
-
# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
|
18
|
-
# gem 'ruby-debug'
|
19
|
-
# gem 'ruby-debug19'
|
20
|
-
|
21
|
-
# Bundle the extra gems:
|
22
|
-
# gem 'bj'
|
23
|
-
# gem 'nokogiri'
|
24
|
-
# gem 'sqlite3-ruby', :require => 'sqlite3'
|
25
|
-
# gem 'aws-s3', :require => 'aws/s3'
|
26
|
-
|
27
|
-
# Bundle gems for the local environment. Make sure to
|
28
|
-
# put test-only gems in this group so their generators
|
29
|
-
# and rake tasks are available in development mode:
|
30
|
-
# group :development, :test do
|
31
|
-
# gem 'webrat'
|
32
|
-
# end
|
33
|
-
gem "yajl-ruby"
|
@@ -1,88 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: /Users/ahoward/src/git/dao
|
3
|
-
specs:
|
4
|
-
dao (2.0.0)
|
5
|
-
map
|
6
|
-
tagz
|
7
|
-
yajl-ruby
|
8
|
-
|
9
|
-
GEM
|
10
|
-
remote: http://rubygems.org/
|
11
|
-
specs:
|
12
|
-
abstract (1.0.0)
|
13
|
-
actionmailer (3.0.3)
|
14
|
-
actionpack (= 3.0.3)
|
15
|
-
mail (~> 2.2.9)
|
16
|
-
actionpack (3.0.3)
|
17
|
-
activemodel (= 3.0.3)
|
18
|
-
activesupport (= 3.0.3)
|
19
|
-
builder (~> 2.1.2)
|
20
|
-
erubis (~> 2.6.6)
|
21
|
-
i18n (~> 0.4)
|
22
|
-
rack (~> 1.2.1)
|
23
|
-
rack-mount (~> 0.6.13)
|
24
|
-
rack-test (~> 0.5.6)
|
25
|
-
tzinfo (~> 0.3.23)
|
26
|
-
activemodel (3.0.3)
|
27
|
-
activesupport (= 3.0.3)
|
28
|
-
builder (~> 2.1.2)
|
29
|
-
i18n (~> 0.4)
|
30
|
-
activerecord (3.0.3)
|
31
|
-
activemodel (= 3.0.3)
|
32
|
-
activesupport (= 3.0.3)
|
33
|
-
arel (~> 2.0.2)
|
34
|
-
tzinfo (~> 0.3.23)
|
35
|
-
activeresource (3.0.3)
|
36
|
-
activemodel (= 3.0.3)
|
37
|
-
activesupport (= 3.0.3)
|
38
|
-
activesupport (3.0.3)
|
39
|
-
arel (2.0.7)
|
40
|
-
builder (2.1.2)
|
41
|
-
erubis (2.6.6)
|
42
|
-
abstract (>= 1.0.0)
|
43
|
-
i18n (0.5.0)
|
44
|
-
mail (2.2.14)
|
45
|
-
activesupport (>= 2.3.6)
|
46
|
-
i18n (>= 0.4.0)
|
47
|
-
mime-types (~> 1.16)
|
48
|
-
treetop (~> 1.4.8)
|
49
|
-
map (2.2.2)
|
50
|
-
mime-types (1.16)
|
51
|
-
polyglot (0.3.1)
|
52
|
-
rack (1.2.1)
|
53
|
-
rack-mount (0.6.13)
|
54
|
-
rack (>= 1.0.0)
|
55
|
-
rack-test (0.5.7)
|
56
|
-
rack (>= 1.0)
|
57
|
-
rails (3.0.3)
|
58
|
-
actionmailer (= 3.0.3)
|
59
|
-
actionpack (= 3.0.3)
|
60
|
-
activerecord (= 3.0.3)
|
61
|
-
activeresource (= 3.0.3)
|
62
|
-
activesupport (= 3.0.3)
|
63
|
-
bundler (~> 1.0)
|
64
|
-
railties (= 3.0.3)
|
65
|
-
railties (3.0.3)
|
66
|
-
actionpack (= 3.0.3)
|
67
|
-
activesupport (= 3.0.3)
|
68
|
-
rake (>= 0.8.7)
|
69
|
-
thor (~> 0.14.4)
|
70
|
-
rake (0.8.7)
|
71
|
-
sqlite3 (1.3.3)
|
72
|
-
sqlite3-ruby (1.3.3)
|
73
|
-
sqlite3 (>= 1.3.3)
|
74
|
-
tagz (8.0.0)
|
75
|
-
thor (0.14.6)
|
76
|
-
treetop (1.4.9)
|
77
|
-
polyglot (>= 0.3.1)
|
78
|
-
tzinfo (0.3.24)
|
79
|
-
yajl-ruby (0.7.9)
|
80
|
-
|
81
|
-
PLATFORMS
|
82
|
-
ruby
|
83
|
-
|
84
|
-
DEPENDENCIES
|
85
|
-
dao!
|
86
|
-
rails (= 3.0.3)
|
87
|
-
sqlite3-ruby
|
88
|
-
yajl-ruby
|
data/sample/rails_app/README
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
a rails app showing sample dao usage
|
data/sample/rails_app/Rakefile
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
2
|
-
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
3
|
-
|
4
|
-
require File.expand_path('../config/application', __FILE__)
|
5
|
-
require 'rake'
|
6
|
-
|
7
|
-
RailsApp::Application.load_tasks
|
data/sample/rails_app/app/api.rb
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
Api =
|
2
|
-
Dao.api do
|
3
|
-
|
4
|
-
description 'ping!'
|
5
|
-
endpoint('/ping'){
|
6
|
-
data.update :time => Time.now
|
7
|
-
}
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
## this is simply a suggest way to model your api. it is not required.
|
13
|
-
#
|
14
|
-
attr_accessor :effective_user
|
15
|
-
attr_accessor :real_user
|
16
|
-
|
17
|
-
def initialize(*args)
|
18
|
-
options = args.extract_options!.to_options!
|
19
|
-
effective_user = args.shift || options[:effective_user] || options[:user]
|
20
|
-
real_user = args.shift || options[:real_user] || effective_user
|
21
|
-
@effective_user = user_for(effective_user) if effective_user
|
22
|
-
@real_user = user_for(real_user) if real_user
|
23
|
-
@real_user ||= @effective_user
|
24
|
-
end
|
25
|
-
|
26
|
-
def user_for(arg)
|
27
|
-
User.find(arg)
|
28
|
-
end
|
29
|
-
|
30
|
-
alias_method('user', 'effective_user')
|
31
|
-
alias_method('user=', 'effective_user=')
|
32
|
-
|
33
|
-
def api
|
34
|
-
self
|
35
|
-
end
|
36
|
-
|
37
|
-
def logged_in?
|
38
|
-
@effective_user and @real_user
|
39
|
-
end
|
40
|
-
|
41
|
-
def user?
|
42
|
-
logged_in?
|
43
|
-
end
|
44
|
-
|
45
|
-
def current_user
|
46
|
-
effective_user
|
47
|
-
end
|
48
|
-
|
49
|
-
def current_user?
|
50
|
-
!!effective_user
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
|
55
|
-
unloadable(Api)
|
@@ -1,99 +0,0 @@
|
|
1
|
-
class APIController < ApplicationController
|
2
|
-
layout false
|
3
|
-
|
4
|
-
skip_before_filter true
|
5
|
-
skip_before_filter :verify_authenticity_token
|
6
|
-
|
7
|
-
before_filter :setup_api
|
8
|
-
|
9
|
-
### skip_before_filter :set_current_user if Rails.env.production?
|
10
|
-
|
11
|
-
##
|
12
|
-
# /api/foo/2/bar/4 -> api.call('/foo/2/bar/4')
|
13
|
-
#
|
14
|
-
def call
|
15
|
-
path = params[:path]
|
16
|
-
mode = params['mode'] || (request.get? ? 'read' : 'write')
|
17
|
-
|
18
|
-
result = api.mode(mode).call(path, params)
|
19
|
-
|
20
|
-
respond_with(result)
|
21
|
-
end
|
22
|
-
|
23
|
-
##
|
24
|
-
#
|
25
|
-
def index
|
26
|
-
json = json_for(api.index)
|
27
|
-
|
28
|
-
respond_to do |wants|
|
29
|
-
wants.json{ render(:json => json) }
|
30
|
-
wants.html{ render(:text => json, :content_type => 'text/plain') }
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
protected
|
35
|
-
|
36
|
-
def respond_with(result)
|
37
|
-
json = json_for(result)
|
38
|
-
|
39
|
-
respond_to do |wants|
|
40
|
-
wants.json{ render :json => json, :status => result.status.code }
|
41
|
-
wants.html{ render :text => json, :status => result.status.code, :content_type => 'text/plain' }
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
# if you don't have yajl-ruby and yajl/json_gem loaded your json will suck
|
46
|
-
#
|
47
|
-
def json_for(object)
|
48
|
-
if Rails.env.production?
|
49
|
-
::JSON.generate(object)
|
50
|
-
else
|
51
|
-
::JSON.pretty_generate(object, :max_nesting => 0)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def setup_api
|
56
|
-
email, password = http_basic_auth_info
|
57
|
-
|
58
|
-
if !email.blank? and !password.blank?
|
59
|
-
user = User.find_by_email(email)
|
60
|
-
if user.password == password
|
61
|
-
@api = Api.new(user)
|
62
|
-
else
|
63
|
-
render(:nothing => true, :status => :unauthorized)
|
64
|
-
return
|
65
|
-
end
|
66
|
-
else
|
67
|
-
if defined?(current_user)
|
68
|
-
if current_user
|
69
|
-
@api = Api.new(current_user)
|
70
|
-
else
|
71
|
-
render(:nothing => true, :status => :unauthorized)
|
72
|
-
end
|
73
|
-
else
|
74
|
-
@api = Api.new
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
def api
|
80
|
-
@api
|
81
|
-
end
|
82
|
-
|
83
|
-
def http_basic_auth
|
84
|
-
@http_basic_auth ||= (
|
85
|
-
request.env['HTTP_AUTHORIZATION'] ||
|
86
|
-
request.env['X-HTTP_AUTHORIZATION'] ||
|
87
|
-
request.env['X_HTTP_AUTHORIZATION'] ||
|
88
|
-
request.env['REDIRECT_X_HTTP_AUTHORIZATION'] ||
|
89
|
-
''
|
90
|
-
)
|
91
|
-
end
|
92
|
-
|
93
|
-
def http_basic_auth_info
|
94
|
-
username, password =
|
95
|
-
ActiveSupport::Base64.decode64(http_basic_auth.split.last.to_s).split(/:/, 2)
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
ApiController = APIController ### rails is a bitch - shut her up
|