pragma-decorator 2.2.0 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0845e95dd2b1793d4db9ddc6280f62fb9420a385416779de9d0de56573a4ba18'
4
- data.tar.gz: 85d1bf273b7748ab953eea1861e3e9935dc548b3d90a6815ffd25fd26c255dbb
3
+ metadata.gz: 8a89663f2c146dfaccaddf296ff7ea5566b59f6d0b271af10a5a70f750374bc0
4
+ data.tar.gz: 6165637c124fa28f02182eb992b59eaa6cfc636e9095ab00d45fc176ffa75396
5
5
  SHA512:
6
- metadata.gz: 596e58d11fc5b7e309ef09a443002d7bd79acb5aada4f7a09eb85b449f357a55995600d0f93ae003d0ef32ef8373c6038c9d187b9a074715c90a91dfa9dc2403
7
- data.tar.gz: f36e57ae761386a60c87245182f9f186803300ec77af42c0a7893568dba99967e85258c6cdfa39bfb8d71f7de21330d7d677dec69edfecae6117bd7036a913b7
6
+ metadata.gz: 87f17f141628bb5f50e5e33365291279fda43a1ce88a7f9448132100d6cbb24359ecdaa879f730739ee71f015e5f03e9040606e45229230214090aa12c992f40
7
+ data.tar.gz: c318c18bf0107c119978b8505fa7406c0123793c757b6eb93bb6cfb66cc87c564d6152e7e95aa750c5e5ad7c076bd810288350794b085f98200107497950653f
data/CHANGELOG.md CHANGED
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [2.2.1]
11
+
12
+ ### Changed
13
+
14
+ - Use [Adaptor](https://github.com/aldesantis/adaptor.rb) for association and pagination adpators
15
+
10
16
  ## [2.2.0]
11
17
 
12
18
  ### Added
@@ -56,7 +62,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
56
62
 
57
63
  First Pragma 2 release.
58
64
 
59
- [Unreleased]: https://github.com/pragmarb/pragma-decorator/compare/v2.1.1...HEAD
65
+ [Unreleased]: https://github.com/pragmarb/pragma-decorator/compare/v2.2.1...HEAD
66
+ [2.2.1]: https://github.com/pragmarb/pragma-decorator/compare/v2.2.0...v2.2.1
60
67
  [2.2.0]: https://github.com/pragmarb/pragma-decorator/compare/v2.1.1...v2.2.0
61
68
  [2.1.1]: https://github.com/pragmarb/pragma-decorator/compare/v2.1.0...v2.1.1
62
69
  [2.1.0]: https://github.com/pragmarb/pragma-decorator/compare/v2.0.0...v2.1.0
@@ -9,6 +9,8 @@ module Pragma
9
9
  #
10
10
  # @api private
11
11
  class ActiveRecord < Base
12
+ include Adaptor
13
+
12
14
  class << self
13
15
  # Returns whether the adapter supports the given model.
14
16
  #
@@ -11,19 +11,6 @@ module Pragma
11
11
  #
12
12
  # @api private
13
13
  class Base
14
- class << self
15
- # Returns whether the adapter supports the given model.
16
- #
17
- # @param _model [Object] a model
18
- #
19
- # @return [Boolean] whether the adpater supports the model
20
- #
21
- # @abstract
22
- def supports?(_model)
23
- fail NotImplementedError
24
- end
25
- end
26
-
27
14
  # @!attribute [r] bond
28
15
  # @return [Bond] the bond this adapter has been instantiated with
29
16
  attr_reader :bond
@@ -10,6 +10,8 @@ module Pragma
10
10
  #
11
11
  # @api private
12
12
  class Poro < Base
13
+ include Adaptor
14
+
13
15
  class << self
14
16
  # Returns whether the adapter supports the model.
15
17
  #
@@ -8,24 +8,8 @@ module Pragma
8
8
  #
9
9
  # @api private
10
10
  module Adapter
11
- # The list of supported adapters, in order of priority.
12
- SUPPORTED_ADAPTERS = [ActiveRecord, Poro].freeze
13
-
14
- # Loads the adapter for the given association bond.
15
- #
16
- # This will try {SUPPORTED_ADAPTERS} in order until it finds an adapter that supports the
17
- # bond's model. When the adapter is found, it will return a new instance of it.
18
- #
19
- # @param bond [Bond] the bond to load the adapter for
20
- #
21
- # @return [Adapter::Base]
22
- #
23
- # @see Adapter::Base.supports?
24
- def self.load_for(bond)
25
- SUPPORTED_ADAPTERS.find do |adapter|
26
- adapter.supports?(bond.model)
27
- end.new(bond)
28
- end
11
+ include Adaptor::Loader
12
+ register ActiveRecord, Poro
29
13
  end
30
14
  end
31
15
  end
@@ -98,7 +98,7 @@ module Pragma
98
98
  private
99
99
 
100
100
  def adapter
101
- @adapter ||= Adapter.load_for(self)
101
+ @adapter ||= Adapter.load_adaptor(self)
102
102
  end
103
103
 
104
104
  def flatten_expand(expand)
@@ -14,17 +14,6 @@ module Pragma
14
14
  # @return [Object] the collection this adapter is working with
15
15
  attr_reader :collection
16
16
 
17
- class << self
18
- # Returns whether this adapter supports the given collection.
19
- #
20
- # @return [Boolean] whether the adapter supports the given collection
21
- #
22
- # @see Adapter.load_for
23
- def supports?(_collection)
24
- fail NotImplementedError
25
- end
26
- end
27
-
28
17
  # Initializes the adapter.
29
18
  #
30
19
  # @param collection [Object] the collection to work with
@@ -17,7 +17,7 @@ module Pragma
17
17
  #
18
18
  # @return [Boolean] whether the adapter supports the given collection
19
19
  #
20
- # @see Adapter.load_for
20
+ # @see Adapter.load_adaptor
21
21
  def supports?(collection)
22
22
  Object.const_defined?('Kaminari') && collection.respond_to?(:prev_page)
23
23
  end
@@ -65,8 +65,6 @@ module Pragma
65
65
  collection.next_page
66
66
  end
67
67
  end
68
-
69
- adapters << Kaminari
70
68
  end
71
69
  end
72
70
  end
@@ -9,6 +9,8 @@ module Pragma
9
9
  #
10
10
  # @api private
11
11
  class WillPaginate < Base
12
+ include Adaptor
13
+
12
14
  class << self
13
15
  # Returns whether this adapter supports the given collection.
14
16
  #
@@ -17,7 +19,7 @@ module Pragma
17
19
  #
18
20
  # @return [Boolean] whether the adapter supports the given collection
19
21
  #
20
- # @see Adapter.load_for
22
+ # @see Adapter.load_adaptor
21
23
  def supports?(collection)
22
24
  Object.const_defined?('WillPaginate') && collection.respond_to?(:previous_page)
23
25
  end
@@ -65,8 +67,6 @@ module Pragma
65
67
  collection.next_page
66
68
  end
67
69
  end
68
-
69
- adapters << WillPaginate
70
70
  end
71
71
  end
72
72
  end
@@ -8,51 +8,8 @@ module Pragma
8
8
  #
9
9
  # @api private
10
10
  module Adapter
11
- class << self
12
- # Loads the adapter for the given collection.
13
- #
14
- # This will try {SUPPORTED_ADAPTERS} in order until it finds an adapter that supports the
15
- # collection. When the adapter is found, it will return a new instance of it.
16
- #
17
- # @param collection [Object] the collection to load the adapter for
18
- #
19
- # @return [Adapter::Base]
20
- #
21
- # @see Adapter::Base.supports?
22
- #
23
- # @raise [AdapterError] if no adapter supports the collection
24
- def load_for(collection)
25
- adapter_klass = adapters.find do |klass|
26
- klass.supports?(collection)
27
- end
28
-
29
- fail NoAdapterError unless adapter_klass
30
-
31
- adapter_klass.new(collection)
32
- end
33
-
34
- # Returns the available pagination adpaters.
35
- #
36
- # This can be used to register new adapters: just append your class to the collection.
37
- #
38
- # @return [Array] an array of pagination adapters
39
- def adapters
40
- @adapters ||= []
41
- end
42
- end
43
-
44
- # This error is raised when no adapter can be found for a collection.
45
- class NoAdapterError < StandardError
46
- # Initializes the adapter.
47
- def initialize
48
- message = <<~MESSAGE.tr("\n", ' ')
49
- No adapter found for the collection. The available adapters are:
50
- #{SUPPORTED_ADAPTERS.map { |a| a.to_s.split('::').last }.join(', ')}.
51
- MESSAGE
52
-
53
- super message
54
- end
55
- end
11
+ include Adaptor::Loader
12
+ register Kaminari, WillPaginate
56
13
  end
57
14
  end
58
15
  end
@@ -88,7 +88,7 @@ module Pragma
88
88
  private
89
89
 
90
90
  def pagination_adapter
91
- @pagination_adapter ||= Pagination::Adapter.load_for(represented)
91
+ @pagination_adapter ||= Pagination::Adapter.load_adaptor(represented)
92
92
  end
93
93
  end
94
94
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Pragma
4
4
  module Decorator
5
- VERSION = '2.2.0'
5
+ VERSION = '2.2.1'
6
6
  end
7
7
  end
@@ -1,9 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'roar'
4
+ require 'adaptor'
4
5
 
5
6
  require 'pragma/decorator/version'
7
+
6
8
  require 'pragma/decorator/base'
9
+
7
10
  require 'pragma/decorator/association'
8
11
  require 'pragma/decorator/association/reflection'
9
12
  require 'pragma/decorator/association/bond'
@@ -12,14 +15,19 @@ require 'pragma/decorator/association/adapter/active_record'
12
15
  require 'pragma/decorator/association/adapter/poro'
13
16
  require 'pragma/decorator/association/adapter'
14
17
  require 'pragma/decorator/association/errors'
18
+
15
19
  require 'pragma/decorator/timestamp'
20
+
16
21
  require 'pragma/decorator/type'
22
+
17
23
  require 'pragma/decorator/collection'
24
+
18
25
  require 'pragma/decorator/pagination'
19
- require 'pragma/decorator/pagination/adapter'
26
+
20
27
  require 'pragma/decorator/pagination/adapter/base'
21
28
  require 'pragma/decorator/pagination/adapter/kaminari'
22
29
  require 'pragma/decorator/pagination/adapter/will_paginate'
30
+ require 'pragma/decorator/pagination/adapter'
23
31
 
24
32
  module Pragma
25
33
  # Represent your API resources in JSON with minimum hassle.
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.add_dependency 'roar', '~> 1.0'
25
25
  spec.add_dependency 'multi_json', '~> 1.12'
26
+ spec.add_dependency 'adaptor', '~> 0.1'
26
27
 
27
28
  spec.add_development_dependency 'bundler'
28
29
  spec.add_development_dependency 'rake'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pragma-decorator
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alessandro Desantis
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-02-14 00:00:00.000000000 Z
11
+ date: 2018-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: roar
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: adaptor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.1'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement