active_model_serializers 0.8.3 → 0.9.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +122 -5
- data/CONTRIBUTING.md +20 -0
- data/DESIGN.textile +4 -4
- data/{MIT-LICENSE.txt → MIT-LICENSE} +0 -0
- data/README.md +396 -95
- data/lib/action_controller/serialization.rb +50 -12
- data/lib/action_controller/serialization_test_case.rb +79 -0
- data/lib/active_model/array_serializer.rb +47 -78
- data/lib/active_model/default_serializer.rb +32 -0
- data/lib/active_model/serializable/utils.rb +16 -0
- data/lib/active_model/serializable.rb +62 -0
- data/lib/active_model/serializer/association/has_many.rb +39 -0
- data/lib/active_model/serializer/association/has_one.rb +25 -0
- data/lib/active_model/serializer/association.rb +58 -0
- data/lib/active_model/serializer/config.rb +31 -0
- data/lib/active_model/serializer/generators/resource_override.rb +13 -0
- data/lib/{generators → active_model/serializer/generators}/serializer/USAGE +0 -0
- data/lib/active_model/serializer/generators/serializer/scaffold_controller_generator.rb +14 -0
- data/lib/active_model/serializer/generators/serializer/serializer_generator.rb +37 -0
- data/lib/active_model/serializer/generators/serializer/templates/controller.rb +93 -0
- data/lib/active_model/serializer/generators/serializer/templates/serializer.rb +8 -0
- data/lib/active_model/serializer/railtie.rb +18 -0
- data/lib/active_model/{serializers → serializer}/version.rb +1 -1
- data/lib/active_model/serializer.rb +214 -423
- data/lib/active_model/serializer_support.rb +5 -0
- data/lib/active_model_serializers/mime_types.rb +14 -0
- data/lib/active_model_serializers.rb +12 -87
- data/test/fixtures/active_record.rb +96 -0
- data/test/fixtures/poro.rb +187 -0
- data/test/fixtures/template.html.erb +1 -0
- data/test/integration/action_controller/namespaced_serialization_test.rb +105 -0
- data/test/integration/action_controller/serialization_test.rb +287 -0
- data/test/integration/action_controller/serialization_test_case_test.rb +71 -0
- data/test/integration/active_record/active_record_test.rb +94 -0
- data/test/integration/generators/resource_generator_test.rb +26 -0
- data/test/integration/generators/scaffold_controller_generator_test.rb +64 -0
- data/test/integration/generators/serializer_generator_test.rb +41 -0
- data/test/test_app.rb +14 -0
- data/test/test_helper.rb +10 -18
- data/test/unit/active_model/array_serializer/except_test.rb +18 -0
- data/test/unit/active_model/array_serializer/key_format_test.rb +18 -0
- data/test/unit/active_model/array_serializer/meta_test.rb +53 -0
- data/test/unit/active_model/array_serializer/only_test.rb +18 -0
- data/test/unit/active_model/array_serializer/options_test.rb +16 -0
- data/test/unit/active_model/array_serializer/root_test.rb +102 -0
- data/test/unit/active_model/array_serializer/scope_test.rb +24 -0
- data/test/unit/active_model/array_serializer/serialization_test.rb +216 -0
- data/test/unit/active_model/default_serializer_test.rb +13 -0
- data/test/unit/active_model/serializer/associations/build_serializer_test.rb +36 -0
- data/test/unit/active_model/serializer/associations_test.rb +19 -0
- data/test/unit/active_model/serializer/attributes_test.rb +57 -0
- data/test/unit/active_model/serializer/config_test.rb +91 -0
- data/test/unit/active_model/serializer/filter_test.rb +69 -0
- data/test/unit/active_model/serializer/has_many_polymorphic_test.rb +189 -0
- data/test/unit/active_model/serializer/has_many_test.rb +265 -0
- data/test/unit/active_model/serializer/has_one_and_has_many_test.rb +27 -0
- data/test/unit/active_model/serializer/has_one_polymorphic_test.rb +196 -0
- data/test/unit/active_model/serializer/has_one_test.rb +253 -0
- data/test/unit/active_model/serializer/key_format_test.rb +25 -0
- data/test/unit/active_model/serializer/meta_test.rb +39 -0
- data/test/unit/active_model/serializer/options_test.rb +42 -0
- data/test/unit/active_model/serializer/root_test.rb +117 -0
- data/test/unit/active_model/serializer/scope_test.rb +49 -0
- data/test/unit/active_model/serializer/url_helpers_test.rb +35 -0
- metadata +107 -64
- data/.gitignore +0 -18
- data/.travis.yml +0 -28
- data/Gemfile +0 -4
- data/Gemfile.edge +0 -9
- data/Rakefile +0 -18
- data/active_model_serializers.gemspec +0 -24
- data/bench/perf.rb +0 -43
- data/cruft.md +0 -19
- data/lib/active_model/serializer/associations.rb +0 -233
- data/lib/active_record/serializer_override.rb +0 -16
- data/lib/generators/resource_override.rb +0 -13
- data/lib/generators/serializer/serializer_generator.rb +0 -42
- data/lib/generators/serializer/templates/serializer.rb +0 -19
- data/test/array_serializer_test.rb +0 -75
- data/test/association_test.rb +0 -592
- data/test/caching_test.rb +0 -96
- data/test/generators_test.rb +0 -85
- data/test/no_serialization_scope_test.rb +0 -34
- data/test/serialization_scope_name_test.rb +0 -67
- data/test/serialization_test.rb +0 -392
- data/test/serializer_support_test.rb +0 -51
- data/test/serializer_test.rb +0 -1465
- data/test/test_fakes.rb +0 -217
@@ -0,0 +1,93 @@
|
|
1
|
+
<% if namespaced? -%>
|
2
|
+
require_dependency "<%= namespaced_file_path %>/application_controller"
|
3
|
+
|
4
|
+
<% end -%>
|
5
|
+
<% module_namespacing do -%>
|
6
|
+
class <%= controller_class_name %>Controller < ApplicationController
|
7
|
+
before_action :set_<%= singular_table_name %>, only: [:show, :edit, :update, :destroy]
|
8
|
+
|
9
|
+
# GET <%= route_url %>
|
10
|
+
# GET <%= route_url %>.json
|
11
|
+
def index
|
12
|
+
@<%= plural_table_name %> = <%= orm_class.all(class_name) %>
|
13
|
+
|
14
|
+
respond_to do |format|
|
15
|
+
format.html # index.html.erb
|
16
|
+
format.json { render json: <%= "@#{plural_table_name}" %> }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# GET <%= route_url %>/1
|
21
|
+
# GET <%= route_url %>/1.json
|
22
|
+
def show
|
23
|
+
respond_to do |format|
|
24
|
+
format.html # show.html.erb
|
25
|
+
format.json { render json: <%= "@#{singular_table_name}" %> }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# GET <%= route_url %>/new
|
30
|
+
def new
|
31
|
+
@<%= singular_table_name %> = <%= orm_class.build(class_name) %>
|
32
|
+
end
|
33
|
+
|
34
|
+
# GET <%= route_url %>/1/edit
|
35
|
+
def edit
|
36
|
+
end
|
37
|
+
|
38
|
+
# POST <%= route_url %>
|
39
|
+
# POST <%= route_url %>.json
|
40
|
+
def create
|
41
|
+
@<%= singular_table_name %> = <%= orm_class.build(class_name, "#{singular_table_name}_params") %>
|
42
|
+
|
43
|
+
respond_to do |format|
|
44
|
+
if @<%= orm_instance.save %>
|
45
|
+
format.html { redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully created.'" %> }
|
46
|
+
format.json { render json: <%= "@#{singular_table_name}" %>, status: :created }
|
47
|
+
else
|
48
|
+
format.html { render action: 'new' }
|
49
|
+
format.json { render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# PATCH/PUT <%= route_url %>/1
|
55
|
+
# PATCH/PUT <%= route_url %>/1.json
|
56
|
+
def update
|
57
|
+
respond_to do |format|
|
58
|
+
if @<%= orm_instance.update("#{singular_table_name}_params") %>
|
59
|
+
format.html { redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully updated.'" %> }
|
60
|
+
format.json { head :no_content }
|
61
|
+
else
|
62
|
+
format.html { render action: 'edit' }
|
63
|
+
format.json { render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# DELETE <%= route_url %>/1
|
69
|
+
# DELETE <%= route_url %>/1.json
|
70
|
+
def destroy
|
71
|
+
@<%= orm_instance.destroy %>
|
72
|
+
respond_to do |format|
|
73
|
+
format.html { redirect_to <%= index_helper %>_url }
|
74
|
+
format.json { head :no_content }
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
# Use callbacks to share common setup or constraints between actions.
|
80
|
+
def set_<%= singular_table_name %>
|
81
|
+
@<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
|
82
|
+
end
|
83
|
+
|
84
|
+
# Never trust parameters from the scary internet, only allow the white list through.
|
85
|
+
def <%= "#{singular_table_name}_params" %>
|
86
|
+
<%- if attributes_names.empty? -%>
|
87
|
+
params[<%= ":#{singular_table_name}" %>]
|
88
|
+
<%- else -%>
|
89
|
+
params.require(<%= ":#{singular_table_name}" %>).permit(<%= attributes_names.map { |name| ":#{name}" }.join(', ') %>)
|
90
|
+
<%- end -%>
|
91
|
+
end
|
92
|
+
end
|
93
|
+
<% end -%>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module ActiveModel
|
2
|
+
class Railtie < Rails::Railtie
|
3
|
+
initializer 'generators' do |app|
|
4
|
+
app.load_generators
|
5
|
+
require 'active_model/serializer/generators/serializer/serializer_generator'
|
6
|
+
require 'active_model/serializer/generators/serializer/scaffold_controller_generator'
|
7
|
+
require 'active_model/serializer/generators/resource_override'
|
8
|
+
end
|
9
|
+
|
10
|
+
initializer 'include_routes.active_model_serializer' do |app|
|
11
|
+
ActiveSupport.on_load(:active_model_serializers) do
|
12
|
+
include app.routes.url_helpers
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
ActiveSupport.run_load_hooks(:active_model_serializers, ActiveModel::Serializer)
|