acts_as_api 0.4.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (161) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -7
  3. data/History.txt +5 -0
  4. data/LICENSE.txt +20 -0
  5. data/README.md +0 -25
  6. data/Rakefile +5 -12
  7. data/acts_as_api.gemspec +14 -13
  8. data/{examples/introduction → docs}/docco.css +0 -0
  9. data/{examples/introduction → docs}/index.html +18 -21
  10. data/{examples/introduction → docs}/index.rb +0 -0
  11. data/{examples/introduction → docs}/layout.mustache +0 -0
  12. data/lib/acts_as_api.rb +9 -12
  13. data/lib/acts_as_api/adapters.rb +1 -1
  14. data/lib/acts_as_api/api_template.rb +23 -25
  15. data/lib/acts_as_api/base.rb +11 -20
  16. data/lib/acts_as_api/collection.rb +1 -2
  17. data/lib/acts_as_api/config.rb +0 -5
  18. data/lib/acts_as_api/exceptions.rb +2 -2
  19. data/lib/acts_as_api/rails_renderer.rb +0 -2
  20. data/lib/acts_as_api/rendering.rb +5 -12
  21. data/lib/acts_as_api/responder.rb +8 -13
  22. data/lib/acts_as_api/version.rb +1 -1
  23. data/spec/README.md +15 -6
  24. data/spec/active_record_dummy/Gemfile +2 -10
  25. data/spec/active_record_dummy/app/models/user.rb +31 -32
  26. data/spec/active_record_dummy/config.ru +1 -1
  27. data/spec/active_record_dummy/config/application.rb +2 -2
  28. data/spec/active_record_dummy/config/boot.rb +1 -1
  29. data/spec/active_record_dummy/config/environments/test.rb +2 -2
  30. data/spec/active_record_dummy/config/initializers/session_store.rb +1 -1
  31. data/spec/active_record_dummy/config/initializers/wrap_parameters.rb +1 -1
  32. data/spec/active_record_dummy/config/routes.rb +1 -57
  33. data/spec/active_record_dummy/db/migrate/20110214201640_create_tables.rb +25 -26
  34. data/spec/active_record_dummy/db/schema.rb +27 -29
  35. data/spec/active_record_dummy/script/rails +2 -2
  36. data/spec/controllers/plain_objects_controller_spec.rb +11 -12
  37. data/spec/controllers/respond_with_users_controller_spec.rb +46 -67
  38. data/spec/controllers/users_controller_spec.rb +2 -3
  39. data/spec/models/model_spec.rb +17 -19
  40. data/spec/mongoid_dummy/Gemfile +3 -12
  41. data/spec/mongoid_dummy/app/models/profile.rb +6 -6
  42. data/spec/mongoid_dummy/app/models/task.rb +10 -10
  43. data/spec/mongoid_dummy/app/models/untouched.rb +4 -4
  44. data/spec/mongoid_dummy/app/models/user.rb +12 -14
  45. data/spec/mongoid_dummy/config.ru +1 -1
  46. data/spec/mongoid_dummy/config/application.rb +7 -7
  47. data/spec/mongoid_dummy/config/boot.rb +1 -1
  48. data/spec/mongoid_dummy/config/environments/development.rb +0 -1
  49. data/spec/mongoid_dummy/config/environments/production.rb +0 -1
  50. data/spec/mongoid_dummy/config/environments/test.rb +2 -2
  51. data/spec/mongoid_dummy/config/initializers/include_acts_as_api.rb +1 -1
  52. data/spec/mongoid_dummy/config/initializers/session_store.rb +1 -1
  53. data/spec/mongoid_dummy/config/initializers/wrap_parameters.rb +1 -2
  54. data/spec/mongoid_dummy/config/routes.rb +1 -57
  55. data/spec/mongoid_dummy/script/rails +2 -2
  56. data/spec/shared_engine/Gemfile +1 -1
  57. data/spec/shared_engine/Rakefile +1 -4
  58. data/spec/shared_engine/app/controllers/shared_engine/plain_objects_controller.rb +2 -2
  59. data/spec/shared_engine/app/controllers/shared_engine/respond_with_users_controller.rb +13 -15
  60. data/spec/shared_engine/app/controllers/shared_engine/users_controller.rb +17 -19
  61. data/spec/shared_engine/app/models/plain_object.rb +3 -1
  62. data/spec/shared_engine/app/models/user_template.rb +28 -29
  63. data/spec/shared_engine/lib/shared_engine.rb +1 -1
  64. data/spec/shared_engine/lib/shared_engine/version.rb +1 -1
  65. data/spec/shared_engine/shared_engine.gemspec +10 -12
  66. data/spec/spec_helper.rb +5 -13
  67. data/spec/support/api_test_helpers.rb +0 -2
  68. data/spec/support/controller_examples.rb +128 -173
  69. data/spec/support/it_supports.rb +1 -1
  70. data/spec/support/model_examples/associations.rb +119 -128
  71. data/spec/support/model_examples/callbacks.rb +17 -27
  72. data/spec/support/model_examples/closures.rb +21 -29
  73. data/spec/support/model_examples/conditional_if.rb +71 -103
  74. data/spec/support/model_examples/conditional_unless.rb +71 -103
  75. data/spec/support/model_examples/enabled.rb +5 -6
  76. data/spec/support/model_examples/extending.rb +49 -56
  77. data/spec/support/model_examples/methods.rb +11 -15
  78. data/spec/support/model_examples/options.rb +19 -25
  79. data/spec/support/model_examples/renaming.rb +21 -30
  80. data/spec/support/model_examples/simple.rb +10 -14
  81. data/spec/support/model_examples/sub_nodes.rb +47 -59
  82. data/spec/support/model_examples/undefined.rb +4 -6
  83. data/spec/support/model_examples/untouched.rb +6 -8
  84. data/spec/support/simple_fixtures.rb +11 -38
  85. metadata +22 -159
  86. data/spec/active_record_dummy/app/assets/images/rails.png +0 -0
  87. data/spec/active_record_dummy/app/assets/javascripts/application.js +0 -15
  88. data/spec/active_record_dummy/app/assets/stylesheets/application.css +0 -13
  89. data/spec/active_record_dummy/app/controllers/application_controller.rb +0 -3
  90. data/spec/active_record_dummy/app/helpers/application_helper.rb +0 -2
  91. data/spec/active_record_dummy/app/mailers/.gitkeep +0 -0
  92. data/spec/active_record_dummy/app/views/layouts/application.html.erb +0 -14
  93. data/spec/active_record_dummy/doc/README_FOR_APP +0 -2
  94. data/spec/active_record_dummy/lib/assets/.gitkeep +0 -0
  95. data/spec/active_record_dummy/lib/tasks/.gitkeep +0 -0
  96. data/spec/active_record_dummy/public/404.html +0 -26
  97. data/spec/active_record_dummy/public/422.html +0 -26
  98. data/spec/active_record_dummy/public/500.html +0 -25
  99. data/spec/active_record_dummy/public/favicon.ico +0 -0
  100. data/spec/active_record_dummy/public/index.html +0 -241
  101. data/spec/active_record_dummy/public/robots.txt +0 -5
  102. data/spec/active_record_dummy/vendor/assets/javascripts/.gitkeep +0 -0
  103. data/spec/active_record_dummy/vendor/assets/stylesheets/.gitkeep +0 -0
  104. data/spec/active_record_dummy/vendor/plugins/.gitkeep +0 -0
  105. data/spec/mongoid_dummy/README.rdoc +0 -261
  106. data/spec/mongoid_dummy/app/assets/images/rails.png +0 -0
  107. data/spec/mongoid_dummy/app/assets/javascripts/application.js +0 -15
  108. data/spec/mongoid_dummy/app/assets/stylesheets/application.css +0 -13
  109. data/spec/mongoid_dummy/app/controllers/application_controller.rb +0 -3
  110. data/spec/mongoid_dummy/app/helpers/application_helper.rb +0 -2
  111. data/spec/mongoid_dummy/app/mailers/.gitkeep +0 -0
  112. data/spec/mongoid_dummy/app/views/layouts/application.html.erb +0 -14
  113. data/spec/mongoid_dummy/doc/README_FOR_APP +0 -2
  114. data/spec/mongoid_dummy/lib/assets/.gitkeep +0 -0
  115. data/spec/mongoid_dummy/lib/tasks/.gitkeep +0 -0
  116. data/spec/mongoid_dummy/public/404.html +0 -26
  117. data/spec/mongoid_dummy/public/422.html +0 -26
  118. data/spec/mongoid_dummy/public/500.html +0 -25
  119. data/spec/mongoid_dummy/public/favicon.ico +0 -0
  120. data/spec/mongoid_dummy/public/index.html +0 -241
  121. data/spec/mongoid_dummy/public/robots.txt +0 -5
  122. data/spec/mongoid_dummy/vendor/assets/javascripts/.gitkeep +0 -0
  123. data/spec/mongoid_dummy/vendor/assets/stylesheets/.gitkeep +0 -0
  124. data/spec/mongoid_dummy/vendor/plugins/.gitkeep +0 -0
  125. data/spec/shared_engine/app/assets/images/shared_engine/.gitkeep +0 -0
  126. data/spec/shared_engine/app/assets/javascripts/shared_engine/application.js +0 -15
  127. data/spec/shared_engine/app/assets/stylesheets/shared_engine/application.css +0 -13
  128. data/spec/shared_engine/app/helpers/shared_engine/application_helper.rb +0 -4
  129. data/spec/shared_engine/app/views/layouts/shared_engine/application.html.erb +0 -14
  130. data/spec/shared_engine/dummy/README.rdoc +0 -261
  131. data/spec/shared_engine/dummy/Rakefile +0 -7
  132. data/spec/shared_engine/dummy/app/assets/javascripts/application.js +0 -15
  133. data/spec/shared_engine/dummy/app/assets/stylesheets/application.css +0 -13
  134. data/spec/shared_engine/dummy/app/controllers/application_controller.rb +0 -3
  135. data/spec/shared_engine/dummy/app/helpers/application_helper.rb +0 -2
  136. data/spec/shared_engine/dummy/app/mailers/.gitkeep +0 -0
  137. data/spec/shared_engine/dummy/app/models/.gitkeep +0 -0
  138. data/spec/shared_engine/dummy/app/views/layouts/application.html.erb +0 -14
  139. data/spec/shared_engine/dummy/config.ru +0 -4
  140. data/spec/shared_engine/dummy/config/application.rb +0 -56
  141. data/spec/shared_engine/dummy/config/boot.rb +0 -10
  142. data/spec/shared_engine/dummy/config/database.yml +0 -25
  143. data/spec/shared_engine/dummy/config/environment.rb +0 -5
  144. data/spec/shared_engine/dummy/config/environments/development.rb +0 -34
  145. data/spec/shared_engine/dummy/config/environments/production.rb +0 -63
  146. data/spec/shared_engine/dummy/config/environments/test.rb +0 -37
  147. data/spec/shared_engine/dummy/config/initializers/backtrace_silencers.rb +0 -7
  148. data/spec/shared_engine/dummy/config/initializers/inflections.rb +0 -15
  149. data/spec/shared_engine/dummy/config/initializers/mime_types.rb +0 -5
  150. data/spec/shared_engine/dummy/config/initializers/secret_token.rb +0 -7
  151. data/spec/shared_engine/dummy/config/initializers/session_store.rb +0 -8
  152. data/spec/shared_engine/dummy/config/initializers/wrap_parameters.rb +0 -14
  153. data/spec/shared_engine/dummy/config/locales/en.yml +0 -5
  154. data/spec/shared_engine/dummy/config/routes.rb +0 -4
  155. data/spec/shared_engine/dummy/lib/assets/.gitkeep +0 -0
  156. data/spec/shared_engine/dummy/log/.gitkeep +0 -0
  157. data/spec/shared_engine/dummy/public/404.html +0 -26
  158. data/spec/shared_engine/dummy/public/422.html +0 -26
  159. data/spec/shared_engine/dummy/public/500.html +0 -25
  160. data/spec/shared_engine/dummy/public/favicon.ico +0 -0
  161. data/spec/shared_engine/dummy/script/rails +0 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f83008775d02827f67246d2c3d6de3611318a279
4
- data.tar.gz: 8827a13005d4caaa92561987fa503feea450be86
3
+ metadata.gz: e16fbb94ed887cceb26f045b1249335016a07682
4
+ data.tar.gz: 40ad8d4be72657344be7ad856eb7c83b66dcf389
5
5
  SHA512:
6
- metadata.gz: 8710cf02573c85ca1a902b2d48d42955c251058ac4f01eeb95a26bae402a9158fe8032ed52c82990ffd8cb9d0ec4bbb45a027fd5d2285fd99157585ff8626e29
7
- data.tar.gz: 875d70c8a6ccb93fe4ed2eda2a6a565ae87fca28c37fd8e87e82c360c66ee1a74c113c0bdac5d65b6b917326e31e58e78866d481f0b8462812f3ba3eb4282a43
6
+ metadata.gz: d08be30be0f420cd61e61bb3da1e98b798d420e8c6a8be3afadafa1e897c0c3180f734a2c374baa711afbd07b56b09503fa3dd25eaf041622aa5b119cfbf8917
7
+ data.tar.gz: 68debff236e8e0e78203841aa33c253949b36dfb518c3d5f75f9ad5bc7002ec01090c80dc0b441e57d363b6c141b36d1d2b1adaa60cb226c7900f3683c5383ed
data/Gemfile CHANGED
@@ -1,19 +1,16 @@
1
- source "http://rubygems.org"
1
+ source 'http://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in acts_as_api.gemspec
4
4
  gemspec
5
5
 
6
6
  group :test do
7
7
  gem 'pry'
8
- gem 'test-unit', '~> 3.0'
9
8
  gem 'sqlite3'
10
9
  gem 'mongoid', '>= 6.0.2'
11
- gem 'rspec', '>= 2.9.0'
12
- gem 'rspec-its'
10
+ gem 'rspec', '>= 3.5.0'
13
11
  gem 'rspec-collection_matchers'
14
12
  gem 'capybara'
15
- gem 'rspec-rails', '>= 2.5.0'
16
- gem 'webrat'
13
+ gem 'rspec-rails', '>= 3.5.0'
17
14
  gem 'responders'
18
- gem 'shared_engine', :path => './spec/shared_engine'
15
+ gem 'shared_engine', path: './spec/shared_engine'
19
16
  end
@@ -1,3 +1,8 @@
1
+ === 1.0.0 2016-11-24
2
+
3
+ * Ditch Ruby 1.8 syntax, overall modernization
4
+ * Finally, 1.0!
5
+
1
6
  === 0.4.4 2016-11-09
2
7
 
3
8
  * Updates spec suite to Rails 5
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Christian Bäuerlein
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 NONINFRINGEMENT.
17
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -84,28 +84,3 @@ There are a lot of how-tos like:
84
84
 
85
85
  Note that upgrading to 0.3.0 will break code that worked with previous versions due to a complete overhaul of the lib.
86
86
  For a legacy version of this readme file look here: https://github.com/fabrik42/acts_as_api/wiki/legacy-acts_as_api-0.2-readme
87
-
88
- ### LICENSE:
89
-
90
- (The MIT License)
91
-
92
- Copyright (c) 2010 Christian Bäuerlein
93
-
94
- Permission is hereby granted, free of charge, to any person obtaining
95
- a copy of this software and associated documentation files (the
96
- 'Software'), to deal in the Software without restriction, including
97
- without limitation the rights to use, copy, modify, merge, publish,
98
- distribute, sublicense, and/or sell copies of the Software, and to
99
- permit persons to whom the Software is furnished to do so, subject to
100
- the following conditions:
101
-
102
- The above copyright notice and this permission notice shall be
103
- included in all copies or substantial portions of the Software.
104
-
105
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
106
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
107
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
108
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
109
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
110
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
111
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -7,13 +7,12 @@ Bundler::GemHelper.install_tasks
7
7
  RSpec::Core::RakeTask.new
8
8
 
9
9
  namespace :spec do
10
-
11
10
  supported_orms = %w(mongoid active_record)
12
11
 
13
12
  supported_orms.each do |orm|
14
13
  desc "Run #{orm} specs only"
15
14
  RSpec::Core::RakeTask.new(orm) do |t|
16
- t.rspec_opts = ["--color"]
15
+ t.rspec_opts = ['--color']
17
16
  end
18
17
 
19
18
  task "prepare_#{orm}" do
@@ -23,26 +22,20 @@ namespace :spec do
23
22
  Rake::Task["spec:#{orm}"].prerequisites << "spec:prepare_#{orm}"
24
23
  end
25
24
 
26
-
27
- # task :all => supported_orms.map{|orm| "spec:#{orm}"}
28
-
29
25
  desc "Runs specs for all ORMs (#{supported_orms.join(', ')})"
30
26
  task :all do
31
27
  supported_orms.each do |orm|
32
28
  puts "Starting to run specs for #{orm}..."
33
29
  system("bundle exec rake spec:#{orm}")
34
- raise "#{orm} failed!" unless $?.exitstatus == 0
30
+ raise "#{orm} failed!" unless $?.exitstatus.zero?
35
31
  end
36
32
  end
37
33
 
38
34
  end
39
35
 
36
+ task default: 'spec:all'
40
37
 
41
- gemspec = Gem::Specification.load("acts_as_api.gemspec")
42
-
43
- task :default => "spec:all"
44
-
45
- desc "Generate the gh_pages site"
38
+ desc 'Generate the gh_pages site'
46
39
  task :rocco do
47
- system "bundle exec rocco examples/introduction/index.rb -t examples/introduction/layout.mustache"
40
+ system 'bundle exec rocco docs/index.rb -t docs/layout.mustache'
48
41
  end
@@ -1,28 +1,29 @@
1
1
  # encoding: utf-8
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "acts_as_api/version"
2
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
3
+ require 'acts_as_api/version'
4
4
 
5
5
  Gem::Specification.new do |s|
6
- s.name = "acts_as_api"
6
+ s.name = 'acts_as_api'
7
7
  s.version = ActsAsApi::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
- s.authors = ["Christian Bäuerlein"]
10
- s.email = ["christian@ffwdme.com"]
11
- s.homepage = "https://github.com/fabrik42/acts_as_api"
12
- s.summary = %q{Makes creating XML/JSON responses in Rails 3, 4 and 5 easy and fun.}
13
- s.description = %q{acts_as_api enriches the models and controllers of your app in a rails-like way so you can easily determine how your XML/JSON API responses should look like.}
9
+ s.authors = ['Christian Bäuerlein']
10
+ s.email = ['christian@ffwdme.com']
11
+ s.homepage = 'https://github.com/fabrik42/acts_as_api'
12
+ s.summary = 'Makes creating XML/JSON responses in Rails 3, 4 and 5 easy and fun.'
13
+ s.description = 'acts_as_api enriches the models and controllers of your app in a rails-like way so you can easily determine how your XML/JSON API responses should look like.'
14
14
 
15
- s.add_dependency('activemodel','>= 3.0.0')
16
- s.add_dependency('activesupport','>= 3.0.0')
17
- s.add_dependency('rack','>= 1.1.0')
15
+ s.add_dependency('activemodel', '>= 3.0.0')
16
+ s.add_dependency('activesupport', '>= 3.0.0')
17
+ s.add_dependency('rack', '>= 1.1.0')
18
18
 
19
19
  s.add_development_dependency('rails', ['>= 3.2.22.2'])
20
20
  s.add_development_dependency('mongoid', ['>= 3.0.1'])
21
+ s.add_development_dependency('rocco', ['>= 0.8.0'])
21
22
 
22
23
  s.rdoc_options = ['--charset=UTF-8']
23
24
 
24
25
  s.files = `git ls-files`.split("\n")
25
26
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
26
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
27
- s.require_paths = ["lib"]
27
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
28
+ s.require_paths = ['lib']
28
29
  end
@@ -44,10 +44,10 @@
44
44
  <p>The built-in XML/JSON support of Rails is great but:
45
45
  You surely don’t want to expose your models always with all attributes.</p>
46
46
 
47
- <p>acts_as_api enriches the models and controllers of your app in a rails-like way so you can easily determine how your API responses should look like.</p>
47
+ <p>acts<em>as</em>api enriches the models and controllers of your app in a rails-like way so you can easily determine how your API responses should look like.</p>
48
48
  </td>
49
49
  <td class=code>
50
- <div class='highlight'><pre></pre></div>
50
+ <div class='highlight'><pre><span></span></pre></div>
51
51
  </td>
52
52
  </tr>
53
53
  <tr id='section-Features'>
@@ -60,17 +60,16 @@ You surely don’t want to expose your models always with all attributes.</p>
60
60
  <ul>
61
61
  <li>DRY templates for your api responses</li>
62
62
  <li>Ships with support for <strong>ActiveRecord</strong> and <strong>Mongoid</strong></li>
63
- <li>Support for Rails 3/4 Responders (extracted to responders gem since Rails 5)</li>
63
+ <li>Support for Rails 3, 4 and 5 Responders</li>
64
64
  <li>Plays very well together with client libs like <a href="http://documentcloud.github.com/backbone">Backbone.js</a> or <a href="http://restkit.org">RestKit</a> (iOS).</li>
65
65
  <li>Easy but very flexible syntax for defining the templates</li>
66
66
  <li>XML, JSON and JSON-P support out of the box, easy to extend</li>
67
- <li>Support for meta data like pagination info, etc&hellip;</li>
67
+ <li>Support for meta data like pagination info, etc...</li>
68
68
  <li>Minimal dependecies (you can also use it without Rails)</li>
69
69
  <li>Supports multiple api rendering templates for a models. This is especially useful for API versioning or for example for private vs. public access points to a user’s profile.</li>
70
70
  </ul>
71
71
 
72
-
73
- <hr />
72
+ <hr>
74
73
  </td>
75
74
  <td class=code>
76
75
  <div class='highlight'><pre></pre></div>
@@ -81,7 +80,7 @@ You surely don’t want to expose your models always with all attributes.</p>
81
80
  <div class="pilwrap">
82
81
  <a class="pilcrow" href="#section-Rails_3.x_Quickstart">&#182;</a>
83
82
  </div>
84
- <h2>Rails Quickstart</h2>
83
+ <h2>Rails 3.x Quickstart</h2>
85
84
  </td>
86
85
  <td class=code>
87
86
  <div class='highlight'><pre></pre></div>
@@ -139,7 +138,7 @@ If you only want to expose the <code>first_name</code> and <code>last_name</code
139
138
  </div>
140
139
  <p>Within your model:</p>
141
140
 
142
- <p>First you activate acts_as_api for your model by calling <code>acts_as_api</code>.</p>
141
+ <p>First you activate acts<em>as</em>api for your model by calling <code>acts_as_api</code>.</p>
143
142
 
144
143
  <p>Then you define an api template to render the model with <code>api_accessible</code>.</p>
145
144
  </td>
@@ -199,7 +198,7 @@ If you only want to expose the <code>first_name</code> and <code>last_name</code
199
198
  <div class="pilwrap">
200
199
  <a class="pilcrow" href="#section-12">&#182;</a>
201
200
  </div>
202
- <p>Note that it&rsquo;s wise to add a <code>root</code> param when rendering lists.</p>
201
+ <p>Note that it&#39;s wise to add a <code>root</code> param when rendering lists.</p>
203
202
  </td>
204
203
  <td class=code>
205
204
  <div class='highlight'><pre> <span class="n">respond_to</span> <span class="k">do</span> <span class="o">|</span><span class="nb">format</span><span class="o">|</span>
@@ -220,12 +219,12 @@ If you only want to expose the <code>first_name</code> and <code>last_name</code
220
219
  <span class="k">end</span></pre></div>
221
220
  </td>
222
221
  </tr>
223
- <tr id='section-That&amp;rsquo;s_it!'>
222
+ <tr id='section-That&amp;#39;s_it!'>
224
223
  <td class=docs>
225
224
  <div class="pilwrap">
226
- <a class="pilcrow" href="#section-That&amp;rsquo;s_it!">&#182;</a>
225
+ <a class="pilcrow" href="#section-That&amp;#39;s_it!">&#182;</a>
227
226
  </div>
228
- <h3>That&rsquo;s it!</h3>
227
+ <h3>That&#39;s it!</h3>
229
228
  </td>
230
229
  <td class=code>
231
230
  <div class='highlight'><pre></pre></div>
@@ -255,20 +254,20 @@ because they were not listed by <code>api_accessible</code> in the model.</p>
255
254
  <div class="pilwrap">
256
255
  <a class="pilcrow" href="#section-15">&#182;</a>
257
256
  </div>
258
- <hr />
257
+ <hr>
259
258
  </td>
260
259
  <td class=code>
261
260
  <div class='highlight'><pre></pre></div>
262
261
  </td>
263
262
  </tr>
264
- <tr id='section-But_wait!_&amp;hellip;_there&amp;rsquo;s_more'>
263
+ <tr id='section-But_wait!_..._there&amp;#39;s_more'>
265
264
  <td class=docs>
266
265
  <div class="pilwrap">
267
- <a class="pilcrow" href="#section-But_wait!_&amp;hellip;_there&amp;rsquo;s_more">&#182;</a>
266
+ <a class="pilcrow" href="#section-But_wait!_..._there&amp;#39;s_more">&#182;</a>
268
267
  </div>
269
- <h2>But wait! &hellip; there&rsquo;s more</h2>
268
+ <h2>But wait! ... there&#39;s more</h2>
270
269
 
271
- <p>Often the pure rendering of database values is just not enough, so acts_as_api
270
+ <p>Often the pure rendering of database values is just not enough, so acts<em>as</em>api
272
271
  provides you some tools to customize your API responses.</p>
273
272
  </td>
274
273
  <td class=code>
@@ -286,7 +285,7 @@ provides you some tools to customize your API responses.</p>
286
285
 
287
286
  <ul>
288
287
  <li><a href="https://github.com/fabrik42/acts_as_api/wiki/Calling-a-method-of-the-model">Include attributes and all other kinds of methods of your model</a></li>
289
- <li><a href="https://github.com/fabrik42/acts_as_api/wiki/Including-a-child-association">Include child associations (if they also act_as_api this will be considered)</a></li>
288
+ <li><a href="https://github.com/fabrik42/acts_as_api/wiki/Including-a-child-association">Include child associations (if they also act<em>as</em>api this will be considered)</a></li>
290
289
  <li><a href="https://github.com/fabrik42/acts_as_api/wiki/Calling-a-lambda-in-the-api-template">Include lambdas and Procs</a></li>
291
290
  <li><a href="https://github.com/fabrik42/acts_as_api/wiki/Calling-a-method-of-the-model">Call methods of a parent association</a></li>
292
291
  <li><a href="https://github.com/fabrik42/acts_as_api/wiki/Calling-a-scope-of-a-sub-resource">Call scopes of your model or child associations</a></li>
@@ -294,7 +293,6 @@ provides you some tools to customize your API responses.</p>
294
293
  <li><a href="https://github.com/fabrik42/acts_as_api/wiki/Creating-a-completely-different-response-structure">Create your own hierarchies</a></li>
295
294
  </ul>
296
295
 
297
-
298
296
  <p>You can find more advanced examples in the <a href="https://github.com/fabrik42/acts_as_api/wiki/">Github Wiki</a></p>
299
297
  </td>
300
298
  <td class=code>
@@ -306,7 +304,7 @@ provides you some tools to customize your API responses.</p>
306
304
  <div class="pilwrap">
307
305
  <a class="pilcrow" href="#section-18">&#182;</a>
308
306
  </div>
309
- <hr />
307
+ <hr>
310
308
  </td>
311
309
  <td class=code>
312
310
  <div class='highlight'><pre></pre></div>
@@ -326,7 +324,6 @@ provides you some tools to customize your API responses.</p>
326
324
  <li><a href="http://rdoc.info/github/fabrik42/acts_as_api">Docs</a></li>
327
325
  </ul>
328
326
 
329
-
330
327
  </td>
331
328
  <td class=code>
332
329
  <div class='highlight'><pre></pre></div>
File without changes
@@ -1,12 +1,9 @@
1
1
  require 'active_model'
2
2
  require 'active_support/core_ext/class'
3
3
 
4
- $:.unshift(File.dirname(__FILE__)) unless
5
- $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
6
-
7
- require "acts_as_api/collection"
8
- require "acts_as_api/rails_renderer"
9
- require "acts_as_api/exceptions"
4
+ require 'acts_as_api/collection'
5
+ require 'acts_as_api/rails_renderer'
6
+ require 'acts_as_api/exceptions'
10
7
 
11
8
  # acts_as_api is a gem that aims to make the construction of JSON and XML
12
9
  # responses in Rails 3, 4 and 5 easy and fun.
@@ -17,12 +14,12 @@ require "acts_as_api/exceptions"
17
14
  # acts_as_api uses the default serializers of your rails app and doesn't
18
15
  # force you into more dependencies.
19
16
  module ActsAsApi
20
- autoload :Config, "acts_as_api/config"
21
- autoload :ApiTemplate, "acts_as_api/api_template"
22
- autoload :Base, "acts_as_api/base"
23
- autoload :Rendering, "acts_as_api/rendering"
24
- autoload :Responder, "acts_as_api/responder"
25
- autoload :Adapters, "acts_as_api/adapters"
17
+ autoload :Config, 'acts_as_api/config'
18
+ autoload :ApiTemplate, 'acts_as_api/api_template'
19
+ autoload :Base, 'acts_as_api/base'
20
+ autoload :Rendering, 'acts_as_api/rendering'
21
+ autoload :Responder, 'acts_as_api/responder'
22
+ autoload :Adapters, 'acts_as_api/adapters'
26
23
  end
27
24
 
28
25
  # Neccessary to render an Array of models, e.g. the result of a search.
@@ -1,5 +1,5 @@
1
1
  module ActsAsApi
2
2
  module Adapters
3
- autoload :Mongoid, "acts_as_api/adapters/mongoid"
3
+ autoload :Mongoid, 'acts_as_api/adapters/mongoid'
4
4
  end
5
5
  end
@@ -8,7 +8,6 @@ module ActsAsApi
8
8
  # Please note that +ApiTemplate+ inherits from +Hash+ so you can use all
9
9
  # kind of +Hash+ and +Enumerable+ methods to manipulate the template.
10
10
  class ApiTemplate < Hash
11
-
12
11
  # The name of the api template as a Symbol.
13
12
  attr_accessor :api_template
14
13
 
@@ -21,7 +20,7 @@ module ActsAsApi
21
20
 
22
21
  def merge!(other_hash, &block)
23
22
  super
24
- self.options.merge!(other_hash.options) if other_hash.respond_to?(:options)
23
+ options.merge!(other_hash.options) if other_hash.respond_to?(:options)
25
24
  end
26
25
 
27
26
  # Adds a field to the api template
@@ -44,7 +43,7 @@ module ActsAsApi
44
43
 
45
44
  # Removes a field from the template
46
45
  def remove(field)
47
- self.delete(field)
46
+ delete(field)
48
47
  end
49
48
 
50
49
  # Returns the options of a field in the api template
@@ -67,9 +66,9 @@ module ActsAsApi
67
66
  # the response based on the conditional options passed.
68
67
  def allowed_to_render?(fieldset, field, model, options)
69
68
  return true unless fieldset.is_a? ActsAsApi::ApiTemplate
70
-
69
+
71
70
  fieldset_options = fieldset.options_for(field)
72
-
71
+
73
72
  if fieldset_options[:unless]
74
73
  !(condition_fulfilled?(model, fieldset_options[:unless], options))
75
74
  elsif fieldset_options[:if]
@@ -112,28 +111,27 @@ module ActsAsApi
112
111
  api_output
113
112
  end
114
113
 
115
- private
116
-
117
- def process_value(model, value, options)
118
- case value
119
- when Symbol
120
- model.send(value)
121
- when Proc
122
- call_proc(value,model,options)
123
- when String
124
- value.split('.').inject(model) { |result, method| result.send(method) }
125
- when Hash
126
- to_response_hash(model, value)
114
+ private
115
+
116
+ def process_value(model, value, options)
117
+ case value
118
+ when Symbol
119
+ model.send(value)
120
+ when Proc
121
+ call_proc(value, model, options)
122
+ when String
123
+ value.split('.').inject(model) { |result, method| result.send(method) }
124
+ when Hash
125
+ to_response_hash(model, value)
126
+ end
127
127
  end
128
- end
129
128
 
130
- def call_proc(the_proc,model,options)
131
- if the_proc.arity == 2
132
- the_proc.call(model, options)
133
- else
134
- the_proc.call(model)
129
+ def call_proc(the_proc, model, options)
130
+ if the_proc.arity == 2
131
+ the_proc.call(model, options)
132
+ else
133
+ the_proc.call(model)
134
+ end
135
135
  end
136
- end
137
-
138
136
  end
139
137
  end