dao 2.2.3 → 3.1.0

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.
Files changed (79) hide show
  1. data/Rakefile +68 -113
  2. data/TODO +3 -9
  3. data/a.rb +25 -0
  4. data/dao.gemspec +70 -14
  5. data/lib/dao.rb +8 -8
  6. data/lib/dao/api.rb +1 -0
  7. data/lib/dao/api/context.rb +48 -23
  8. data/lib/dao/api/dsl.rb +1 -1
  9. data/lib/dao/api/interfaces.rb +149 -117
  10. data/lib/dao/api/modes.rb +24 -23
  11. data/lib/dao/api/routes.rb +9 -0
  12. data/lib/dao/data.rb +9 -2
  13. data/lib/dao/errors.rb +15 -11
  14. data/lib/dao/form.rb +46 -37
  15. data/lib/dao/interface.rb +1 -1
  16. data/lib/dao/mode.rb +45 -20
  17. data/lib/dao/params.rb +35 -53
  18. data/lib/dao/path.rb +6 -9
  19. data/lib/dao/rails/lib/generators/dao/templates/api.rb +1 -1
  20. data/lib/dao/rails/lib/generators/dao/templates/dao_helper.rb +16 -0
  21. data/lib/dao/result.rb +26 -133
  22. data/lib/dao/route.rb +87 -0
  23. data/lib/dao/status.rb +96 -94
  24. data/lib/dao/support.rb +5 -3
  25. data/lib/dao/validations.rb +46 -442
  26. data/lib/dao/validations/base.rb +68 -0
  27. data/lib/dao/validations/common.rb +463 -0
  28. data/test/dao_test.rb +214 -33
  29. metadata +20 -112
  30. data/lib/dao/rails/app/api.rb +0 -55
  31. data/lib/dao/rails/app/controllers/api_controller.rb +0 -99
  32. data/sample/rails_app/Gemfile +0 -33
  33. data/sample/rails_app/Gemfile.lock +0 -88
  34. data/sample/rails_app/README +0 -1
  35. data/sample/rails_app/Rakefile +0 -7
  36. data/sample/rails_app/app/api.rb +0 -55
  37. data/sample/rails_app/app/controllers/api_controller.rb +0 -99
  38. data/sample/rails_app/app/controllers/application_controller.rb +0 -3
  39. data/sample/rails_app/app/helpers/application_helper.rb +0 -2
  40. data/sample/rails_app/app/views/layouts/application.html.erb +0 -14
  41. data/sample/rails_app/config.ru +0 -4
  42. data/sample/rails_app/config/application.rb +0 -51
  43. data/sample/rails_app/config/boot.rb +0 -13
  44. data/sample/rails_app/config/database.yml +0 -22
  45. data/sample/rails_app/config/environment.rb +0 -5
  46. data/sample/rails_app/config/environments/development.rb +0 -26
  47. data/sample/rails_app/config/environments/production.rb +0 -49
  48. data/sample/rails_app/config/environments/test.rb +0 -35
  49. data/sample/rails_app/config/initializers/backtrace_silencers.rb +0 -7
  50. data/sample/rails_app/config/initializers/inflections.rb +0 -10
  51. data/sample/rails_app/config/initializers/mime_types.rb +0 -5
  52. data/sample/rails_app/config/initializers/secret_token.rb +0 -7
  53. data/sample/rails_app/config/initializers/session_store.rb +0 -8
  54. data/sample/rails_app/config/locales/en.yml +0 -5
  55. data/sample/rails_app/config/routes.rb +0 -62
  56. data/sample/rails_app/db/development.sqlite3 +0 -0
  57. data/sample/rails_app/db/seeds.rb +0 -7
  58. data/sample/rails_app/doc/README_FOR_APP +0 -2
  59. data/sample/rails_app/log/development.log +0 -27
  60. data/sample/rails_app/log/production.log +0 -0
  61. data/sample/rails_app/log/server.log +0 -0
  62. data/sample/rails_app/log/test.log +0 -0
  63. data/sample/rails_app/pubic/javascripts/dao.js +0 -148
  64. data/sample/rails_app/public/404.html +0 -26
  65. data/sample/rails_app/public/422.html +0 -26
  66. data/sample/rails_app/public/500.html +0 -26
  67. data/sample/rails_app/public/favicon.ico +0 -0
  68. data/sample/rails_app/public/images/rails.png +0 -0
  69. data/sample/rails_app/public/index.html +0 -239
  70. data/sample/rails_app/public/javascripts/application.js +0 -2
  71. data/sample/rails_app/public/javascripts/controls.js +0 -965
  72. data/sample/rails_app/public/javascripts/dragdrop.js +0 -974
  73. data/sample/rails_app/public/javascripts/effects.js +0 -1123
  74. data/sample/rails_app/public/javascripts/prototype.js +0 -6001
  75. data/sample/rails_app/public/javascripts/rails.js +0 -175
  76. data/sample/rails_app/public/robots.txt +0 -5
  77. data/sample/rails_app/script/rails +0 -6
  78. data/sample/rails_app/test/performance/browsing_test.rb +0 -9
  79. data/sample/rails_app/test/test_helper.rb +0 -13
@@ -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
@@ -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
@@ -1 +0,0 @@
1
- a rails app showing sample dao usage
@@ -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
@@ -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
@@ -1,3 +0,0 @@
1
- class ApplicationController < ActionController::Base
2
- protect_from_forgery
3
- end