api_me 0.10.3 → 0.10.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +7 -5
  3. data/lib/api_me.rb +20 -13
  4. data/lib/api_me/version.rb +1 -1
  5. metadata +32 -18
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f6b29b1a465714cdcc7feedeebd6c5d33f1a5372570d12a15aa34bcd703abea5
4
- data.tar.gz: d6508859d1824d21da8317575310a7b86d449a4b8de223bf50d9fa10dafbc03f
3
+ metadata.gz: '0309df280a0738df9908bd663210fd71390c6495eb3f89ab5132b51200b98013'
4
+ data.tar.gz: a886ff6a38a273964da8982933ad9adc1232e70acab477cb635bf02422ae2390
5
5
  SHA512:
6
- metadata.gz: 39e6b061f1f38eeb5c78b686a9ff0fca4c41abaa45d065f02b85790ea5ac0ce8133d948cc15d375a21ca4db7c1ac570125b0b8f57c0a50a16aee568a70714ae9
7
- data.tar.gz: 9f0909bbc887578ed2caea5c5924ddb6671b754bed90e059f502f582355e71b4fbca5440218b96e8ec04c2b2f6ea7ded6e35b3ce3aae340baa437b857d83b7a1
6
+ metadata.gz: 0c6f7161dd7154ab4e52b211fcd63c6200c29644bffc7c3d866f59f241d583dd7edc72b20fbec0eecb82cd2bc61fc08b1139a50d8d67e8ff7bcb8b35c45782c9
7
+ data.tar.gz: 511c29eaa0bb6a3018cb208135beddffb003001af4f5be9b48f004d163f00bf02a3ac22515816464c00733d945ee008df31f957e6a219c16396a00727054596d
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  begin
2
4
  require 'bundler/setup'
3
5
  rescue LoadError
@@ -14,15 +16,15 @@ RDoc::Task.new(:rdoc) do |rdoc|
14
16
  rdoc.rdoc_files.include('lib/**/*.rb')
15
17
  end
16
18
 
17
- APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
19
+ APP_RAKEFILE = File.expand_path('spec/dummy/Rakefile', __dir__)
18
20
  load 'rails/tasks/engine.rake'
19
21
  load 'rails/tasks/statistics.rake'
20
22
 
21
23
  Bundler::GemHelper.install_tasks
22
- require "rake"
23
- require "rspec/core/rake_task"
24
+ require 'rake'
25
+ require 'rspec/core/rake_task'
24
26
  RSpec::Core::RakeTask.new(:spec) do |t|
25
- t.pattern = Dir.glob("spec/**/*_spec.rb")
26
- t.rspec_opts = "--format documentation"
27
+ t.pattern = Dir.glob('spec/**/*_spec.rb')
28
+ t.rspec_opts = '--format documentation'
27
29
  end
28
30
  task default: :spec
data/lib/api_me.rb CHANGED
@@ -16,6 +16,7 @@ module ApiMe
16
16
 
17
17
  included do
18
18
  rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
19
+ rescue_from ActiveRecord::ActiveRecordError, with: :handle_active_record_errors
19
20
  rescue_from ActiveRecord::RecordNotFound, with: :resource_not_found
20
21
  end
21
22
 
@@ -55,11 +56,11 @@ module ApiMe
55
56
  end
56
57
 
57
58
  def serializer_klass_name
58
- @serializer_klass_name ||= "#{name.demodulize.sub(/Controller$/, '').singularize}Serializer"
59
+ @serializer_klass_name ||= "#{model_klass_name}Serializer"
59
60
  end
60
61
 
61
62
  def filter_klass_name
62
- @filter_klass_name ||= "#{name.demodulize.sub(/Controller$/, '').singularize}Filter"
63
+ @filter_klass_name ||= "#{model_klass_name}Filter"
63
64
  end
64
65
  end
65
66
 
@@ -73,7 +74,7 @@ module ApiMe
73
74
  @sorted_scope = sort_scope(@filter_scope)
74
75
  @pagination_object = paginate_scope(@sorted_scope, page_params)
75
76
 
76
- render({
77
+ render(
77
78
  json: @pagination_object.results,
78
79
  root: collection_root_key,
79
80
  each_serializer: serializer_klass,
@@ -81,7 +82,7 @@ module ApiMe
81
82
  page: @pagination_object.page_meta,
82
83
  sort: sorting_meta(@filter_scope)
83
84
  }
84
- })
85
+ )
85
86
  end
86
87
 
87
88
  def show
@@ -101,11 +102,9 @@ module ApiMe
101
102
  def create
102
103
  @object = build_resource
103
104
  authorize_resource @object
104
- @object.save!(object_params)
105
+ create_resource!
105
106
 
106
107
  render status: 201, json: @object, root: singular_root_key, serializer: serializer_klass
107
- rescue ActiveRecord::RecordInvalid => e
108
- handle_active_record_errors(e)
109
108
  end
110
109
 
111
110
  def edit
@@ -118,21 +117,17 @@ module ApiMe
118
117
  def update
119
118
  @object = find_resource
120
119
  authorize_resource @object
121
- @object.update!(object_params)
120
+ update_resource!
122
121
 
123
122
  head 204
124
- rescue ActiveRecord::RecordInvalid => e
125
- handle_active_record_errors(e)
126
123
  end
127
124
 
128
125
  def destroy
129
126
  @object = find_resource
130
127
  authorize_resource @object
131
- @object.destroy
128
+ destroy_resource!
132
129
 
133
130
  head 204
134
- rescue ActiveRecord::RecordInvalid => e
135
- handle_active_record_errors(e)
136
131
  end
137
132
 
138
133
  protected
@@ -242,6 +237,18 @@ module ApiMe
242
237
  @build_resource ||= model_klass.new(object_params)
243
238
  end
244
239
 
240
+ def create_resource!
241
+ @object.save!(object_params)
242
+ end
243
+
244
+ def update_resource!
245
+ @object.update!(object_params)
246
+ end
247
+
248
+ def destroy_resource!
249
+ @object.destroy!
250
+ end
251
+
245
252
  def authorize_resource(resource)
246
253
  authorize resource
247
254
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ApiMe
4
- VERSION = '0.10.3'
4
+ VERSION = '0.10.4'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_me
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.3
4
+ version: 0.10.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Clopton
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-12-17 00:00:00.000000000 Z
12
+ date: 2019-05-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -25,6 +25,34 @@ dependencies:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
27
  version: '4.2'
28
+ - !ruby/object:Gem::Dependency
29
+ name: actionview
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 4.2.11.1
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: 4.2.11.1
42
+ - !ruby/object:Gem::Dependency
43
+ name: activejob
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: 4.2.11
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 4.2.11
28
56
  - !ruby/object:Gem::Dependency
29
57
  name: pundit
30
58
  requirement: !ruby/object:Gem::Requirement
@@ -85,30 +113,16 @@ dependencies:
85
113
  name: rspec-rails
86
114
  requirement: !ruby/object:Gem::Requirement
87
115
  requirements:
88
- - - "~>"
116
+ - - ">="
89
117
  - !ruby/object:Gem::Version
90
118
  version: 3.6.1
91
119
  type: :development
92
120
  prerelease: false
93
121
  version_requirements: !ruby/object:Gem::Requirement
94
122
  requirements:
95
- - - "~>"
123
+ - - ">="
96
124
  - !ruby/object:Gem::Version
97
125
  version: 3.6.1
98
- - !ruby/object:Gem::Dependency
99
- name: factory_girl_rails
100
- requirement: !ruby/object:Gem::Requirement
101
- requirements:
102
- - - "~>"
103
- - !ruby/object:Gem::Version
104
- version: 4.8.0
105
- type: :development
106
- prerelease: false
107
- version_requirements: !ruby/object:Gem::Requirement
108
- requirements:
109
- - - "~>"
110
- - !ruby/object:Gem::Version
111
- version: 4.8.0
112
126
  - !ruby/object:Gem::Dependency
113
127
  name: sqlite3
114
128
  requirement: !ruby/object:Gem::Requirement