dao 2.2.3 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
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,2 +0,0 @@
1
- module ApplicationHelper
2
- end
@@ -1,14 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>RailsApp</title>
5
- <%= stylesheet_link_tag :all %>
6
- <%= javascript_include_tag :defaults %>
7
- <%= csrf_meta_tag %>
8
- </head>
9
- <body>
10
-
11
- <%= yield %>
12
-
13
- </body>
14
- </html>
@@ -1,4 +0,0 @@
1
- # This file is used by Rack-based servers to start the application.
2
-
3
- require ::File.expand_path('../config/environment', __FILE__)
4
- run RailsApp::Application
@@ -1,51 +0,0 @@
1
- require File.expand_path('../boot', __FILE__)
2
-
3
- require 'rails/all'
4
-
5
- # If you have a Gemfile, require the gems listed there, including any gems
6
- # you've limited to :test, :development, or :production.
7
- Bundler.require(:default, Rails.env) if defined?(Bundler)
8
-
9
- module RailsApp
10
- class Application < Rails::Application
11
-
12
- config.after_initialize do
13
- require 'app/api.rb'
14
- require 'yajl/json_gem'
15
- end
16
-
17
- config.autoload_paths += %w( app )
18
-
19
-
20
- # Settings in config/environments/* take precedence over those specified here.
21
- # Application configuration should go into files in config/initializers
22
- # -- all .rb files in that directory are automatically loaded.
23
-
24
- # Custom directories with classes and modules you want to be autoloadable.
25
- # config.autoload_paths += %W(#{config.root}/extras)
26
-
27
- # Only load the plugins named here, in the order given (default is alphabetical).
28
- # :all can be used as a placeholder for all plugins not explicitly named.
29
- # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
30
-
31
- # Activate observers that should always be running.
32
- # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
33
-
34
- # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
35
- # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
36
- # config.time_zone = 'Central Time (US & Canada)'
37
-
38
- # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
39
- # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
40
- # config.i18n.default_locale = :de
41
-
42
- # JavaScript files you want as :defaults (application.js is always included).
43
- # config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
44
-
45
- # Configure the default encoding used in templates for Ruby 1.9.
46
- config.encoding = "utf-8"
47
-
48
- # Configure sensitive parameters which will be filtered from the log file.
49
- config.filter_parameters += [:password]
50
- end
51
- end
@@ -1,13 +0,0 @@
1
- require 'rubygems'
2
-
3
- # Set up gems listed in the Gemfile.
4
- gemfile = File.expand_path('../../Gemfile', __FILE__)
5
- begin
6
- ENV['BUNDLE_GEMFILE'] = gemfile
7
- require 'bundler'
8
- Bundler.setup
9
- rescue Bundler::GemNotFound => e
10
- STDERR.puts e.message
11
- STDERR.puts "Try running `bundle install`."
12
- exit!
13
- end if File.exist?(gemfile)
@@ -1,22 +0,0 @@
1
- # SQLite version 3.x
2
- # gem install sqlite3-ruby (not necessary on OS X Leopard)
3
- development:
4
- adapter: sqlite3
5
- database: db/development.sqlite3
6
- pool: 5
7
- timeout: 5000
8
-
9
- # Warning: The database defined as "test" will be erased and
10
- # re-generated from your development database when you run "rake".
11
- # Do not set this db to the same as development or production.
12
- test:
13
- adapter: sqlite3
14
- database: db/test.sqlite3
15
- pool: 5
16
- timeout: 5000
17
-
18
- production:
19
- adapter: sqlite3
20
- database: db/production.sqlite3
21
- pool: 5
22
- timeout: 5000
@@ -1,5 +0,0 @@
1
- # Load the rails application
2
- require File.expand_path('../application', __FILE__)
3
-
4
- # Initialize the rails application
5
- RailsApp::Application.initialize!
@@ -1,26 +0,0 @@
1
- RailsApp::Application.configure do
2
- # Settings specified here will take precedence over those in config/application.rb
3
-
4
- # In the development environment your application's code is reloaded on
5
- # every request. This slows down response time but is perfect for development
6
- # since you don't have to restart the webserver when you make code changes.
7
- config.cache_classes = false
8
-
9
- # Log error messages when you accidentally call methods on nil.
10
- config.whiny_nils = true
11
-
12
- # Show full error reports and disable caching
13
- config.consider_all_requests_local = true
14
- config.action_view.debug_rjs = true
15
- config.action_controller.perform_caching = false
16
-
17
- # Don't care if the mailer can't send
18
- config.action_mailer.raise_delivery_errors = false
19
-
20
- # Print deprecation notices to the Rails logger
21
- config.active_support.deprecation = :log
22
-
23
- # Only use best-standards-support built into browsers
24
- config.action_dispatch.best_standards_support = :builtin
25
- end
26
-
@@ -1,49 +0,0 @@
1
- RailsApp::Application.configure do
2
- # Settings specified here will take precedence over those in config/application.rb
3
-
4
- # The production environment is meant for finished, "live" apps.
5
- # Code is not reloaded between requests
6
- config.cache_classes = true
7
-
8
- # Full error reports are disabled and caching is turned on
9
- config.consider_all_requests_local = false
10
- config.action_controller.perform_caching = true
11
-
12
- # Specifies the header that your server uses for sending files
13
- config.action_dispatch.x_sendfile_header = "X-Sendfile"
14
-
15
- # For nginx:
16
- # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
17
-
18
- # If you have no front-end server that supports something like X-Sendfile,
19
- # just comment this out and Rails will serve the files
20
-
21
- # See everything in the log (default is :info)
22
- # config.log_level = :debug
23
-
24
- # Use a different logger for distributed setups
25
- # config.logger = SyslogLogger.new
26
-
27
- # Use a different cache store in production
28
- # config.cache_store = :mem_cache_store
29
-
30
- # Disable Rails's static asset server
31
- # In production, Apache or nginx will already do this
32
- config.serve_static_assets = false
33
-
34
- # Enable serving of images, stylesheets, and javascripts from an asset server
35
- # config.action_controller.asset_host = "http://assets.example.com"
36
-
37
- # Disable delivery errors, bad email addresses will be ignored
38
- # config.action_mailer.raise_delivery_errors = false
39
-
40
- # Enable threaded mode
41
- # config.threadsafe!
42
-
43
- # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
44
- # the I18n.default_locale when a translation can not be found)
45
- config.i18n.fallbacks = true
46
-
47
- # Send deprecation notices to registered listeners
48
- config.active_support.deprecation = :notify
49
- end
@@ -1,35 +0,0 @@
1
- RailsApp::Application.configure do
2
- # Settings specified here will take precedence over those in config/application.rb
3
-
4
- # The test environment is used exclusively to run your application's
5
- # test suite. You never need to work with it otherwise. Remember that
6
- # your test database is "scratch space" for the test suite and is wiped
7
- # and recreated between test runs. Don't rely on the data there!
8
- config.cache_classes = true
9
-
10
- # Log error messages when you accidentally call methods on nil.
11
- config.whiny_nils = true
12
-
13
- # Show full error reports and disable caching
14
- config.consider_all_requests_local = true
15
- config.action_controller.perform_caching = false
16
-
17
- # Raise exceptions instead of rendering exception templates
18
- config.action_dispatch.show_exceptions = false
19
-
20
- # Disable request forgery protection in test environment
21
- config.action_controller.allow_forgery_protection = false
22
-
23
- # Tell Action Mailer not to deliver emails to the real world.
24
- # The :test delivery method accumulates sent emails in the
25
- # ActionMailer::Base.deliveries array.
26
- config.action_mailer.delivery_method = :test
27
-
28
- # Use SQL instead of Active Record's schema dumper when creating the test database.
29
- # This is necessary if your schema can't be completely dumped by the schema dumper,
30
- # like if you have constraints or database-specific column types
31
- # config.active_record.schema_format = :sql
32
-
33
- # Print deprecation notices to the stderr
34
- config.active_support.deprecation = :stderr
35
- end
@@ -1,7 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
- # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
-
6
- # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7
- # Rails.backtrace_cleaner.remove_silencers!
@@ -1,10 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- # Add new inflection rules using the following format
4
- # (all these examples are active by default):
5
- # ActiveSupport::Inflector.inflections do |inflect|
6
- # inflect.plural /^(ox)$/i, '\1en'
7
- # inflect.singular /^(ox)en/i, '\1'
8
- # inflect.irregular 'person', 'people'
9
- # inflect.uncountable %w( fish sheep )
10
- # end
@@ -1,5 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- # Add new mime types for use in respond_to blocks:
4
- # Mime::Type.register "text/richtext", :rtf
5
- # Mime::Type.register_alias "text/html", :iphone
@@ -1,7 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- # Your secret key for verifying the integrity of signed cookies.
4
- # If you change this key, all old signed cookies will become invalid!
5
- # Make sure the secret is at least 30 characters and all random,
6
- # no regular words or you'll be exposed to dictionary attacks.
7
- RailsApp::Application.config.secret_token = 'd67b7c5d32dbeff93f9c57e59cdb92d3a6058ba264cbf1760678ab2485c0a521dd67290c52b9afa7c6a7b536741170fd579a0d0df11a5608a096439650b9ba95'
@@ -1,8 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- RailsApp::Application.config.session_store :cookie_store, :key => '_rails_app_session'
4
-
5
- # Use the database for sessions instead of the cookie-based default,
6
- # which shouldn't be used to store highly confidential information
7
- # (create the session table with "rails generate session_migration")
8
- # RailsApp::Application.config.session_store :active_record_store
@@ -1,5 +0,0 @@
1
- # Sample localization file for English. Add more files in this directory for other locales.
2
- # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
-
4
- en:
5
- hello: "Hello world"
@@ -1,62 +0,0 @@
1
- RailsApp::Application.routes.draw do
2
- match 'api' => 'api#index', :as => 'api_index'
3
-
4
- match 'api/*path' => 'api#call', :as => 'api'
5
-
6
- # The priority is based upon order of creation:
7
- # first created -> highest priority.
8
-
9
- # Sample of regular route:
10
- # match 'products/:id' => 'catalog#view'
11
- # Keep in mind you can assign values other than :controller and :action
12
-
13
- # Sample of named route:
14
- # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
15
- # This route can be invoked with purchase_url(:id => product.id)
16
-
17
- # Sample resource route (maps HTTP verbs to controller actions automatically):
18
- # resources :products
19
-
20
- # Sample resource route with options:
21
- # resources :products do
22
- # member do
23
- # get 'short'
24
- # post 'toggle'
25
- # end
26
- #
27
- # collection do
28
- # get 'sold'
29
- # end
30
- # end
31
-
32
- # Sample resource route with sub-resources:
33
- # resources :products do
34
- # resources :comments, :sales
35
- # resource :seller
36
- # end
37
-
38
- # Sample resource route with more complex sub-resources
39
- # resources :products do
40
- # resources :comments
41
- # resources :sales do
42
- # get 'recent', :on => :collection
43
- # end
44
- # end
45
-
46
- # Sample resource route within a namespace:
47
- # namespace :admin do
48
- # # Directs /admin/products/* to Admin::ProductsController
49
- # # (app/controllers/admin/products_controller.rb)
50
- # resources :products
51
- # end
52
-
53
- # You can have the root of your site routed with "root"
54
- # just remember to delete public/index.html.
55
- # root :to => "welcome#index"
56
-
57
- # See how all your routes lay out with "rake routes"
58
-
59
- # This is a legacy wild controller route that's not recommended for RESTful applications.
60
- # Note: This route will make all actions in every controller accessible via GET requests.
61
- # match ':controller(/:action(/:id(.:format)))'
62
- end
File without changes
@@ -1,7 +0,0 @@
1
- # This file should contain all the record creation needed to seed the database with its default values.
2
- # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
3
- #
4
- # Examples:
5
- #
6
- # cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
7
- # Mayor.create(:name => 'Daley', :city => cities.first)
@@ -1,2 +0,0 @@
1
- Use this README file to introduce your application and point to useful places in the API for learning more.
2
- Run "rake doc:app" to generate API documentation for your models, controllers, helpers, and libraries.
@@ -1,27 +0,0 @@
1
-
2
-
3
- Started GET "/api" for 127.0.0.1 at Fri Jan 28 13:32:22 -0700 2011
4
- Processing by APIController#index as HTML
5
- Rendered text template (0.0ms)
6
- Completed 200 OK in 2ms (Views: 1.4ms | ActiveRecord: 0.0ms)
7
-
8
-
9
- Started GET "/api/ping" for 127.0.0.1 at Fri Jan 28 13:32:25 -0700 2011
10
- Processing by APIController#call as HTML
11
- Parameters: {"path"=>"ping"}
12
- Rendered text template (0.0ms)
13
- Completed 200 OK in 7ms (Views: 1.0ms | ActiveRecord: 0.0ms)
14
-
15
-
16
- Started GET "/api/ping" for 127.0.0.1 at Fri Jan 28 13:43:47 -0700 2011
17
- Processing by APIController#call as HTML
18
- Parameters: {"path"=>"ping"}
19
- Rendered text template (0.0ms)
20
- Completed 200 OK in 3ms (Views: 1.4ms | ActiveRecord: 0.0ms)
21
-
22
-
23
- Started GET "/api/ping" for 127.0.0.1 at Fri Jan 28 13:47:01 -0700 2011
24
- Processing by APIController#call as HTML
25
- Parameters: {"path"=>"ping"}
26
- Rendered text template (0.0ms)
27
- Completed 200 OK in 3ms (Views: 1.4ms | ActiveRecord: 0.0ms)
File without changes
File without changes
File without changes
@@ -1,148 +0,0 @@
1
- if(!window.Dao){
2
- (function(){
3
- window.Dao = {};
4
-
5
- // pull jQuery off the CDN iff needed
6
- //
7
- !window.jQuery && document.write(unescape('%3Cscript src="js/libs/jquery-1.4.2.js"%3E%3C/script%3E'));
8
- var jq = jQuery;
9
-
10
- // ctor
11
- //
12
- Dao.Api = function(){
13
- this.route = '' + Dao.Api.route;
14
- this.result = null;
15
- this.results = [];
16
- this.mode = 'get';
17
- this.method = Dao[this.mode];
18
- };
19
- Dao.Api.route = '/api';
20
- Dao.Api.modes = ["options", "get", "head", "post", "put", "delete", "trace", "connect"];
21
-
22
- // single call interface
23
- //
24
- Dao.Api.prototype.call = function(){
25
- var api = this;
26
- var options = {};
27
-
28
- if(arguments.length == 1){
29
- var arg = arguments[0];
30
-
31
- if(typeof(arg)=='string'){
32
- options.path = arg;
33
- } else {
34
- options = arg;
35
- }
36
- }
37
-
38
- if(arguments.length > 1){
39
- options.path = arguments[0];
40
- options.params = arguments[1];
41
- options.success = arguments[2];
42
- }
43
-
44
- if(!options.path){
45
- options.path = '/ping';
46
- }
47
-
48
- if(!options.params){
49
- options.params = {};
50
- }
51
-
52
- if(!options.success){
53
- options.success = function(result){
54
- result = new Dao.Result(result);
55
- api.result = result;
56
- api.results.push(result);
57
- };
58
- }
59
-
60
- var url = api.route + options.path;
61
-
62
- var data = options.params;
63
-
64
- var success = function(result){
65
- var result = new Dao.Result(result);
66
- if(options.success){
67
- options.success(result);
68
- } else {
69
- api.result = result;
70
- api.results.push(result);
71
- }
72
- };
73
-
74
- var ajax = {};
75
- ajax.url = url;
76
- ajax.data = data;
77
- ajax.success = success;
78
-
79
- Dao[api.mode](ajax);
80
- return(api);
81
- };
82
-
83
- // meta-program api.read(..), api.post(...), ...
84
- //
85
- for(var i = 0; i < Dao.Api.modes.length; i++){
86
- (function(){
87
- var mode = Dao.Api.modes[i];
88
-
89
- Dao.Api.prototype[mode] = function(){
90
- var api = this;
91
- var previous = api.mode;
92
- api.mode = mode;
93
- var returned = api.call.apply(api, arguments);
94
- api.mode = previous;
95
- return(returned);
96
- };
97
- })();
98
- }
99
- Dao.Api.prototype['read'] = Dao.Api.prototype['get'];
100
- Dao.Api.prototype['write'] = Dao.Api.prototype['post'];
101
-
102
- // a thin wrapper on results for now. TODO - make it smarter
103
- //
104
- Dao.Result = function(options){
105
- this.path = options.path;
106
- this.status = options.status;
107
- this.errors = options.errors;
108
- this.data = options.data;
109
-
110
- //parts = ('' + this.status).split(/\s+/);
111
- //this.status.code = parseInt(parts.shift());
112
- //this.status.message = parts.join(' ');
113
- };
114
-
115
- // ajax utils
116
- //
117
- Dao.ajax = function(options){
118
- var ajax = {};
119
- ajax.type = options.type;
120
- ajax.url = options.url;
121
- ajax.dataType = 'json';
122
- if(ajax.type == 'POST' || ajax.type == 'PUT'){
123
- ajax.data = jq.toJSON(options.data || {});
124
- } else {
125
- ajax.data = (options.data || {});
126
- };
127
- ajax.contentType = (options.contentType || 'application/json; charset=utf-8');
128
- ajax.success = (options.success || function(){});
129
- jq.ajax(ajax);
130
- };
131
-
132
- // meta-program Api.get(...), Api.post(...)
133
- //
134
- for(var i = 0; i < Dao.Api.modes.length; i++){
135
- (function(){
136
- var mode = Dao.Api.modes[i];
137
-
138
- Dao[mode] = function(options){
139
- options.type = mode.toUpperCase();
140
- Dao.ajax(options);
141
- };
142
- })();
143
- }
144
-
145
- Dao.api = new Dao.Api();
146
- window.api = window.api || Dao.api;
147
- }());
148
- }