dao 0.0.0 → 2.0.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.
- data/README +35 -0
- data/Rakefile +6 -3
- data/TODO +37 -0
- data/dao.gemspec +30 -0
- data/db/dao.yml +8 -0
- data/lib/dao.rb +84 -5
- data/lib/dao/active_record.rb +76 -0
- data/lib/dao/api.rb +9 -0
- data/lib/dao/api/context.rb +38 -0
- data/lib/dao/api/dsl.rb +50 -0
- data/lib/dao/api/endpoints.rb +190 -0
- data/lib/dao/api/initializers.rb +71 -0
- data/lib/dao/api/modes.rb +85 -0
- data/lib/dao/blankslate.rb +5 -0
- data/lib/dao/data.rb +58 -0
- data/lib/dao/db.rb +183 -0
- data/lib/dao/endpoint.rb +16 -0
- data/lib/dao/engine.rb +7 -0
- data/lib/dao/errors.rb +238 -0
- data/lib/dao/exceptions.rb +2 -0
- data/lib/dao/form.rb +236 -0
- data/lib/dao/mode.rb +41 -0
- data/lib/dao/mongo_mapper.rb +70 -0
- data/lib/dao/params.rb +109 -0
- data/lib/dao/path.rb +149 -0
- data/lib/dao/rails.rb +15 -0
- data/lib/dao/rails/app/api.rb +55 -0
- data/lib/dao/rails/app/controllers/api_controller.rb +99 -0
- data/lib/dao/rails/lib/generators/dao/USAGE +9 -0
- data/lib/dao/rails/lib/generators/dao/api_generator.rb +3 -0
- data/lib/dao/rails/lib/generators/dao/dao_generator.rb +27 -0
- data/lib/dao/rails/lib/generators/dao/templates/api.rb +55 -0
- data/lib/dao/rails/lib/generators/dao/templates/api_controller.rb +99 -0
- data/lib/dao/result.rb +87 -0
- data/lib/dao/slug.rb +11 -0
- data/lib/dao/status.rb +223 -0
- data/lib/dao/stdext.rb +10 -0
- data/lib/dao/support.rb +62 -0
- data/lib/dao/validations.rb +115 -0
- data/sample/rails_app/Gemfile +33 -0
- data/sample/rails_app/Gemfile.lock +88 -0
- data/sample/rails_app/README +1 -0
- data/sample/rails_app/Rakefile +7 -0
- data/sample/rails_app/app/api.rb +55 -0
- data/sample/rails_app/app/controllers/api_controller.rb +99 -0
- data/sample/rails_app/app/controllers/application_controller.rb +3 -0
- data/sample/rails_app/app/helpers/application_helper.rb +2 -0
- data/sample/rails_app/app/views/layouts/application.html.erb +14 -0
- data/sample/rails_app/config.ru +4 -0
- data/sample/rails_app/config/application.rb +51 -0
- data/sample/rails_app/config/boot.rb +13 -0
- data/sample/rails_app/config/database.yml +22 -0
- data/sample/rails_app/config/environment.rb +5 -0
- data/sample/rails_app/config/environments/development.rb +26 -0
- data/sample/rails_app/config/environments/production.rb +49 -0
- data/sample/rails_app/config/environments/test.rb +35 -0
- data/sample/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/sample/rails_app/config/initializers/inflections.rb +10 -0
- data/sample/rails_app/config/initializers/mime_types.rb +5 -0
- data/sample/rails_app/config/initializers/secret_token.rb +7 -0
- data/sample/rails_app/config/initializers/session_store.rb +8 -0
- data/sample/rails_app/config/locales/en.yml +5 -0
- data/sample/rails_app/config/routes.rb +62 -0
- data/sample/rails_app/db/development.sqlite3 +0 -0
- data/sample/rails_app/db/seeds.rb +7 -0
- data/sample/rails_app/doc/README_FOR_APP +2 -0
- data/sample/rails_app/log/development.log +27 -0
- 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/public/404.html +26 -0
- data/sample/rails_app/public/422.html +26 -0
- data/sample/rails_app/public/500.html +26 -0
- 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 +239 -0
- data/sample/rails_app/public/javascripts/application.js +2 -0
- data/sample/rails_app/public/javascripts/controls.js +965 -0
- data/sample/rails_app/public/javascripts/dragdrop.js +974 -0
- data/sample/rails_app/public/javascripts/effects.js +1123 -0
- data/sample/rails_app/public/javascripts/prototype.js +6001 -0
- data/sample/rails_app/public/javascripts/rails.js +175 -0
- data/sample/rails_app/public/robots.txt +5 -0
- data/sample/rails_app/script/rails +6 -0
- data/sample/rails_app/test/performance/browsing_test.rb +9 -0
- data/sample/rails_app/test/test_helper.rb +13 -0
- data/test/dao_test.rb +271 -0
- data/test/helper.rb +15 -0
- data/test/testing.rb +74 -0
- metadata +137 -9
@@ -0,0 +1,33 @@
|
|
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"
|
@@ -0,0 +1,88 @@
|
|
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
|
@@ -0,0 +1 @@
|
|
1
|
+
a rails app showing sample dao usage
|
@@ -0,0 +1,7 @@
|
|
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
|
@@ -0,0 +1,55 @@
|
|
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)
|
@@ -0,0 +1,99 @@
|
|
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
|
@@ -0,0 +1,51 @@
|
|
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
|
@@ -0,0 +1,13 @@
|
|
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)
|
@@ -0,0 +1,22 @@
|
|
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
|
@@ -0,0 +1,26 @@
|
|
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
|
+
|