jsonapionify 0.11.10 → 0.11.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Nzg2ZGJhNjcxNmEzOTJmYWI4MjlkODQ5YjhhZWZkYWY5MjlkMTUyNQ==
4
+ NGNhMGNhNzcwZDMxOGZkYTA3MzBhZWIzNDhiZDlhODEyNjUwYzZkMw==
5
5
  data.tar.gz: !binary |-
6
- YzE3OWY1MTA0ODhiZGZiNmZkMjcwYTZkMGRiZjFmY2ZlNjE0NmVhNQ==
6
+ MzFmOWY1MDZkODE2ODU4NGZjYjYzNmQ3ZWIyNmJhNGQ4ZWFjNTExMA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ODE4MDFiZDFmOTlmNzBiOGU3ZDVlOTQ0YTE3NmMzYmU0Y2ZiM2EwNGIxMzcz
10
- OTNlYWZlNDEzNmI5ZjBkNTdiNTBmNzNiYWIwZGUxNGMzZmJmNzE2NzQ1ZDc4
11
- MzkyYTE3MWM4MDU5ODdkYmMwYjQ2ZWEyNTY5Yzc5ODU1MjgxZGY=
9
+ N2MzN2UyZjYzYjMwMjE4NTdmYjFjMTgyYzdjNDA0NDUwNTlmMDliOWQ0ZDUy
10
+ MTk2MTBhZjA0MWNkNThiMDhjZmVhYTRiNzBlYmNkOGE3ZWY2OWZkZGM1ZmNj
11
+ ODVmMzFlNGRmMDJmYTQ0ZWJlZjNmOTM5YTFhYjYyYTJjZmVhYjU=
12
12
  data.tar.gz: !binary |-
13
- ZmU0NjY3YzU0ZDUyZjA0ZDY1NWM2N2NhZjQyZWY4NmJlODQ3OTI1ZjBiYTJl
14
- NjAwMjM3OTgyZDU0OGQwMDM4YzZjNjYyODEzMWU2MDA5N2YwMjYxZjMwNjUx
15
- MDk5YWViNTIxZTBjZTE0NDdkZmM4NWMxMTEzYTJkNzY3MjQ4NjM=
13
+ ODI2NWRiMWZhMTYxMWIzNmQwOTg4MmRlMTI0MjJhZDljNTM0NzNmZTY5Y2Zm
14
+ MjA4OGJlOTFkZDA5M2U5ZTkyMWU0NzgzNGI1OWVhMWEyYmRkNjM2ZTI3YjJj
15
+ NTdkMjM3ZWZhYThhY2Y2MTRmMWVlZGIzZDU3ZmQ0ZjJkZGMzNTE=
@@ -1,6 +1,5 @@
1
1
  module JSONAPIonify::Api
2
2
  module Base::ResourceDefinitions
3
-
4
3
  def self.extended(klass)
5
4
  klass.class_eval do
6
5
  extend JSONAPIonify::InheritedAttributes
@@ -54,10 +53,9 @@ module JSONAPIonify::Api
54
53
  else
55
54
  block
56
55
  end
57
- const_name = name.to_s.camelcase + 'Resource'
56
+ const_name = name.to_s.camelcase + 'Resource'
58
57
  remove_const(const_name) if const_defined? const_name, false
59
58
  name
60
59
  end
61
-
62
60
  end
63
61
  end
@@ -1,31 +1,28 @@
1
1
  module JSONAPIonify::Api
2
2
  module Resource::Defaults::Options
3
+ def self.scope_is_active_record? scope
4
+ return false unless defined?(ActiveRecord)
5
+ scope < ActiveRecord::Base
6
+ rescue NoMethodError, ArgumentError, TypeError
7
+ false
8
+ end
9
+
3
10
  extend ActiveSupport::Concern
4
11
  included do
5
12
  id :id
6
13
  scope { self.type.classify.constantize }
7
14
  collection do |scope, context|
8
- if defined?(ActiveRecord) && scope.is_a?(Class) && scope < ActiveRecord::Base
9
- scope.all
10
- else
11
- scope
12
- end
15
+ Resource::Defaults::Options.scope_is_active_record?(scope) ? scope.all : scope
13
16
  end
14
17
 
15
18
  instance do |scope, key|
16
- if defined?(ActiveRecord) && scope.is_a?(Class) && scope < ActiveRecord::Base
17
- scope.find_by! id_attribute => key
18
- else
19
- raise NotImplementedError, 'instance not implemented'
20
- end
19
+ raise NotImplementedError, 'instance not implemented' unless Resource::Defaults::Options.scope_is_active_record?(scope)
20
+ scope.find_by! id_attribute => key
21
21
  end
22
22
 
23
23
  new_instance do |scope|
24
- if defined?(ActiveRecord) && scope.is_a?(Class) && scope < ActiveRecord::Base
25
- scope.new
26
- else
27
- raise NotImplementedError, 'scope not implemented'
28
- end
24
+ raise NotImplementedError, 'new_instance not implemented' unless scope.respond_to?(:new)
25
+ scope.new
29
26
  end
30
27
 
31
28
  before do |context|
@@ -1,3 +1,3 @@
1
1
  module JSONAPIonify
2
- VERSION = "0.11.10"
2
+ VERSION = "0.11.11"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonapionify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.10
4
+ version: 0.11.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Waldrip
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-24 00:00:00.000000000 Z
11
+ date: 2016-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport