acts_as_api_sequel 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.travis.yml +5 -0
- data/Gemfile +13 -0
- data/History.txt +108 -0
- data/README.md +126 -0
- data/Rakefile +48 -0
- data/acts_as_api.gemspec +28 -0
- data/examples/introduction/docco.css +186 -0
- data/examples/introduction/index.html +338 -0
- data/examples/introduction/index.rb +144 -0
- data/examples/introduction/layout.mustache +67 -0
- data/lib/acts_as_api.rb +46 -0
- data/lib/acts_as_api/adapters.rb +5 -0
- data/lib/acts_as_api/adapters/mongoid.rb +11 -0
- data/lib/acts_as_api/api_template.rb +139 -0
- data/lib/acts_as_api/array.rb +21 -0
- data/lib/acts_as_api/base.rb +88 -0
- data/lib/acts_as_api/config.rb +58 -0
- data/lib/acts_as_api/exceptions.rb +4 -0
- data/lib/acts_as_api/rails_renderer.rb +17 -0
- data/lib/acts_as_api/rendering.rb +95 -0
- data/lib/acts_as_api/responder.rb +39 -0
- data/lib/acts_as_api/version.rb +3 -0
- data/spec/README.md +55 -0
- data/spec/active_record_dummy/.gitignore +15 -0
- data/spec/active_record_dummy/Gemfile +16 -0
- data/spec/active_record_dummy/README.rdoc +261 -0
- data/spec/active_record_dummy/Rakefile +7 -0
- data/spec/active_record_dummy/app/assets/images/rails.png +0 -0
- data/spec/active_record_dummy/app/assets/javascripts/application.js +15 -0
- data/spec/active_record_dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/active_record_dummy/app/controllers/application_controller.rb +3 -0
- data/spec/active_record_dummy/app/helpers/application_helper.rb +2 -0
- data/spec/active_record_dummy/app/mailers/.gitkeep +0 -0
- data/spec/active_record_dummy/app/models/.gitkeep +0 -0
- data/spec/active_record_dummy/app/models/profile.rb +4 -0
- data/spec/active_record_dummy/app/models/task.rb +4 -0
- data/spec/active_record_dummy/app/models/untouched.rb +2 -0
- data/spec/active_record_dummy/app/models/user.rb +186 -0
- data/spec/active_record_dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/active_record_dummy/config.ru +4 -0
- data/spec/active_record_dummy/config/application.rb +59 -0
- data/spec/active_record_dummy/config/boot.rb +6 -0
- data/spec/active_record_dummy/config/database.yml +25 -0
- data/spec/active_record_dummy/config/environment.rb +5 -0
- data/spec/active_record_dummy/config/environments/development.rb +37 -0
- data/spec/active_record_dummy/config/environments/production.rb +67 -0
- data/spec/active_record_dummy/config/environments/test.rb +37 -0
- data/spec/active_record_dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/active_record_dummy/config/initializers/generators.rb +2 -0
- data/spec/active_record_dummy/config/initializers/inflections.rb +15 -0
- data/spec/active_record_dummy/config/initializers/mime_types.rb +5 -0
- data/spec/active_record_dummy/config/initializers/secret_token.rb +7 -0
- data/spec/active_record_dummy/config/initializers/session_store.rb +8 -0
- data/spec/active_record_dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/active_record_dummy/config/locales/en.yml +5 -0
- data/spec/active_record_dummy/config/routes.rb +59 -0
- data/spec/active_record_dummy/db/migrate/20110214201640_create_tables.rb +44 -0
- data/spec/active_record_dummy/db/schema.rb +47 -0
- data/spec/active_record_dummy/db/seeds.rb +7 -0
- data/spec/active_record_dummy/doc/README_FOR_APP +2 -0
- data/spec/active_record_dummy/lib/assets/.gitkeep +0 -0
- data/spec/active_record_dummy/lib/tasks/.gitkeep +0 -0
- data/spec/active_record_dummy/log/.gitkeep +0 -0
- data/spec/active_record_dummy/public/404.html +26 -0
- data/spec/active_record_dummy/public/422.html +26 -0
- data/spec/active_record_dummy/public/500.html +25 -0
- data/spec/active_record_dummy/public/favicon.ico +0 -0
- data/spec/active_record_dummy/public/index.html +241 -0
- data/spec/active_record_dummy/public/robots.txt +5 -0
- data/spec/active_record_dummy/script/rails +6 -0
- data/spec/active_record_dummy/vendor/assets/javascripts/.gitkeep +0 -0
- data/spec/active_record_dummy/vendor/assets/stylesheets/.gitkeep +0 -0
- data/spec/active_record_dummy/vendor/plugins/.gitkeep +0 -0
- data/spec/controllers/plain_objects_controller_spec.rb +36 -0
- data/spec/controllers/respond_with_users_controller_spec.rb +142 -0
- data/spec/controllers/users_controller_spec.rb +15 -0
- data/spec/models/model_spec.rb +31 -0
- data/spec/mongoid_dummy/.gitignore +15 -0
- data/spec/mongoid_dummy/Gemfile +18 -0
- data/spec/mongoid_dummy/README.rdoc +261 -0
- data/spec/mongoid_dummy/Rakefile +7 -0
- data/spec/mongoid_dummy/app/assets/images/rails.png +0 -0
- data/spec/mongoid_dummy/app/assets/javascripts/application.js +15 -0
- data/spec/mongoid_dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/mongoid_dummy/app/controllers/application_controller.rb +3 -0
- data/spec/mongoid_dummy/app/helpers/application_helper.rb +2 -0
- data/spec/mongoid_dummy/app/mailers/.gitkeep +0 -0
- data/spec/mongoid_dummy/app/models/.gitkeep +0 -0
- data/spec/mongoid_dummy/app/models/profile.rb +10 -0
- data/spec/mongoid_dummy/app/models/task.rb +12 -0
- data/spec/mongoid_dummy/app/models/untouched.rb +7 -0
- data/spec/mongoid_dummy/app/models/user.rb +48 -0
- data/spec/mongoid_dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/mongoid_dummy/config.ru +4 -0
- data/spec/mongoid_dummy/config/application.rb +65 -0
- data/spec/mongoid_dummy/config/boot.rb +6 -0
- data/spec/mongoid_dummy/config/environment.rb +5 -0
- data/spec/mongoid_dummy/config/environments/development.rb +31 -0
- data/spec/mongoid_dummy/config/environments/production.rb +64 -0
- data/spec/mongoid_dummy/config/environments/test.rb +35 -0
- data/spec/mongoid_dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/mongoid_dummy/config/initializers/generators.rb +2 -0
- data/spec/mongoid_dummy/config/initializers/include_acts_as_api.rb +3 -0
- data/spec/mongoid_dummy/config/initializers/inflections.rb +15 -0
- data/spec/mongoid_dummy/config/initializers/mime_types.rb +5 -0
- data/spec/mongoid_dummy/config/initializers/secret_token.rb +7 -0
- data/spec/mongoid_dummy/config/initializers/session_store.rb +8 -0
- data/spec/mongoid_dummy/config/initializers/wrap_parameters.rb +10 -0
- data/spec/mongoid_dummy/config/locales/en.yml +5 -0
- data/spec/mongoid_dummy/config/mongoid.yml +120 -0
- data/spec/mongoid_dummy/config/routes.rb +59 -0
- data/spec/mongoid_dummy/db/seeds.rb +7 -0
- data/spec/mongoid_dummy/doc/README_FOR_APP +2 -0
- data/spec/mongoid_dummy/lib/assets/.gitkeep +0 -0
- data/spec/mongoid_dummy/lib/tasks/.gitkeep +0 -0
- data/spec/mongoid_dummy/log/.gitkeep +0 -0
- data/spec/mongoid_dummy/public/404.html +26 -0
- data/spec/mongoid_dummy/public/422.html +26 -0
- data/spec/mongoid_dummy/public/500.html +25 -0
- data/spec/mongoid_dummy/public/favicon.ico +0 -0
- data/spec/mongoid_dummy/public/index.html +241 -0
- data/spec/mongoid_dummy/public/robots.txt +5 -0
- data/spec/mongoid_dummy/script/rails +6 -0
- data/spec/mongoid_dummy/vendor/assets/javascripts/.gitkeep +0 -0
- data/spec/mongoid_dummy/vendor/assets/stylesheets/.gitkeep +0 -0
- data/spec/mongoid_dummy/vendor/plugins/.gitkeep +0 -0
- data/spec/shared_engine/.gitignore +7 -0
- data/spec/shared_engine/Gemfile +14 -0
- data/spec/shared_engine/MIT-LICENSE +20 -0
- data/spec/shared_engine/README.rdoc +3 -0
- data/spec/shared_engine/Rakefile +29 -0
- data/spec/shared_engine/app/assets/images/shared_engine/.gitkeep +0 -0
- data/spec/shared_engine/app/assets/javascripts/shared_engine/application.js +15 -0
- data/spec/shared_engine/app/assets/stylesheets/shared_engine/application.css +13 -0
- data/spec/shared_engine/app/controllers/shared_engine/application_controller.rb +4 -0
- data/spec/shared_engine/app/controllers/shared_engine/plain_objects_controller.rb +14 -0
- data/spec/shared_engine/app/controllers/shared_engine/respond_with_users_controller.rb +64 -0
- data/spec/shared_engine/app/controllers/shared_engine/users_controller.rb +71 -0
- data/spec/shared_engine/app/helpers/shared_engine/application_helper.rb +4 -0
- data/spec/shared_engine/app/models/plain_object.rb +17 -0
- data/spec/shared_engine/app/models/user_template.rb +154 -0
- data/spec/shared_engine/app/views/layouts/shared_engine/application.html.erb +14 -0
- data/spec/shared_engine/config/routes.rb +28 -0
- data/spec/shared_engine/dummy/README.rdoc +261 -0
- data/spec/shared_engine/dummy/Rakefile +7 -0
- data/spec/shared_engine/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/shared_engine/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/shared_engine/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/shared_engine/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/shared_engine/dummy/app/mailers/.gitkeep +0 -0
- data/spec/shared_engine/dummy/app/models/.gitkeep +0 -0
- data/spec/shared_engine/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/shared_engine/dummy/config.ru +4 -0
- data/spec/shared_engine/dummy/config/application.rb +62 -0
- data/spec/shared_engine/dummy/config/boot.rb +10 -0
- data/spec/shared_engine/dummy/config/database.yml +25 -0
- data/spec/shared_engine/dummy/config/environment.rb +5 -0
- data/spec/shared_engine/dummy/config/environments/development.rb +37 -0
- data/spec/shared_engine/dummy/config/environments/production.rb +67 -0
- data/spec/shared_engine/dummy/config/environments/test.rb +37 -0
- data/spec/shared_engine/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/shared_engine/dummy/config/initializers/inflections.rb +15 -0
- data/spec/shared_engine/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/shared_engine/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/shared_engine/dummy/config/initializers/session_store.rb +8 -0
- data/spec/shared_engine/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/shared_engine/dummy/config/locales/en.yml +5 -0
- data/spec/shared_engine/dummy/config/routes.rb +4 -0
- data/spec/shared_engine/dummy/lib/assets/.gitkeep +0 -0
- data/spec/shared_engine/dummy/log/.gitkeep +0 -0
- data/spec/shared_engine/dummy/public/404.html +26 -0
- data/spec/shared_engine/dummy/public/422.html +26 -0
- data/spec/shared_engine/dummy/public/500.html +25 -0
- data/spec/shared_engine/dummy/public/favicon.ico +0 -0
- data/spec/shared_engine/dummy/script/rails +6 -0
- data/spec/shared_engine/lib/magic/rails/engine.rb +69 -0
- data/spec/shared_engine/lib/shared_engine.rb +4 -0
- data/spec/shared_engine/lib/shared_engine/engine.rb +5 -0
- data/spec/shared_engine/lib/shared_engine/version.rb +3 -0
- data/spec/shared_engine/lib/tasks/shared_engine_tasks.rake +4 -0
- data/spec/shared_engine/script/rails +8 -0
- data/spec/shared_engine/shared_engine.gemspec +22 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +22 -0
- data/spec/support/api_test_helpers.rb +23 -0
- data/spec/support/controller_examples.rb +458 -0
- data/spec/support/it_supports.rb +3 -0
- data/spec/support/model_examples/associations.rb +272 -0
- data/spec/support/model_examples/callbacks.rb +38 -0
- data/spec/support/model_examples/closures.rb +49 -0
- data/spec/support/model_examples/conditional_if.rb +165 -0
- data/spec/support/model_examples/conditional_unless.rb +165 -0
- data/spec/support/model_examples/enabled.rb +10 -0
- data/spec/support/model_examples/extending.rb +112 -0
- data/spec/support/model_examples/methods.rb +23 -0
- data/spec/support/model_examples/options.rb +53 -0
- data/spec/support/model_examples/renaming.rb +50 -0
- data/spec/support/model_examples/simple.rb +23 -0
- data/spec/support/model_examples/sub_nodes.rb +105 -0
- data/spec/support/model_examples/undefined.rb +7 -0
- data/spec/support/model_examples/untouched.rb +13 -0
- data/spec/support/routing.rb +4 -0
- data/spec/support/simple_fixtures.rb +59 -0
- metadata +499 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
|
3
|
+
|
|
4
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
|
5
|
+
require File.expand_path('../../config/boot', __FILE__)
|
|
6
|
+
require 'rails/commands'
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
source "http://rubygems.org"
|
|
2
|
+
|
|
3
|
+
# Declare your gem's dependencies in shared_engine.gemspec.
|
|
4
|
+
# Bundler will treat runtime dependencies like base dependencies, and
|
|
5
|
+
# development dependencies will be added by default to the :development group.
|
|
6
|
+
gemspec
|
|
7
|
+
|
|
8
|
+
# Declare any dependencies that are still in development here instead of in
|
|
9
|
+
# your gemspec. These might include edge Rails or gems from your path or
|
|
10
|
+
# Git. Remember to move these dependencies to your gemspec before releasing
|
|
11
|
+
# your gem to rubygems.org.
|
|
12
|
+
|
|
13
|
+
# To use debugger
|
|
14
|
+
# gem 'ruby-debug19', :require => 'ruby-debug'
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright 2012 YOURNAME
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#!/usr/bin/env rake
|
|
2
|
+
begin
|
|
3
|
+
require 'bundler/setup'
|
|
4
|
+
rescue LoadError
|
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
|
6
|
+
end
|
|
7
|
+
begin
|
|
8
|
+
require 'rdoc/task'
|
|
9
|
+
rescue LoadError
|
|
10
|
+
require 'rdoc/rdoc'
|
|
11
|
+
require 'rake/rdoctask'
|
|
12
|
+
RDoc::Task = Rake::RDocTask
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
17
|
+
rdoc.title = 'SharedEngine'
|
|
18
|
+
rdoc.options << '--line-numbers'
|
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
APP_RAKEFILE = File.expand_path("../active_record_dummy/Rakefile", __FILE__)
|
|
24
|
+
load 'rails/tasks/engine.rake'
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
Bundler::GemHelper.install_tasks
|
|
29
|
+
|
|
File without changes
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
|
2
|
+
// listed below.
|
|
3
|
+
//
|
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
|
6
|
+
//
|
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
|
8
|
+
// the compiled file.
|
|
9
|
+
//
|
|
10
|
+
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
|
|
11
|
+
// GO AFTER THE REQUIRES BELOW.
|
|
12
|
+
//
|
|
13
|
+
//= require jquery
|
|
14
|
+
//= require jquery_ujs
|
|
15
|
+
//= require_tree .
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
|
3
|
+
* listed below.
|
|
4
|
+
*
|
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
|
7
|
+
*
|
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
|
10
|
+
*
|
|
11
|
+
*= require_self
|
|
12
|
+
*= require_tree .
|
|
13
|
+
*/
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module SharedEngine
|
|
2
|
+
class PlainObjectsController < SharedEngine::ApplicationController
|
|
3
|
+
before_filter :setup_objects
|
|
4
|
+
|
|
5
|
+
def index
|
|
6
|
+
@users = [@han, @luke, @leia]
|
|
7
|
+
|
|
8
|
+
respond_to do |format|
|
|
9
|
+
format.xml { render_for_api params[:api_template].to_sym, :xml => @users }
|
|
10
|
+
format.json { render_for_api params[:api_template].to_sym, :json => @users }
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
module SharedEngine
|
|
2
|
+
class RespondWithUsersController < SharedEngine::ApplicationController
|
|
3
|
+
|
|
4
|
+
respond_to :json, :xml
|
|
5
|
+
|
|
6
|
+
self.responder = ActsAsApi::Responder
|
|
7
|
+
|
|
8
|
+
def index
|
|
9
|
+
@users = User.all.sort_by(&:first_name)
|
|
10
|
+
respond_with @users, :api_template => params[:api_template].to_sym, :root => :users
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def index_no_root_no_order
|
|
14
|
+
@users = User.all
|
|
15
|
+
respond_with @users, :api_template => params[:api_template].to_sym
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def index_meta
|
|
19
|
+
@users = User.all
|
|
20
|
+
meta_hash = { :page => 1, :total => 999 }
|
|
21
|
+
respond_with @users, :api_template => params[:api_template].to_sym, :root => :users, :meta => meta_hash
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def index_relation
|
|
25
|
+
@users = User.limit(100).sort_by(&:first_name)
|
|
26
|
+
respond_with @users, :api_template => params[:api_template].to_sym
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def show
|
|
30
|
+
@user = User.find(params[:id])
|
|
31
|
+
# :root => :user is only used here because we need it for the node name of the MongoUser model
|
|
32
|
+
respond_with @user, :api_template => params[:api_template].to_sym, :root => :user
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def show_meta
|
|
36
|
+
@user = User.find(params[:id])
|
|
37
|
+
meta_hash = { :page => 1, :total => 999 }
|
|
38
|
+
# :root => :user is only used here because we need it for the node name of the MongoUser model
|
|
39
|
+
respond_with @user, :api_template => params[:api_template].to_sym, :root => :user, :meta => meta_hash
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def show_default
|
|
43
|
+
@user = User.find(params[:id])
|
|
44
|
+
respond_with @user
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def show_prefix_postfix
|
|
48
|
+
@user = User.find(params[:id])
|
|
49
|
+
# :root => :user is only used here because we need it for the node name of the MongoUser model
|
|
50
|
+
respond_with @user, :api_template => {:template => params[:api_template], :prefix => params[:api_prefix], :postfix => params[:api_postfix]}, :root => :user
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def create
|
|
54
|
+
@user = User.new(params[:user])
|
|
55
|
+
|
|
56
|
+
if @user.save
|
|
57
|
+
respond_with @user, :api_template => params[:api_template]
|
|
58
|
+
else
|
|
59
|
+
respond_with @user
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
end
|
|
64
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
module SharedEngine
|
|
2
|
+
class UsersController < SharedEngine::ApplicationController
|
|
3
|
+
|
|
4
|
+
def index
|
|
5
|
+
@users = User.all.sort_by(&:first_name)
|
|
6
|
+
|
|
7
|
+
respond_to do |format|
|
|
8
|
+
format.xml { render_for_api params[:api_template].to_sym, :xml => @users, :root => :users }
|
|
9
|
+
format.json { render_for_api params[:api_template].to_sym, :json => @users, :root => :users }
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def index_meta
|
|
14
|
+
@users = User.all
|
|
15
|
+
meta_hash = { :page => 1, :total => 999 }
|
|
16
|
+
|
|
17
|
+
respond_to do |format|
|
|
18
|
+
format.xml { render_for_api params[:api_template].to_sym, :xml => @users, :root => :users, :meta => meta_hash }
|
|
19
|
+
format.json { render_for_api params[:api_template].to_sym, :json => @users, :root => :users, :meta => meta_hash }
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def index_relation
|
|
24
|
+
@users = User.limit(100).sort_by(&:first_name)
|
|
25
|
+
|
|
26
|
+
respond_to do |format|
|
|
27
|
+
format.xml { render_for_api params[:api_template].to_sym, :xml => @users }
|
|
28
|
+
format.json { render_for_api params[:api_template].to_sym, :json => @users }
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def show
|
|
33
|
+
@user = User.find(params[:id])
|
|
34
|
+
|
|
35
|
+
respond_to do |format|
|
|
36
|
+
# :root => :user is only used here because we need it for the node name of the MongoUser model
|
|
37
|
+
format.xml { render_for_api params[:api_template].to_sym, :xml => @user, :root => :user }
|
|
38
|
+
format.json { render_for_api params[:api_template].to_sym, :json => @user, :root => :user }
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def show_meta
|
|
43
|
+
@user = User.find(params[:id])
|
|
44
|
+
meta_hash = { :page => 1, :total => 999 }
|
|
45
|
+
respond_to do |format|
|
|
46
|
+
# :root => :user is only used here because we need it for the node name of the MongoUser model
|
|
47
|
+
format.xml { render_for_api params[:api_template].to_sym, :xml => @user, :root => :user }
|
|
48
|
+
format.json { render_for_api params[:api_template].to_sym, :json => @user, :root => :user, :meta => meta_hash }
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def show_default
|
|
53
|
+
@user = User.find(params[:id])
|
|
54
|
+
respond_to do |format|
|
|
55
|
+
format.xml { render :xml => @user }
|
|
56
|
+
format.json { render :json => @user }
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def show_prefix_postfix
|
|
61
|
+
@user = User.find(params[:id])
|
|
62
|
+
template = {:template => params[:api_template], :prefix => params[:api_prefix], :postfix => params[:api_postfix]}
|
|
63
|
+
respond_to do |format|
|
|
64
|
+
# :root => :user is only used here because we need it for the node name of the MongoUser model
|
|
65
|
+
format.xml { render_for_api template, :xml => @user, :root => :user }
|
|
66
|
+
format.json { render_for_api template, :json => @user, :root => :user }
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
end
|
|
71
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
class PlainObject < Struct.new(:first_name, :last_name, :age, :active)
|
|
2
|
+
extend ActsAsApi::Base
|
|
3
|
+
|
|
4
|
+
def initialize(opts)
|
|
5
|
+
opts.each do |k, v|
|
|
6
|
+
send("#{k}=", v)
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def model_name
|
|
11
|
+
'plain_object'
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
acts_as_api
|
|
15
|
+
|
|
16
|
+
include SharedEngine::UserTemplate
|
|
17
|
+
end
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
module UserTemplate
|
|
2
|
+
extend ActiveSupport::Concern
|
|
3
|
+
|
|
4
|
+
included do
|
|
5
|
+
api_accessible :name_only do |t|
|
|
6
|
+
t.add :first_name
|
|
7
|
+
t.add :last_name
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
api_accessible :only_full_name do |t|
|
|
11
|
+
t.add :full_name
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
api_accessible :rename_last_name do |t|
|
|
15
|
+
t.add :last_name, :as => :family_name
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
api_accessible :rename_full_name do |t|
|
|
19
|
+
t.add :full_name, :as => :other_full_name
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
api_accessible :with_former_value do |t|
|
|
23
|
+
t.add :first_name
|
|
24
|
+
t.add :last_name
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
api_accessible :age_and_first_name, :extend => :with_former_value do |t|
|
|
28
|
+
t.add :age
|
|
29
|
+
t.remove :last_name
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
api_accessible :calling_a_proc do |t|
|
|
33
|
+
t.add Proc.new{|model| model.full_name.upcase }, :as => :all_caps_name
|
|
34
|
+
t.add Proc.new{|model| Time.now.class.to_s }, :as => :without_param
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
api_accessible :calling_a_lambda do |t|
|
|
38
|
+
t.add lambda{|model| model.full_name.upcase }, :as => :all_caps_name
|
|
39
|
+
t.add lambda{|model| Time.now.class.to_s }, :as => :without_param
|
|
40
|
+
end
|
|
41
|
+
api_accessible :include_tasks do |t|
|
|
42
|
+
t.add :tasks
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
api_accessible :include_profile do |t|
|
|
46
|
+
t.add :profile
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
api_accessible :other_sub_template do |t|
|
|
50
|
+
t.add :first_name
|
|
51
|
+
t.add :tasks, :template => :other_template
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
api_accessible :include_completed_tasks do |t|
|
|
55
|
+
t.add "tasks.completed.all", :as => :completed_tasks
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
api_accessible :sub_node do |t|
|
|
59
|
+
t.add Hash[:foo => :say_something], :as => :sub_nodes
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
api_accessible :nested_sub_node do |t|
|
|
63
|
+
t.add Hash[:foo, Hash[:bar, :last_name]], :as => :sub_nodes
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
api_accessible :nested_sub_hash do |t|
|
|
67
|
+
t.add :sub_hash
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
api_accessible :if_over_thirty do |t|
|
|
71
|
+
t.add :first_name
|
|
72
|
+
t.add :last_name, :if => :over_thirty?
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
api_accessible :if_returns_nil do |t|
|
|
76
|
+
t.add :first_name
|
|
77
|
+
t.add :last_name, :if => :return_nil
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
api_accessible :if_over_thirty_proc do |t|
|
|
81
|
+
t.add :first_name
|
|
82
|
+
t.add :last_name, :if => lambda{|u| u.over_thirty? }
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
api_accessible :if_returns_nil_proc do |t|
|
|
86
|
+
t.add :first_name
|
|
87
|
+
t.add :last_name, :if => lambda{|u| nil }
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
api_accessible :unless_under_thirty do |t|
|
|
91
|
+
t.add :first_name
|
|
92
|
+
t.add :last_name, :unless => :under_thirty?
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
api_accessible :unless_returns_nil do |t|
|
|
96
|
+
t.add :first_name
|
|
97
|
+
t.add :last_name, :unless => :return_nil
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
api_accessible :unless_under_thirty_proc do |t|
|
|
101
|
+
t.add :first_name
|
|
102
|
+
t.add :last_name, :unless => lambda{|u| u.under_thirty? }
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
api_accessible :unless_returns_nil_proc do |t|
|
|
106
|
+
t.add :first_name
|
|
107
|
+
t.add :last_name, :unless => lambda{|u| nil }
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
api_accessible :with_prefix_name_only do |t|
|
|
111
|
+
t.add lambda{|model| 'true' }, :as => :prefix
|
|
112
|
+
t.add :first_name
|
|
113
|
+
t.add :last_name
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
api_accessible :name_only_with_postfix do |t|
|
|
117
|
+
t.add :first_name
|
|
118
|
+
t.add :last_name
|
|
119
|
+
t.add lambda{|model| 'true' }, :as => :postfix
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
api_accessible :with_prefix_name_only_with_postfix do |t|
|
|
123
|
+
t.add lambda{|model| 'true' }, :as => :prefix
|
|
124
|
+
t.add :first_name
|
|
125
|
+
t.add :last_name
|
|
126
|
+
t.add lambda{|model| 'true' }, :as => :postfix
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def before_api_response(api_response)
|
|
130
|
+
@before_api_response_called = true
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def before_api_response_called?
|
|
134
|
+
!!@before_api_response_called
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def after_api_response(api_response)
|
|
138
|
+
@after_api_response_called = true
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def after_api_response_called?
|
|
142
|
+
!!@after_api_response_called
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def skip_api_response=(should_skip)
|
|
146
|
+
@skip_api_response = should_skip
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
def around_api_response(api_response)
|
|
150
|
+
@skip_api_response ? { :skipped => true } : yield
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
end
|
|
154
|
+
end
|