Skip to content

Commit 3c5f243

Browse files
author
Lee Richmond
committed
Update to 0.5.x
1 parent be1a59a commit 3c5f243

12 files changed

+70
-75
lines changed

Gemfile

+5-7
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@ source 'https://rubygems.org'
33
gem 'rails', '~> 5.0.0', '>= 5.0.0.1'
44
gem 'sqlite3'
55
gem 'puma', '~> 3.0'
6-
gem 'jsonapi_suite', '~> 0.1'
6+
gem 'jsonapi_suite', '~> 0.5'
7+
gem 'jsonapi-rails', '~> 0.1'
78
gem 'kaminari', '~> 0.17'
89

9-
gem 'jsonapi-rb', path: '../jsonapi-rb'
10-
gem 'jsonapi-rails', path: '../jsonapi-rails', require: 'jsonapi/rails'
11-
gem 'jsonapi_compliable', path: '../jsonapi_compliable'
12-
gem 'jsonapi-serializable', path: '../serializable'
13-
gem 'jsonapi-deserializable', path: '../jsonapi-deserializable'
14-
gem 'jsonapi-parser', path: '../jsonapi-parser'
10+
gem 'jsonapi-serializable',
11+
git: 'https://github.com/jsonapi-rb/jsonapi-serializable.git',
12+
branch: 'optim-1'
1513

1614
group :development, :test do
1715
gem 'pry'

Gemfile.lock

+24-50
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,7 @@
1-
PATH
2-
remote: ../jsonapi-deserializable
3-
specs:
4-
jsonapi-deserializable (0.1.1)
5-
jsonapi-parser (= 0.1.1)
6-
7-
PATH
8-
remote: ../jsonapi-parser
9-
specs:
10-
jsonapi-parser (0.1.1)
11-
12-
PATH
13-
remote: ../jsonapi-rails
14-
specs:
15-
jsonapi-rails (0.1.1.beta4)
16-
jsonapi-rb (= 0.1.1)
17-
18-
PATH
19-
remote: ../jsonapi-rb
20-
specs:
21-
jsonapi-rb (0.1.1)
22-
jsonapi-deserializable (= 0.1.1)
23-
jsonapi-serializable (= 0.1.1)
24-
25-
PATH
26-
remote: ../jsonapi_compliable
27-
specs:
28-
jsonapi_compliable (0.3.10)
29-
jsonapi-rails
30-
rails (>= 4.1, < 6)
31-
32-
PATH
33-
remote: ../serializable
1+
GIT
2+
remote: https://github.com/jsonapi-rb/jsonapi-serializable.git
3+
revision: c852bed5232c8853d62c188d4c796f2fc22b5b6c
4+
branch: optim-1
345
specs:
356
jsonapi-serializable (0.1.1)
367
jsonapi-renderer (= 0.1.1)
@@ -91,27 +62,34 @@ GEM
9162
globalid (0.3.7)
9263
activesupport (>= 4.1.0)
9364
i18n (0.7.0)
94-
json (1.8.3)
65+
json (1.8.6)
9566
jsonapi (0.1.1.beta2)
9667
json (~> 1.8)
68+
jsonapi-deserializable (0.1.1)
69+
jsonapi-parser (= 0.1.1)
70+
jsonapi-parser (0.1.1)
71+
jsonapi-rails (0.1.1)
72+
jsonapi-rb (= 0.1.1)
73+
jsonapi-rb (0.1.1)
74+
jsonapi-deserializable (= 0.1.1)
75+
jsonapi-serializable (= 0.1.1)
9776
jsonapi-renderer (0.1.1)
98-
jsonapi_ams_extensions (0.1.1)
99-
active_model_serializers (~> 0.10.x)
77+
jsonapi_compliable (0.5.2)
78+
jsonapi-serializable (~> 0.1)
10079
jsonapi_errorable (0.1.1)
10180
active_model_serializers (~> 0.10)
10281
rails (>= 4.1, < 6)
10382
jsonapi_spec_helpers (0.2.3)
104-
jsonapi_suite (0.1.2)
105-
active_model_serializers (~> 0.10.x)
106-
jsonapi_ams_extensions (~> 0.1)
107-
jsonapi_compliable (~> 0.3)
83+
jsonapi_suite (0.5.1)
84+
jsonapi (= 0.1.1.beta2)
85+
jsonapi_compliable (~> 0.5)
10886
jsonapi_errorable (~> 0.1)
10987
jsonapi_spec_helpers (~> 0.2)
11088
jsonapi_swagger_helpers (~> 0.1)
11189
nested_attribute_reassignable (~> 0.6)
11290
rails (>= 4.1, < 6)
11391
strong_resources (~> 0.1)
114-
jsonapi_swagger_helpers (0.1.2)
92+
jsonapi_swagger_helpers (0.1.5)
11593
swagger-blocks (~> 1.3)
11694
kaminari (0.17.0)
11795
actionpack (>= 3.0.0)
@@ -204,12 +182,12 @@ GEM
204182
activesupport (>= 4.0)
205183
sprockets (>= 3.0.0)
206184
sqlite3 (1.3.11)
207-
strong_resources (0.1.1)
185+
strong_resources (0.1.6)
208186
rails (>= 4.1, < 6.0)
209187
stronger_parameters (~> 2.6)
210188
stronger_parameters (2.6.0)
211189
actionpack (>= 3.2, < 5.1)
212-
swagger-blocks (1.3.4)
190+
swagger-blocks (1.4.0)
213191
thor (0.19.1)
214192
thread_safe (0.3.5)
215193
tzinfo (1.2.2)
@@ -223,13 +201,9 @@ PLATFORMS
223201

224202
DEPENDENCIES
225203
database_cleaner (~> 1.5)
226-
jsonapi-deserializable!
227-
jsonapi-parser!
228-
jsonapi-rails!
229-
jsonapi-rb!
204+
jsonapi-rails (~> 0.1)
230205
jsonapi-serializable!
231-
jsonapi_compliable!
232-
jsonapi_suite (~> 0.1)
206+
jsonapi_suite (~> 0.5)
233207
kaminari (~> 0.17)
234208
listen (~> 3.0.5)
235209
pry
@@ -243,4 +217,4 @@ DEPENDENCIES
243217
tzinfo-data
244218

245219
BUNDLED WITH
246-
1.12.5
220+
1.13.6

app/controllers/departments_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class DepartmentsController < ApplicationController
2-
jsonapi { }
2+
jsonapi resource: DepartmentResource
33

44
def index
55
departments = Department.all
+5-17
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
11
class EmployeesController < ApplicationController
2-
jsonapi do
3-
allow_filter :name
4-
allow_filter :age
5-
6-
allow_filter :name_prefix do |scope, value|
7-
scope.where(["name LIKE ?", "#{value}%"])
8-
end
9-
10-
includes whitelist: {
11-
index: :department,
12-
show: { department: :goals }
13-
}
14-
end
2+
jsonapi resource: EmployeeResource
153

164
before_action :deserialize_jsonapi!, only: [:create, :update]
175

@@ -25,15 +13,15 @@ def index
2513
end
2614

2715
def show
28-
employee = jsonapi_scope(Employee.all).find(params[:id])
29-
render_jsonapi(employee)
16+
employee = jsonapi_scope(Employee.where(id: params[:id]))
17+
render_jsonapi(employee.resolve.first, scope: false)
3018
end
3119

3220
def create
3321
employee = Employee.new(strong_resource)
3422

3523
if employee.save
36-
render_jsonapi(employee)
24+
render_jsonapi(employee, scope: false)
3725
else
3826
render_errors_for(employee)
3927
end
@@ -52,6 +40,6 @@ def update
5240
def destroy
5341
employee = Employee.find(params[:id])
5442
employee.destroy
55-
render_jsonapi(employee)
43+
render_jsonapi(employee, scope: false)
5644
end
5745
end

app/resources/application_resource.rb

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class ApplicationResource < JsonapiCompliable::Resource
2+
use_adapter JsonapiCompliable::Adapters::ActiveRecord
3+
end

app/resources/department_resource.rb

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class DepartmentResource < ApplicationResource
2+
type :departments
3+
4+
belongs_to :employee,
5+
foreign_key: :employee_id,
6+
scope: -> { Employee.all },
7+
resource: EmployeeResource
8+
end

app/resources/employee_resource.rb

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class EmployeeResource < ApplicationResource
2+
type :employees
3+
4+
allow_filter :name
5+
allow_filter :age
6+
7+
allow_filter :name_prefix do |scope, value|
8+
scope.where(["name LIKE ?", "#{value}%"])
9+
end
10+
11+
has_many :departments,
12+
scope: -> { Department.all },
13+
foreign_key: :employee_id,
14+
resource: DepartmentResource
15+
end

app/resources/goal_resource.rb

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class GoalResource < ApplicationResource
2+
type :goals
3+
4+
belongs_to :department,
5+
scope: -> { Department.all },
6+
foreign_key: :department_id,
7+
resource: DepartmentResource
8+
end

config/initializers/jsonapi.rb

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require 'jsonapi_compliable/adapters/active_record'

0 commit comments

Comments
 (0)