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.
- checksums.yaml +4 -4
- data/Gemfile +4 -7
- data/History.txt +5 -0
- data/LICENSE.txt +20 -0
- data/README.md +0 -25
- data/Rakefile +5 -12
- data/acts_as_api.gemspec +14 -13
- data/{examples/introduction → docs}/docco.css +0 -0
- data/{examples/introduction → docs}/index.html +18 -21
- data/{examples/introduction → docs}/index.rb +0 -0
- data/{examples/introduction → docs}/layout.mustache +0 -0
- data/lib/acts_as_api.rb +9 -12
- data/lib/acts_as_api/adapters.rb +1 -1
- data/lib/acts_as_api/api_template.rb +23 -25
- data/lib/acts_as_api/base.rb +11 -20
- data/lib/acts_as_api/collection.rb +1 -2
- data/lib/acts_as_api/config.rb +0 -5
- data/lib/acts_as_api/exceptions.rb +2 -2
- data/lib/acts_as_api/rails_renderer.rb +0 -2
- data/lib/acts_as_api/rendering.rb +5 -12
- data/lib/acts_as_api/responder.rb +8 -13
- data/lib/acts_as_api/version.rb +1 -1
- data/spec/README.md +15 -6
- data/spec/active_record_dummy/Gemfile +2 -10
- data/spec/active_record_dummy/app/models/user.rb +31 -32
- data/spec/active_record_dummy/config.ru +1 -1
- data/spec/active_record_dummy/config/application.rb +2 -2
- data/spec/active_record_dummy/config/boot.rb +1 -1
- data/spec/active_record_dummy/config/environments/test.rb +2 -2
- data/spec/active_record_dummy/config/initializers/session_store.rb +1 -1
- data/spec/active_record_dummy/config/initializers/wrap_parameters.rb +1 -1
- data/spec/active_record_dummy/config/routes.rb +1 -57
- data/spec/active_record_dummy/db/migrate/20110214201640_create_tables.rb +25 -26
- data/spec/active_record_dummy/db/schema.rb +27 -29
- data/spec/active_record_dummy/script/rails +2 -2
- data/spec/controllers/plain_objects_controller_spec.rb +11 -12
- data/spec/controllers/respond_with_users_controller_spec.rb +46 -67
- data/spec/controllers/users_controller_spec.rb +2 -3
- data/spec/models/model_spec.rb +17 -19
- data/spec/mongoid_dummy/Gemfile +3 -12
- data/spec/mongoid_dummy/app/models/profile.rb +6 -6
- data/spec/mongoid_dummy/app/models/task.rb +10 -10
- data/spec/mongoid_dummy/app/models/untouched.rb +4 -4
- data/spec/mongoid_dummy/app/models/user.rb +12 -14
- data/spec/mongoid_dummy/config.ru +1 -1
- data/spec/mongoid_dummy/config/application.rb +7 -7
- data/spec/mongoid_dummy/config/boot.rb +1 -1
- data/spec/mongoid_dummy/config/environments/development.rb +0 -1
- data/spec/mongoid_dummy/config/environments/production.rb +0 -1
- data/spec/mongoid_dummy/config/environments/test.rb +2 -2
- data/spec/mongoid_dummy/config/initializers/include_acts_as_api.rb +1 -1
- data/spec/mongoid_dummy/config/initializers/session_store.rb +1 -1
- data/spec/mongoid_dummy/config/initializers/wrap_parameters.rb +1 -2
- data/spec/mongoid_dummy/config/routes.rb +1 -57
- data/spec/mongoid_dummy/script/rails +2 -2
- data/spec/shared_engine/Gemfile +1 -1
- data/spec/shared_engine/Rakefile +1 -4
- data/spec/shared_engine/app/controllers/shared_engine/plain_objects_controller.rb +2 -2
- data/spec/shared_engine/app/controllers/shared_engine/respond_with_users_controller.rb +13 -15
- data/spec/shared_engine/app/controllers/shared_engine/users_controller.rb +17 -19
- data/spec/shared_engine/app/models/plain_object.rb +3 -1
- data/spec/shared_engine/app/models/user_template.rb +28 -29
- data/spec/shared_engine/lib/shared_engine.rb +1 -1
- data/spec/shared_engine/lib/shared_engine/version.rb +1 -1
- data/spec/shared_engine/shared_engine.gemspec +10 -12
- data/spec/spec_helper.rb +5 -13
- data/spec/support/api_test_helpers.rb +0 -2
- data/spec/support/controller_examples.rb +128 -173
- data/spec/support/it_supports.rb +1 -1
- data/spec/support/model_examples/associations.rb +119 -128
- data/spec/support/model_examples/callbacks.rb +17 -27
- data/spec/support/model_examples/closures.rb +21 -29
- data/spec/support/model_examples/conditional_if.rb +71 -103
- data/spec/support/model_examples/conditional_unless.rb +71 -103
- data/spec/support/model_examples/enabled.rb +5 -6
- data/spec/support/model_examples/extending.rb +49 -56
- data/spec/support/model_examples/methods.rb +11 -15
- data/spec/support/model_examples/options.rb +19 -25
- data/spec/support/model_examples/renaming.rb +21 -30
- data/spec/support/model_examples/simple.rb +10 -14
- data/spec/support/model_examples/sub_nodes.rb +47 -59
- data/spec/support/model_examples/undefined.rb +4 -6
- data/spec/support/model_examples/untouched.rb +6 -8
- data/spec/support/simple_fixtures.rb +11 -38
- metadata +22 -159
- data/spec/active_record_dummy/app/assets/images/rails.png +0 -0
- data/spec/active_record_dummy/app/assets/javascripts/application.js +0 -15
- data/spec/active_record_dummy/app/assets/stylesheets/application.css +0 -13
- data/spec/active_record_dummy/app/controllers/application_controller.rb +0 -3
- data/spec/active_record_dummy/app/helpers/application_helper.rb +0 -2
- data/spec/active_record_dummy/app/mailers/.gitkeep +0 -0
- data/spec/active_record_dummy/app/views/layouts/application.html.erb +0 -14
- data/spec/active_record_dummy/doc/README_FOR_APP +0 -2
- 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/public/404.html +0 -26
- data/spec/active_record_dummy/public/422.html +0 -26
- data/spec/active_record_dummy/public/500.html +0 -25
- data/spec/active_record_dummy/public/favicon.ico +0 -0
- data/spec/active_record_dummy/public/index.html +0 -241
- data/spec/active_record_dummy/public/robots.txt +0 -5
- 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/mongoid_dummy/README.rdoc +0 -261
- data/spec/mongoid_dummy/app/assets/images/rails.png +0 -0
- data/spec/mongoid_dummy/app/assets/javascripts/application.js +0 -15
- data/spec/mongoid_dummy/app/assets/stylesheets/application.css +0 -13
- data/spec/mongoid_dummy/app/controllers/application_controller.rb +0 -3
- data/spec/mongoid_dummy/app/helpers/application_helper.rb +0 -2
- data/spec/mongoid_dummy/app/mailers/.gitkeep +0 -0
- data/spec/mongoid_dummy/app/views/layouts/application.html.erb +0 -14
- data/spec/mongoid_dummy/doc/README_FOR_APP +0 -2
- data/spec/mongoid_dummy/lib/assets/.gitkeep +0 -0
- data/spec/mongoid_dummy/lib/tasks/.gitkeep +0 -0
- data/spec/mongoid_dummy/public/404.html +0 -26
- data/spec/mongoid_dummy/public/422.html +0 -26
- data/spec/mongoid_dummy/public/500.html +0 -25
- data/spec/mongoid_dummy/public/favicon.ico +0 -0
- data/spec/mongoid_dummy/public/index.html +0 -241
- data/spec/mongoid_dummy/public/robots.txt +0 -5
- 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/app/assets/images/shared_engine/.gitkeep +0 -0
- data/spec/shared_engine/app/assets/javascripts/shared_engine/application.js +0 -15
- data/spec/shared_engine/app/assets/stylesheets/shared_engine/application.css +0 -13
- data/spec/shared_engine/app/helpers/shared_engine/application_helper.rb +0 -4
- data/spec/shared_engine/app/views/layouts/shared_engine/application.html.erb +0 -14
- data/spec/shared_engine/dummy/README.rdoc +0 -261
- data/spec/shared_engine/dummy/Rakefile +0 -7
- data/spec/shared_engine/dummy/app/assets/javascripts/application.js +0 -15
- data/spec/shared_engine/dummy/app/assets/stylesheets/application.css +0 -13
- data/spec/shared_engine/dummy/app/controllers/application_controller.rb +0 -3
- data/spec/shared_engine/dummy/app/helpers/application_helper.rb +0 -2
- 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 +0 -14
- data/spec/shared_engine/dummy/config.ru +0 -4
- data/spec/shared_engine/dummy/config/application.rb +0 -56
- data/spec/shared_engine/dummy/config/boot.rb +0 -10
- data/spec/shared_engine/dummy/config/database.yml +0 -25
- data/spec/shared_engine/dummy/config/environment.rb +0 -5
- data/spec/shared_engine/dummy/config/environments/development.rb +0 -34
- data/spec/shared_engine/dummy/config/environments/production.rb +0 -63
- data/spec/shared_engine/dummy/config/environments/test.rb +0 -37
- data/spec/shared_engine/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/shared_engine/dummy/config/initializers/inflections.rb +0 -15
- data/spec/shared_engine/dummy/config/initializers/mime_types.rb +0 -5
- data/spec/shared_engine/dummy/config/initializers/secret_token.rb +0 -7
- data/spec/shared_engine/dummy/config/initializers/session_store.rb +0 -8
- data/spec/shared_engine/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/spec/shared_engine/dummy/config/locales/en.yml +0 -5
- data/spec/shared_engine/dummy/config/routes.rb +0 -4
- 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 +0 -26
- data/spec/shared_engine/dummy/public/422.html +0 -26
- data/spec/shared_engine/dummy/public/500.html +0 -25
- data/spec/shared_engine/dummy/public/favicon.ico +0 -0
- data/spec/shared_engine/dummy/script/rails +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e16fbb94ed887cceb26f045b1249335016a07682
|
4
|
+
data.tar.gz: 40ad8d4be72657344be7ad856eb7c83b66dcf389
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d08be30be0f420cd61e61bb3da1e98b798d420e8c6a8be3afadafa1e897c0c3180f734a2c374baa711afbd07b56b09503fa3dd25eaf041622aa5b119cfbf8917
|
7
|
+
data.tar.gz: 68debff236e8e0e78203841aa33c253949b36dfb518c3d5f75f9ad5bc7002ec01090c80dc0b441e57d363b6c141b36d1d2b1adaa60cb226c7900f3683c5383ed
|
data/Gemfile
CHANGED
@@ -1,19 +1,16 @@
|
|
1
|
-
source
|
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', '>=
|
12
|
-
gem 'rspec-its'
|
10
|
+
gem 'rspec', '>= 3.5.0'
|
13
11
|
gem 'rspec-collection_matchers'
|
14
12
|
gem 'capybara'
|
15
|
-
gem 'rspec-rails', '>=
|
16
|
-
gem 'webrat'
|
13
|
+
gem 'rspec-rails', '>= 3.5.0'
|
17
14
|
gem 'responders'
|
18
|
-
gem 'shared_engine', :
|
15
|
+
gem 'shared_engine', path: './spec/shared_engine'
|
19
16
|
end
|
data/History.txt
CHANGED
data/LICENSE.txt
ADDED
@@ -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 = [
|
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
|
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
|
-
|
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
|
40
|
+
system 'bundle exec rocco docs/index.rb -t docs/layout.mustache'
|
48
41
|
end
|
data/acts_as_api.gemspec
CHANGED
@@ -1,28 +1,29 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
|
3
|
-
require
|
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 =
|
6
|
+
s.name = 'acts_as_api'
|
7
7
|
s.version = ActsAsApi::VERSION
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
|
-
s.authors = [
|
10
|
-
s.email = [
|
11
|
-
s.homepage =
|
12
|
-
s.summary =
|
13
|
-
s.description =
|
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 = [
|
27
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
28
|
+
s.require_paths = ['lib']
|
28
29
|
end
|
File without changes
|
@@ -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>
|
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
|
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
|
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">¶</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
|
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">¶</a>
|
201
200
|
</div>
|
202
|
-
<p>Note that it
|
201
|
+
<p>Note that it'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&
|
222
|
+
<tr id='section-That&#39;s_it!'>
|
224
223
|
<td class=docs>
|
225
224
|
<div class="pilwrap">
|
226
|
-
<a class="pilcrow" href="#section-That&
|
225
|
+
<a class="pilcrow" href="#section-That&#39;s_it!">¶</a>
|
227
226
|
</div>
|
228
|
-
<h3>That
|
227
|
+
<h3>That'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">¶</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!_
|
263
|
+
<tr id='section-But_wait!_..._there&#39;s_more'>
|
265
264
|
<td class=docs>
|
266
265
|
<div class="pilwrap">
|
267
|
-
<a class="pilcrow" href="#section-But_wait!_
|
266
|
+
<a class="pilcrow" href="#section-But_wait!_..._there&#39;s_more">¶</a>
|
268
267
|
</div>
|
269
|
-
<h2>But wait!
|
268
|
+
<h2>But wait! ... there's more</h2>
|
270
269
|
|
271
|
-
<p>Often the pure rendering of database values is just not enough, so
|
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
|
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">¶</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
|
File without changes
|
data/lib/acts_as_api.rb
CHANGED
@@ -1,12 +1,9 @@
|
|
1
1
|
require 'active_model'
|
2
2
|
require 'active_support/core_ext/class'
|
3
3
|
|
4
|
-
|
5
|
-
|
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,
|
21
|
-
autoload :ApiTemplate,
|
22
|
-
autoload :Base,
|
23
|
-
autoload :Rendering,
|
24
|
-
autoload :Responder,
|
25
|
-
autoload :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.
|
data/lib/acts_as_api/adapters.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
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
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
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
|