acts_as_api_sequel 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (206) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/.travis.yml +5 -0
  4. data/Gemfile +13 -0
  5. data/History.txt +108 -0
  6. data/README.md +126 -0
  7. data/Rakefile +48 -0
  8. data/acts_as_api.gemspec +28 -0
  9. data/examples/introduction/docco.css +186 -0
  10. data/examples/introduction/index.html +338 -0
  11. data/examples/introduction/index.rb +144 -0
  12. data/examples/introduction/layout.mustache +67 -0
  13. data/lib/acts_as_api.rb +46 -0
  14. data/lib/acts_as_api/adapters.rb +5 -0
  15. data/lib/acts_as_api/adapters/mongoid.rb +11 -0
  16. data/lib/acts_as_api/api_template.rb +139 -0
  17. data/lib/acts_as_api/array.rb +21 -0
  18. data/lib/acts_as_api/base.rb +88 -0
  19. data/lib/acts_as_api/config.rb +58 -0
  20. data/lib/acts_as_api/exceptions.rb +4 -0
  21. data/lib/acts_as_api/rails_renderer.rb +17 -0
  22. data/lib/acts_as_api/rendering.rb +95 -0
  23. data/lib/acts_as_api/responder.rb +39 -0
  24. data/lib/acts_as_api/version.rb +3 -0
  25. data/spec/README.md +55 -0
  26. data/spec/active_record_dummy/.gitignore +15 -0
  27. data/spec/active_record_dummy/Gemfile +16 -0
  28. data/spec/active_record_dummy/README.rdoc +261 -0
  29. data/spec/active_record_dummy/Rakefile +7 -0
  30. data/spec/active_record_dummy/app/assets/images/rails.png +0 -0
  31. data/spec/active_record_dummy/app/assets/javascripts/application.js +15 -0
  32. data/spec/active_record_dummy/app/assets/stylesheets/application.css +13 -0
  33. data/spec/active_record_dummy/app/controllers/application_controller.rb +3 -0
  34. data/spec/active_record_dummy/app/helpers/application_helper.rb +2 -0
  35. data/spec/active_record_dummy/app/mailers/.gitkeep +0 -0
  36. data/spec/active_record_dummy/app/models/.gitkeep +0 -0
  37. data/spec/active_record_dummy/app/models/profile.rb +4 -0
  38. data/spec/active_record_dummy/app/models/task.rb +4 -0
  39. data/spec/active_record_dummy/app/models/untouched.rb +2 -0
  40. data/spec/active_record_dummy/app/models/user.rb +186 -0
  41. data/spec/active_record_dummy/app/views/layouts/application.html.erb +14 -0
  42. data/spec/active_record_dummy/config.ru +4 -0
  43. data/spec/active_record_dummy/config/application.rb +59 -0
  44. data/spec/active_record_dummy/config/boot.rb +6 -0
  45. data/spec/active_record_dummy/config/database.yml +25 -0
  46. data/spec/active_record_dummy/config/environment.rb +5 -0
  47. data/spec/active_record_dummy/config/environments/development.rb +37 -0
  48. data/spec/active_record_dummy/config/environments/production.rb +67 -0
  49. data/spec/active_record_dummy/config/environments/test.rb +37 -0
  50. data/spec/active_record_dummy/config/initializers/backtrace_silencers.rb +7 -0
  51. data/spec/active_record_dummy/config/initializers/generators.rb +2 -0
  52. data/spec/active_record_dummy/config/initializers/inflections.rb +15 -0
  53. data/spec/active_record_dummy/config/initializers/mime_types.rb +5 -0
  54. data/spec/active_record_dummy/config/initializers/secret_token.rb +7 -0
  55. data/spec/active_record_dummy/config/initializers/session_store.rb +8 -0
  56. data/spec/active_record_dummy/config/initializers/wrap_parameters.rb +14 -0
  57. data/spec/active_record_dummy/config/locales/en.yml +5 -0
  58. data/spec/active_record_dummy/config/routes.rb +59 -0
  59. data/spec/active_record_dummy/db/migrate/20110214201640_create_tables.rb +44 -0
  60. data/spec/active_record_dummy/db/schema.rb +47 -0
  61. data/spec/active_record_dummy/db/seeds.rb +7 -0
  62. data/spec/active_record_dummy/doc/README_FOR_APP +2 -0
  63. data/spec/active_record_dummy/lib/assets/.gitkeep +0 -0
  64. data/spec/active_record_dummy/lib/tasks/.gitkeep +0 -0
  65. data/spec/active_record_dummy/log/.gitkeep +0 -0
  66. data/spec/active_record_dummy/public/404.html +26 -0
  67. data/spec/active_record_dummy/public/422.html +26 -0
  68. data/spec/active_record_dummy/public/500.html +25 -0
  69. data/spec/active_record_dummy/public/favicon.ico +0 -0
  70. data/spec/active_record_dummy/public/index.html +241 -0
  71. data/spec/active_record_dummy/public/robots.txt +5 -0
  72. data/spec/active_record_dummy/script/rails +6 -0
  73. data/spec/active_record_dummy/vendor/assets/javascripts/.gitkeep +0 -0
  74. data/spec/active_record_dummy/vendor/assets/stylesheets/.gitkeep +0 -0
  75. data/spec/active_record_dummy/vendor/plugins/.gitkeep +0 -0
  76. data/spec/controllers/plain_objects_controller_spec.rb +36 -0
  77. data/spec/controllers/respond_with_users_controller_spec.rb +142 -0
  78. data/spec/controllers/users_controller_spec.rb +15 -0
  79. data/spec/models/model_spec.rb +31 -0
  80. data/spec/mongoid_dummy/.gitignore +15 -0
  81. data/spec/mongoid_dummy/Gemfile +18 -0
  82. data/spec/mongoid_dummy/README.rdoc +261 -0
  83. data/spec/mongoid_dummy/Rakefile +7 -0
  84. data/spec/mongoid_dummy/app/assets/images/rails.png +0 -0
  85. data/spec/mongoid_dummy/app/assets/javascripts/application.js +15 -0
  86. data/spec/mongoid_dummy/app/assets/stylesheets/application.css +13 -0
  87. data/spec/mongoid_dummy/app/controllers/application_controller.rb +3 -0
  88. data/spec/mongoid_dummy/app/helpers/application_helper.rb +2 -0
  89. data/spec/mongoid_dummy/app/mailers/.gitkeep +0 -0
  90. data/spec/mongoid_dummy/app/models/.gitkeep +0 -0
  91. data/spec/mongoid_dummy/app/models/profile.rb +10 -0
  92. data/spec/mongoid_dummy/app/models/task.rb +12 -0
  93. data/spec/mongoid_dummy/app/models/untouched.rb +7 -0
  94. data/spec/mongoid_dummy/app/models/user.rb +48 -0
  95. data/spec/mongoid_dummy/app/views/layouts/application.html.erb +14 -0
  96. data/spec/mongoid_dummy/config.ru +4 -0
  97. data/spec/mongoid_dummy/config/application.rb +65 -0
  98. data/spec/mongoid_dummy/config/boot.rb +6 -0
  99. data/spec/mongoid_dummy/config/environment.rb +5 -0
  100. data/spec/mongoid_dummy/config/environments/development.rb +31 -0
  101. data/spec/mongoid_dummy/config/environments/production.rb +64 -0
  102. data/spec/mongoid_dummy/config/environments/test.rb +35 -0
  103. data/spec/mongoid_dummy/config/initializers/backtrace_silencers.rb +7 -0
  104. data/spec/mongoid_dummy/config/initializers/generators.rb +2 -0
  105. data/spec/mongoid_dummy/config/initializers/include_acts_as_api.rb +3 -0
  106. data/spec/mongoid_dummy/config/initializers/inflections.rb +15 -0
  107. data/spec/mongoid_dummy/config/initializers/mime_types.rb +5 -0
  108. data/spec/mongoid_dummy/config/initializers/secret_token.rb +7 -0
  109. data/spec/mongoid_dummy/config/initializers/session_store.rb +8 -0
  110. data/spec/mongoid_dummy/config/initializers/wrap_parameters.rb +10 -0
  111. data/spec/mongoid_dummy/config/locales/en.yml +5 -0
  112. data/spec/mongoid_dummy/config/mongoid.yml +120 -0
  113. data/spec/mongoid_dummy/config/routes.rb +59 -0
  114. data/spec/mongoid_dummy/db/seeds.rb +7 -0
  115. data/spec/mongoid_dummy/doc/README_FOR_APP +2 -0
  116. data/spec/mongoid_dummy/lib/assets/.gitkeep +0 -0
  117. data/spec/mongoid_dummy/lib/tasks/.gitkeep +0 -0
  118. data/spec/mongoid_dummy/log/.gitkeep +0 -0
  119. data/spec/mongoid_dummy/public/404.html +26 -0
  120. data/spec/mongoid_dummy/public/422.html +26 -0
  121. data/spec/mongoid_dummy/public/500.html +25 -0
  122. data/spec/mongoid_dummy/public/favicon.ico +0 -0
  123. data/spec/mongoid_dummy/public/index.html +241 -0
  124. data/spec/mongoid_dummy/public/robots.txt +5 -0
  125. data/spec/mongoid_dummy/script/rails +6 -0
  126. data/spec/mongoid_dummy/vendor/assets/javascripts/.gitkeep +0 -0
  127. data/spec/mongoid_dummy/vendor/assets/stylesheets/.gitkeep +0 -0
  128. data/spec/mongoid_dummy/vendor/plugins/.gitkeep +0 -0
  129. data/spec/shared_engine/.gitignore +7 -0
  130. data/spec/shared_engine/Gemfile +14 -0
  131. data/spec/shared_engine/MIT-LICENSE +20 -0
  132. data/spec/shared_engine/README.rdoc +3 -0
  133. data/spec/shared_engine/Rakefile +29 -0
  134. data/spec/shared_engine/app/assets/images/shared_engine/.gitkeep +0 -0
  135. data/spec/shared_engine/app/assets/javascripts/shared_engine/application.js +15 -0
  136. data/spec/shared_engine/app/assets/stylesheets/shared_engine/application.css +13 -0
  137. data/spec/shared_engine/app/controllers/shared_engine/application_controller.rb +4 -0
  138. data/spec/shared_engine/app/controllers/shared_engine/plain_objects_controller.rb +14 -0
  139. data/spec/shared_engine/app/controllers/shared_engine/respond_with_users_controller.rb +64 -0
  140. data/spec/shared_engine/app/controllers/shared_engine/users_controller.rb +71 -0
  141. data/spec/shared_engine/app/helpers/shared_engine/application_helper.rb +4 -0
  142. data/spec/shared_engine/app/models/plain_object.rb +17 -0
  143. data/spec/shared_engine/app/models/user_template.rb +154 -0
  144. data/spec/shared_engine/app/views/layouts/shared_engine/application.html.erb +14 -0
  145. data/spec/shared_engine/config/routes.rb +28 -0
  146. data/spec/shared_engine/dummy/README.rdoc +261 -0
  147. data/spec/shared_engine/dummy/Rakefile +7 -0
  148. data/spec/shared_engine/dummy/app/assets/javascripts/application.js +15 -0
  149. data/spec/shared_engine/dummy/app/assets/stylesheets/application.css +13 -0
  150. data/spec/shared_engine/dummy/app/controllers/application_controller.rb +3 -0
  151. data/spec/shared_engine/dummy/app/helpers/application_helper.rb +2 -0
  152. data/spec/shared_engine/dummy/app/mailers/.gitkeep +0 -0
  153. data/spec/shared_engine/dummy/app/models/.gitkeep +0 -0
  154. data/spec/shared_engine/dummy/app/views/layouts/application.html.erb +14 -0
  155. data/spec/shared_engine/dummy/config.ru +4 -0
  156. data/spec/shared_engine/dummy/config/application.rb +62 -0
  157. data/spec/shared_engine/dummy/config/boot.rb +10 -0
  158. data/spec/shared_engine/dummy/config/database.yml +25 -0
  159. data/spec/shared_engine/dummy/config/environment.rb +5 -0
  160. data/spec/shared_engine/dummy/config/environments/development.rb +37 -0
  161. data/spec/shared_engine/dummy/config/environments/production.rb +67 -0
  162. data/spec/shared_engine/dummy/config/environments/test.rb +37 -0
  163. data/spec/shared_engine/dummy/config/initializers/backtrace_silencers.rb +7 -0
  164. data/spec/shared_engine/dummy/config/initializers/inflections.rb +15 -0
  165. data/spec/shared_engine/dummy/config/initializers/mime_types.rb +5 -0
  166. data/spec/shared_engine/dummy/config/initializers/secret_token.rb +7 -0
  167. data/spec/shared_engine/dummy/config/initializers/session_store.rb +8 -0
  168. data/spec/shared_engine/dummy/config/initializers/wrap_parameters.rb +14 -0
  169. data/spec/shared_engine/dummy/config/locales/en.yml +5 -0
  170. data/spec/shared_engine/dummy/config/routes.rb +4 -0
  171. data/spec/shared_engine/dummy/lib/assets/.gitkeep +0 -0
  172. data/spec/shared_engine/dummy/log/.gitkeep +0 -0
  173. data/spec/shared_engine/dummy/public/404.html +26 -0
  174. data/spec/shared_engine/dummy/public/422.html +26 -0
  175. data/spec/shared_engine/dummy/public/500.html +25 -0
  176. data/spec/shared_engine/dummy/public/favicon.ico +0 -0
  177. data/spec/shared_engine/dummy/script/rails +6 -0
  178. data/spec/shared_engine/lib/magic/rails/engine.rb +69 -0
  179. data/spec/shared_engine/lib/shared_engine.rb +4 -0
  180. data/spec/shared_engine/lib/shared_engine/engine.rb +5 -0
  181. data/spec/shared_engine/lib/shared_engine/version.rb +3 -0
  182. data/spec/shared_engine/lib/tasks/shared_engine_tasks.rake +4 -0
  183. data/spec/shared_engine/script/rails +8 -0
  184. data/spec/shared_engine/shared_engine.gemspec +22 -0
  185. data/spec/spec.opts +1 -0
  186. data/spec/spec_helper.rb +22 -0
  187. data/spec/support/api_test_helpers.rb +23 -0
  188. data/spec/support/controller_examples.rb +458 -0
  189. data/spec/support/it_supports.rb +3 -0
  190. data/spec/support/model_examples/associations.rb +272 -0
  191. data/spec/support/model_examples/callbacks.rb +38 -0
  192. data/spec/support/model_examples/closures.rb +49 -0
  193. data/spec/support/model_examples/conditional_if.rb +165 -0
  194. data/spec/support/model_examples/conditional_unless.rb +165 -0
  195. data/spec/support/model_examples/enabled.rb +10 -0
  196. data/spec/support/model_examples/extending.rb +112 -0
  197. data/spec/support/model_examples/methods.rb +23 -0
  198. data/spec/support/model_examples/options.rb +53 -0
  199. data/spec/support/model_examples/renaming.rb +50 -0
  200. data/spec/support/model_examples/simple.rb +23 -0
  201. data/spec/support/model_examples/sub_nodes.rb +105 -0
  202. data/spec/support/model_examples/undefined.rb +7 -0
  203. data/spec/support/model_examples/untouched.rb +13 -0
  204. data/spec/support/routing.rb +4 -0
  205. data/spec/support/simple_fixtures.rb +59 -0
  206. metadata +499 -0
@@ -0,0 +1,5 @@
1
+ # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
2
+ #
3
+ # To ban all spiders from the entire site uncomment the next two lines:
4
+ # User-Agent: *
5
+ # Disallow: /
@@ -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'
@@ -0,0 +1,7 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ dummy/db/*.sqlite3
5
+ dummy/log/*.log
6
+ dummy/tmp/
7
+ dummy/.sass-cache
@@ -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,3 @@
1
+ = SharedEngine
2
+
3
+ This project rocks and uses MIT-LICENSE.
@@ -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
+
@@ -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,4 @@
1
+ module SharedEngine
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -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,4 @@
1
+ module SharedEngine
2
+ module ApplicationHelper
3
+ end
4
+ 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