pragma-decorator 2.2.6 → 2.3.0

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: 98b91700778dde7caf78fca62ad944dd136d8c2ce8d48bb598b085ad8567c741
4
- data.tar.gz: 9d428e1e9e9c0c6eb00a0e128728da271375d939c60230fe67f7c62466086cc2
3
+ metadata.gz: 67f54c6658ab7c26683372702f60dbf57d1b387b36e4f76906aa43564a895f3c
4
+ data.tar.gz: 1e6dda3d51df96252a20f5be71fac7c97bfcafdcd6da3f9557dd114fc9ffd350
5
5
  SHA512:
6
- metadata.gz: 72b88fd97948adf0f682469ab5854cb302fd967d09da55afc04974d5a2200748dbf70d36699b810eb4d9999723b72e7088d5a0074846b64d17639ad6167becdb
7
- data.tar.gz: c7c96cce6da9dff0946e003a0ab990013ccf1dfc02e77656b31e4ebd747007e79341c7fc8d042f981c14e8e3d6cc80e6a0dc6ce345bb9fec8fd58d43dc7c71bb
6
+ metadata.gz: 034e2d52748a517a49d795f62c5f7eef4853687ecf1129a7a252d568a85d64d888910f1233e113e05908d3600b0f30f405582669b9939ff57ee49001ffc2ee9a
7
+ data.tar.gz: ce705e07d802802cb6517f70fc70d433812a014fdbdb587bc83b19b4ca67f3ebca1736c4a6d0e051cf8841dfb9138f7cb5d11aecbc43a0cb58e27abaf5c20fcd
@@ -36,16 +36,16 @@ Metrics/LineLength:
36
36
  Max: 100
37
37
  AllowURI: true
38
38
 
39
- Layout/FirstParameterIndentation:
39
+ Layout/IndentFirstArgument:
40
40
  Enabled: false
41
41
 
42
42
  Layout/MultilineMethodCallIndentation:
43
43
  EnforcedStyle: indented
44
44
 
45
- Layout/IndentArray:
45
+ Layout/IndentFirstArrayElement:
46
46
  EnforcedStyle: consistent
47
47
 
48
- Layout/IndentHash:
48
+ Layout/IndentFirstHashElement:
49
49
  EnforcedStyle: consistent
50
50
 
51
51
  Style/SignalException:
@@ -97,9 +97,6 @@ Capybara/FeatureMethods:
97
97
  Metrics/ClassLength:
98
98
  Enabled: false
99
99
 
100
- Style/GuardClause:
101
- Enabled: false
102
-
103
100
  Naming/FileName:
104
101
  Exclude:
105
102
  - 'pragma-decorator.gemspec'
@@ -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.3.0]
11
+
12
+ ### Added
13
+
14
+ - `Collection` now assumes the instance decorator is `Instance`
15
+
10
16
  ## [2.2.6]
11
17
 
12
18
  ### Fixed
@@ -93,7 +99,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
93
99
 
94
100
  First Pragma 2 release.
95
101
 
96
- [Unreleased]: https://github.com/pragmarb/pragma-decorator/compare/v2.2.6...HEAD
102
+ [Unreleased]: https://github.com/pragmarb/pragma-decorator/compare/v2.3.0...HEAD
103
+ [2.3.0]: https://github.com/pragmarb/pragma-decorator/compare/v2.2.6...v2.3.0
97
104
  [2.2.6]: https://github.com/pragmarb/pragma-decorator/compare/v2.2.5...v2.2.6
98
105
  [2.2.5]: https://github.com/pragmarb/pragma-decorator/compare/v2.2.4...v2.2.5
99
106
  [2.2.4]: https://github.com/pragmarb/pragma-decorator/compare/v2.2.3...v2.2.4
data/README.md CHANGED
@@ -118,7 +118,13 @@ module API
118
118
  end
119
119
  ```
120
120
 
121
- Note: `array` is already overridden with the more language-agnostic `list`.
121
+ `Array` and `ActiveRecord::Relation` are already overridden as `list` to avoid exposing internal
122
+ details. If you want to specify your own global overrides, you can do it by adding entries to the
123
+ `Pragma::Decorator::Type.overrides` hash:
124
+
125
+ ```ruby
126
+ Pragma::Decorator::Type.overrides['Article'] = 'post'
127
+ ```
122
128
 
123
129
  ### Timestamps
124
130
 
@@ -244,7 +250,7 @@ module API
244
250
  module Decorator
245
251
  class Collection < Pragma::Decorator::Base
246
252
  include Pragma::Decorator::Collection
247
- decorate_with Instance # specify the instance decorator
253
+ decorate_with Instance # this is optional, the default is 'Instance'
248
254
 
249
255
  property :total_cents, exec_context: :decorator
250
256
 
@@ -118,6 +118,7 @@ module Pragma
118
118
 
119
119
  expand.each do |property|
120
120
  next if self.class.associations.key?(property.to_sym) || property.include?('.')
121
+
121
122
  fail Association::AssociationNotFound, property
122
123
  end
123
124
  end
@@ -11,8 +11,6 @@ module Pragma
11
11
  # class ArticlesDecorator < Pragma::Decorator::Base
12
12
  # include Pragma::Decorator::Collection
13
13
  #
14
- # decorate_with ArticleDecorator
15
- #
16
14
  # property :total_count, exec_context: :decorator
17
15
  #
18
16
  # def total_count
@@ -60,10 +58,6 @@ module Pragma
60
58
  end
61
59
 
62
60
  module ClassMethods # :nodoc:
63
- # @!attribute [r]
64
- # @return [Class\Proc] the instance decorator to use
65
- attr_reader :instance_decorator
66
-
67
61
  # Defines the decorator to use for each resource in the collection.
68
62
  #
69
63
  # @param decorator [Class|Proc] a decorator class, or a callable accepting a represented
@@ -71,6 +65,18 @@ module Pragma
71
65
  def decorate_with(decorator)
72
66
  @instance_decorator = decorator
73
67
  end
68
+
69
+ # Returns the instance decorator for this collection.
70
+ #
71
+ # If no decorator was set manually with {#decorate_with}, this assumes the decorator is in
72
+ # the same namespace as the current class and is called +Instance+.
73
+ #
74
+ # @return [Class\Proc] the instance decorator to use
75
+ def instance_decorator
76
+ @instance_decorator ||= Object.const_get((
77
+ name.split('::')[0..-2] + ['Instance']
78
+ ).join('::'))
79
+ end
74
80
  end
75
81
  end
76
82
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Pragma
4
4
  module Decorator
5
- VERSION = '2.2.6'
5
+ VERSION = '2.3.0'
6
6
  end
7
7
  end
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.6
4
+ version: 2.3.0
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-08-12 00:00:00.000000000 Z
11
+ date: 2019-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: roar