Skip to content

Commit 6ab9a0e

Browse files
author
Lee Richmond
committed
initial commit
0 parents  commit 6ab9a0e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1262
-0
lines changed

.gitignore

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
2+
#
3+
# If you find yourself ignoring temporary files generated by your text editor
4+
# or operating system, you probably want to add a global ignore instead:
5+
# git config --global core.excludesfile '~/.gitignore_global'
6+
7+
# Ignore bundler config.
8+
/.bundle
9+
10+
# Ignore the default SQLite database.
11+
/db/*.sqlite3
12+
/db/*.sqlite3-journal
13+
spec/examples.txt
14+
15+
# Ignore all logfiles and tempfiles.
16+
/log/*
17+
/tmp/*
18+
!/log/.keep
19+
!/tmp/.keep
20+
21+
# Ignore Byebug command history file.
22+
.byebug_history

.rspec

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--format documentation
2+
--color

Gemfile

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
source 'https://rubygems.org'
2+
3+
gem 'rails', '~> 5.0.0', '>= 5.0.0.1'
4+
gem 'sqlite3'
5+
gem 'puma', '~> 3.0'
6+
gem 'jsonapi_suite', '~> 0.1'
7+
gem 'kaminari', '~> 0.17'
8+
gem 'active_model_serializers',
9+
git: 'https://github.com/richmolj/active_model_serializers.git',
10+
branch: 'include_data_if_sideloaded'
11+
12+
group :development, :test do
13+
gem 'pry'
14+
gem 'pry-byebug', platform: :mri
15+
gem 'rspec-rails', '~> 3.5'
16+
end
17+
18+
group :test do
19+
gem 'database_cleaner', '~> 1.5'
20+
end
21+
22+
group :development do
23+
gem 'listen', '~> 3.0.5'
24+
gem 'spring'
25+
gem 'spring-watcher-listen', '~> 2.0.0'
26+
end
27+
28+
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
29+
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

Gemfile.lock

+214
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
GIT
2+
remote: https://github.com/richmolj/active_model_serializers.git
3+
revision: 8700ac6124b8685b979b4a03570f71d498a18d36
4+
branch: include_data_if_sideloaded
5+
specs:
6+
active_model_serializers (0.10.2)
7+
actionpack (>= 4.1, < 6)
8+
activemodel (>= 4.1, < 6)
9+
jsonapi (~> 0.1.1.beta2)
10+
11+
GEM
12+
remote: https://rubygems.org/
13+
specs:
14+
actioncable (5.0.0.1)
15+
actionpack (= 5.0.0.1)
16+
nio4r (~> 1.2)
17+
websocket-driver (~> 0.6.1)
18+
actionmailer (5.0.0.1)
19+
actionpack (= 5.0.0.1)
20+
actionview (= 5.0.0.1)
21+
activejob (= 5.0.0.1)
22+
mail (~> 2.5, >= 2.5.4)
23+
rails-dom-testing (~> 2.0)
24+
actionpack (5.0.0.1)
25+
actionview (= 5.0.0.1)
26+
activesupport (= 5.0.0.1)
27+
rack (~> 2.0)
28+
rack-test (~> 0.6.3)
29+
rails-dom-testing (~> 2.0)
30+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
31+
actionview (5.0.0.1)
32+
activesupport (= 5.0.0.1)
33+
builder (~> 3.1)
34+
erubis (~> 2.7.0)
35+
rails-dom-testing (~> 2.0)
36+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
37+
activejob (5.0.0.1)
38+
activesupport (= 5.0.0.1)
39+
globalid (>= 0.3.6)
40+
activemodel (5.0.0.1)
41+
activesupport (= 5.0.0.1)
42+
activerecord (5.0.0.1)
43+
activemodel (= 5.0.0.1)
44+
activesupport (= 5.0.0.1)
45+
arel (~> 7.0)
46+
activesupport (5.0.0.1)
47+
concurrent-ruby (~> 1.0, >= 1.0.2)
48+
i18n (~> 0.7)
49+
minitest (~> 5.1)
50+
tzinfo (~> 1.1)
51+
arel (7.1.2)
52+
builder (3.2.2)
53+
byebug (9.0.5)
54+
coderay (1.1.1)
55+
concurrent-ruby (1.0.2)
56+
database_cleaner (1.5.3)
57+
diff-lcs (1.2.5)
58+
erubis (2.7.0)
59+
ffi (1.9.14)
60+
globalid (0.3.7)
61+
activesupport (>= 4.1.0)
62+
i18n (0.7.0)
63+
json (1.8.3)
64+
jsonapi (0.1.1.beta2)
65+
json (~> 1.8)
66+
jsonapi_ams_extensions (0.1.1)
67+
active_model_serializers (~> 0.10.x)
68+
jsonapi_compliable (0.3.4)
69+
active_model_serializers (~> 0.10)
70+
jsonapi (~> 0.1.1.beta2)
71+
jsonapi_ams_extensions (~> 0.1)
72+
rails (>= 4.1, < 6)
73+
jsonapi_errorable (0.1.1)
74+
active_model_serializers (~> 0.10)
75+
rails (>= 4.1, < 6)
76+
jsonapi_spec_helpers (0.2.1)
77+
jsonapi_suite (0.1.2)
78+
active_model_serializers (~> 0.10.x)
79+
jsonapi_ams_extensions (~> 0.1)
80+
jsonapi_compliable (~> 0.3)
81+
jsonapi_errorable (~> 0.1)
82+
jsonapi_spec_helpers (~> 0.2)
83+
jsonapi_swagger_helpers (~> 0.1)
84+
nested_attribute_reassignable (~> 0.6)
85+
rails (>= 4.1, < 6)
86+
strong_resources (~> 0.1)
87+
jsonapi_swagger_helpers (0.1.2)
88+
swagger-blocks (~> 1.3)
89+
kaminari (0.17.0)
90+
actionpack (>= 3.0.0)
91+
activesupport (>= 3.0.0)
92+
listen (3.0.8)
93+
rb-fsevent (~> 0.9, >= 0.9.4)
94+
rb-inotify (~> 0.9, >= 0.9.7)
95+
loofah (2.0.3)
96+
nokogiri (>= 1.5.9)
97+
mail (2.6.4)
98+
mime-types (>= 1.16, < 4)
99+
method_source (0.8.2)
100+
mime-types (3.1)
101+
mime-types-data (~> 3.2015)
102+
mime-types-data (3.2016.0521)
103+
mini_portile2 (2.1.0)
104+
minitest (5.9.0)
105+
nested_attribute_reassignable (0.6.5)
106+
activerecord (>= 4.1, < 6)
107+
nio4r (1.2.1)
108+
nokogiri (1.6.8)
109+
mini_portile2 (~> 2.1.0)
110+
pkg-config (~> 1.1.7)
111+
pkg-config (1.1.7)
112+
pry (0.10.4)
113+
coderay (~> 1.1.0)
114+
method_source (~> 0.8.1)
115+
slop (~> 3.4)
116+
pry-byebug (3.4.0)
117+
byebug (~> 9.0)
118+
pry (~> 0.10)
119+
puma (3.6.0)
120+
rack (2.0.1)
121+
rack-test (0.6.3)
122+
rack (>= 1.0)
123+
rails (5.0.0.1)
124+
actioncable (= 5.0.0.1)
125+
actionmailer (= 5.0.0.1)
126+
actionpack (= 5.0.0.1)
127+
actionview (= 5.0.0.1)
128+
activejob (= 5.0.0.1)
129+
activemodel (= 5.0.0.1)
130+
activerecord (= 5.0.0.1)
131+
activesupport (= 5.0.0.1)
132+
bundler (>= 1.3.0, < 2.0)
133+
railties (= 5.0.0.1)
134+
sprockets-rails (>= 2.0.0)
135+
rails-dom-testing (2.0.1)
136+
activesupport (>= 4.2.0, < 6.0)
137+
nokogiri (~> 1.6.0)
138+
rails-html-sanitizer (1.0.3)
139+
loofah (~> 2.0)
140+
railties (5.0.0.1)
141+
actionpack (= 5.0.0.1)
142+
activesupport (= 5.0.0.1)
143+
method_source
144+
rake (>= 0.8.7)
145+
thor (>= 0.18.1, < 2.0)
146+
rake (11.3.0)
147+
rb-fsevent (0.9.7)
148+
rb-inotify (0.9.7)
149+
ffi (>= 0.5.0)
150+
rspec-core (3.5.3)
151+
rspec-support (~> 3.5.0)
152+
rspec-expectations (3.5.0)
153+
diff-lcs (>= 1.2.0, < 2.0)
154+
rspec-support (~> 3.5.0)
155+
rspec-mocks (3.5.0)
156+
diff-lcs (>= 1.2.0, < 2.0)
157+
rspec-support (~> 3.5.0)
158+
rspec-rails (3.5.1)
159+
actionpack (>= 3.0)
160+
activesupport (>= 3.0)
161+
railties (>= 3.0)
162+
rspec-core (~> 3.5.0)
163+
rspec-expectations (~> 3.5.0)
164+
rspec-mocks (~> 3.5.0)
165+
rspec-support (~> 3.5.0)
166+
rspec-support (3.5.0)
167+
slop (3.6.0)
168+
spring (1.7.2)
169+
spring-watcher-listen (2.0.0)
170+
listen (>= 2.7, < 4.0)
171+
spring (~> 1.2)
172+
sprockets (3.7.0)
173+
concurrent-ruby (~> 1.0)
174+
rack (> 1, < 3)
175+
sprockets-rails (3.2.0)
176+
actionpack (>= 4.0)
177+
activesupport (>= 4.0)
178+
sprockets (>= 3.0.0)
179+
sqlite3 (1.3.11)
180+
strong_resources (0.1.1)
181+
rails (>= 4.1, < 6.0)
182+
stronger_parameters (~> 2.6)
183+
stronger_parameters (2.6.0)
184+
actionpack (>= 3.2, < 5.1)
185+
swagger-blocks (1.3.4)
186+
thor (0.19.1)
187+
thread_safe (0.3.5)
188+
tzinfo (1.2.2)
189+
thread_safe (~> 0.1)
190+
websocket-driver (0.6.4)
191+
websocket-extensions (>= 0.1.0)
192+
websocket-extensions (0.1.2)
193+
194+
PLATFORMS
195+
ruby
196+
197+
DEPENDENCIES
198+
active_model_serializers!
199+
database_cleaner (~> 1.5)
200+
jsonapi_suite (~> 0.1)
201+
kaminari (~> 0.17)
202+
listen (~> 3.0.5)
203+
pry
204+
pry-byebug
205+
puma (~> 3.0)
206+
rails (~> 5.0.0, >= 5.0.0.1)
207+
rspec-rails (~> 3.5)
208+
spring
209+
spring-watcher-listen (~> 2.0.0)
210+
sqlite3
211+
tzinfo-data
212+
213+
BUNDLED WITH
214+
1.12.5

README.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# README
2+
3+
This README would normally document whatever steps are necessary to get the
4+
application up and running.
5+
6+
Things you may want to cover:
7+
8+
* Ruby version
9+
10+
* System dependencies
11+
12+
* Configuration
13+
14+
* Database creation
15+
16+
* Database initialization
17+
18+
* How to run the test suite
19+
20+
* Services (job queues, cache servers, search engines, etc.)
21+
22+
* Deployment instructions
23+
24+
* ...

Rakefile

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Add your own tasks in files placed in lib/tasks ending in .rake,
2+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3+
4+
require_relative 'config/application'
5+
6+
Rails.application.load_tasks
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class ApplicationController < ActionController::API
2+
include JsonapiSuite::ControllerMixin
3+
4+
rescue_from Exception do |e|
5+
handle_exception(e)
6+
end
7+
end

app/controllers/concerns/.keep

Whitespace-only changes.
+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
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
15+
16+
before_action :deserialize_jsonapi!, only: [:create, :update]
17+
18+
strong_resource :employee do
19+
belongs_to :department
20+
end
21+
22+
def index
23+
employees = Employee.all
24+
render_ams(employees)
25+
end
26+
27+
def show
28+
employee = jsonapi_scope(Employee.all).find(params[:id])
29+
render_ams(employee)
30+
end
31+
32+
def create
33+
employee = Employee.new(strong_resource)
34+
35+
if employee.save
36+
render_ams(employee)
37+
else
38+
render_errors_for(employee)
39+
end
40+
end
41+
42+
def update
43+
employee = Employee.find(params[:id])
44+
45+
if employee.update_attributes(strong_resource)
46+
render_ams(employee, scope: false)
47+
else
48+
render_errors_for(employee)
49+
end
50+
end
51+
52+
def destroy
53+
employee = Employee.find(params[:id])
54+
employee.destroy
55+
render_ams(employee)
56+
end
57+
end

app/models/application_record.rb

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class ApplicationRecord < ActiveRecord::Base
2+
self.abstract_class = true
3+
end

app/models/concerns/.keep

Whitespace-only changes.

app/models/department.rb

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Department < ApplicationRecord
2+
has_many :employees
3+
has_many :goals
4+
end

app/models/employee.rb

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Employee < ApplicationRecord
2+
include NestedAttributeReassignable
3+
4+
belongs_to :department
5+
6+
reassignable_nested_attributes_for :department
7+
end

app/models/goal.rb

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Goal < ApplicationRecord
2+
belongs_to :department
3+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class ApplicationSerializer < ActiveModel::Serializer
2+
include JsonapiAmsExtensions
3+
end

0 commit comments

Comments
 (0)