pragma-decorator 2.2.0 → 2.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -1
- data/lib/pragma/decorator/association/adapter/active_record.rb +2 -0
- data/lib/pragma/decorator/association/adapter/base.rb +0 -13
- data/lib/pragma/decorator/association/adapter/poro.rb +2 -0
- data/lib/pragma/decorator/association/adapter.rb +2 -18
- data/lib/pragma/decorator/association/bond.rb +1 -1
- data/lib/pragma/decorator/pagination/adapter/base.rb +0 -11
- data/lib/pragma/decorator/pagination/adapter/kaminari.rb +1 -3
- data/lib/pragma/decorator/pagination/adapter/will_paginate.rb +3 -3
- data/lib/pragma/decorator/pagination/adapter.rb +2 -45
- data/lib/pragma/decorator/pagination.rb +1 -1
- data/lib/pragma/decorator/version.rb +1 -1
- data/lib/pragma/decorator.rb +9 -1
- data/pragma-decorator.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a89663f2c146dfaccaddf296ff7ea5566b59f6d0b271af10a5a70f750374bc0
|
4
|
+
data.tar.gz: 6165637c124fa28f02182eb992b59eaa6cfc636e9095ab00d45fc176ffa75396
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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
|
@@ -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
|
@@ -8,24 +8,8 @@ module Pragma
|
|
8
8
|
#
|
9
9
|
# @api private
|
10
10
|
module Adapter
|
11
|
-
|
12
|
-
|
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
|
@@ -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.
|
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.
|
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
|
-
|
12
|
-
|
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
|
data/lib/pragma/decorator.rb
CHANGED
@@ -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
|
-
|
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.
|
data/pragma-decorator.gemspec
CHANGED
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.
|
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-
|
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
|