lite-decorator 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 60d3ae53a48e641cb07f39420c98869a64197e59eecf15b6c268e87a3ef05edf
4
- data.tar.gz: cd8539721c92583c28e19831d17ac8bf163ba96dad188beba0f3ee4f10237b20
3
+ metadata.gz: 1fbe8cde8843bd22d6181ad4aeaebd5fe3e74eab12a970c3862a6615e4e761a1
4
+ data.tar.gz: 1304f8031585e3500a704bdbb4091816a8966177325c094e24dfa1f02f7654ed
5
5
  SHA512:
6
- metadata.gz: 301f80a6ca6be17abc0a0b066710e425778df93a0a45b39567f4b6f4900708a9c52f26b68b1bd3c29be7fe27683451e35806843d8c672a3456a2e314bd6b9a0a
7
- data.tar.gz: 781fd14419aa60d5d9ce058812c47c09132677ea48650ffb3fada9cc16bd754a13ab7845d094784a379748431dc7d1ac903eeabfd803bdc7a6bc63e3b3091e96
6
+ metadata.gz: 9207d3e6a931bc694d25030ae219d88efb8ec99798623a6b0c36ae20f00131034515be2102075b216c2077bee890772cbd00cb46bfe3c556efab3d393c497c4e
7
+ data.tar.gz: d43cfa5cb11fd7987476229ec6c95b332c75f4c288ff1343cb2ade16e2214e93b91f914d5c790ca7c5c6510f28b4534b32b99bc7c784532c70a71a51f8c205ad
data/.rubocop.yml CHANGED
@@ -6,6 +6,8 @@ AllCops:
6
6
  NewCops: enable
7
7
  DisplayCopNames: true
8
8
  DisplayStyleGuide: true
9
+ Gemspec/DevelopmentDependencies:
10
+ EnforcedStyle: gemspec
9
11
  Gemspec/RequiredRubyVersion:
10
12
  Enabled: false
11
13
  Layout/EmptyLinesAroundAttributeAccessor:
data/CHANGELOG.md CHANGED
@@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.3.0] - 2024-09-20
10
+ ### Added
11
+ - Record lazy load module
12
+
13
+ ## [1.2.1] - 2024-09-20
14
+ ### Changed
15
+ - Bump dependencies
16
+
9
17
  ## [1.2.0] - 2022-11-19
10
18
  ### Changed
11
19
  - Improved docs
data/Gemfile.lock CHANGED
@@ -1,131 +1,169 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lite-decorator (1.2.0)
4
+ lite-decorator (1.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- actionpack (7.0.4)
10
- actionview (= 7.0.4)
11
- activesupport (= 7.0.4)
12
- rack (~> 2.0, >= 2.2.0)
9
+ actionpack (7.2.1)
10
+ actionview (= 7.2.1)
11
+ activesupport (= 7.2.1)
12
+ nokogiri (>= 1.8.5)
13
+ racc
14
+ rack (>= 2.2.4, < 3.2)
15
+ rack-session (>= 1.0.1)
13
16
  rack-test (>= 0.6.3)
14
- rails-dom-testing (~> 2.0)
15
- rails-html-sanitizer (~> 1.0, >= 1.2.0)
16
- actionview (7.0.4)
17
- activesupport (= 7.0.4)
17
+ rails-dom-testing (~> 2.2)
18
+ rails-html-sanitizer (~> 1.6)
19
+ useragent (~> 0.16)
20
+ actionview (7.2.1)
21
+ activesupport (= 7.2.1)
18
22
  builder (~> 3.1)
19
- erubi (~> 1.4)
20
- rails-dom-testing (~> 2.0)
21
- rails-html-sanitizer (~> 1.1, >= 1.2.0)
22
- activemodel (7.0.4)
23
- activesupport (= 7.0.4)
24
- activerecord (7.0.4)
25
- activemodel (= 7.0.4)
26
- activesupport (= 7.0.4)
27
- activesupport (7.0.4)
28
- concurrent-ruby (~> 1.0, >= 1.0.2)
23
+ erubi (~> 1.11)
24
+ rails-dom-testing (~> 2.2)
25
+ rails-html-sanitizer (~> 1.6)
26
+ activemodel (7.2.1)
27
+ activesupport (= 7.2.1)
28
+ activerecord (7.2.1)
29
+ activemodel (= 7.2.1)
30
+ activesupport (= 7.2.1)
31
+ timeout (>= 0.4.0)
32
+ activesupport (7.2.1)
33
+ base64
34
+ bigdecimal
35
+ concurrent-ruby (~> 1.0, >= 1.3.1)
36
+ connection_pool (>= 2.2.5)
37
+ drb
29
38
  i18n (>= 1.6, < 2)
39
+ logger (>= 1.4.2)
30
40
  minitest (>= 5.1)
31
- tzinfo (~> 2.0)
41
+ securerandom (>= 0.3)
42
+ tzinfo (~> 2.0, >= 2.0.5)
32
43
  ast (2.4.2)
33
- builder (3.2.4)
34
- colorize (0.8.1)
35
- concurrent-ruby (1.1.10)
44
+ base64 (0.2.0)
45
+ bigdecimal (3.1.8)
46
+ builder (3.3.0)
47
+ concurrent-ruby (1.3.4)
48
+ connection_pool (2.4.1)
36
49
  crass (1.0.6)
37
- database_cleaner (2.0.1)
38
- database_cleaner-active_record (~> 2.0.0)
39
- database_cleaner-active_record (2.0.1)
50
+ database_cleaner (2.0.2)
51
+ database_cleaner-active_record (>= 2, < 3)
52
+ database_cleaner-active_record (2.2.0)
40
53
  activerecord (>= 5.a)
41
54
  database_cleaner-core (~> 2.0.0)
42
55
  database_cleaner-core (2.0.1)
43
- diff-lcs (1.5.0)
44
- erubi (1.11.0)
45
- fasterer (0.10.0)
46
- colorize (~> 0.7)
56
+ diff-lcs (1.5.1)
57
+ drb (2.2.1)
58
+ erubi (1.13.0)
59
+ fasterer (0.11.0)
47
60
  ruby_parser (>= 3.19.1)
48
- generator_spec (0.9.4)
61
+ generator_spec (0.10.0)
49
62
  activesupport (>= 3.0.0)
50
63
  railties (>= 3.0.0)
51
- i18n (1.12.0)
64
+ i18n (1.14.6)
52
65
  concurrent-ruby (~> 1.0)
53
- json (2.6.2)
54
- loofah (2.19.0)
66
+ io-console (0.7.2)
67
+ irb (1.14.0)
68
+ rdoc (>= 4.0.0)
69
+ reline (>= 0.4.2)
70
+ json (2.7.2)
71
+ language_server-protocol (3.17.0.3)
72
+ logger (1.6.1)
73
+ loofah (2.22.0)
55
74
  crass (~> 1.0.2)
56
- nokogiri (>= 1.5.9)
57
- method_source (1.0.0)
58
- mini_portile2 (2.8.0)
59
- minitest (5.16.3)
60
- nokogiri (1.13.9)
61
- mini_portile2 (~> 2.8.0)
75
+ nokogiri (>= 1.12.0)
76
+ mini_portile2 (2.8.7)
77
+ minitest (5.25.1)
78
+ nokogiri (1.16.7)
79
+ mini_portile2 (~> 2.8.2)
62
80
  racc (~> 1.4)
63
- parallel (1.22.1)
64
- parser (3.1.2.1)
81
+ parallel (1.26.3)
82
+ parser (3.3.5.0)
65
83
  ast (~> 2.4.1)
66
- racc (1.6.0)
67
- rack (2.2.4)
68
- rack-test (2.0.2)
84
+ racc
85
+ psych (5.1.2)
86
+ stringio
87
+ racc (1.8.1)
88
+ rack (3.1.7)
89
+ rack-session (2.0.0)
90
+ rack (>= 3.0.0)
91
+ rack-test (2.1.0)
69
92
  rack (>= 1.3)
70
- rails-dom-testing (2.0.3)
71
- activesupport (>= 4.2.0)
93
+ rackup (2.1.0)
94
+ rack (>= 3)
95
+ webrick (~> 1.8)
96
+ rails-dom-testing (2.2.0)
97
+ activesupport (>= 5.0.0)
98
+ minitest
72
99
  nokogiri (>= 1.6)
73
- rails-html-sanitizer (1.4.3)
74
- loofah (~> 2.3)
75
- railties (7.0.4)
76
- actionpack (= 7.0.4)
77
- activesupport (= 7.0.4)
78
- method_source
100
+ rails-html-sanitizer (1.6.0)
101
+ loofah (~> 2.21)
102
+ nokogiri (~> 1.14)
103
+ railties (7.2.1)
104
+ actionpack (= 7.2.1)
105
+ activesupport (= 7.2.1)
106
+ irb (~> 1.13)
107
+ rackup (>= 1.0.0)
79
108
  rake (>= 12.2)
80
- thor (~> 1.0)
81
- zeitwerk (~> 2.5)
109
+ thor (~> 1.0, >= 1.2.2)
110
+ zeitwerk (~> 2.6)
82
111
  rainbow (3.1.1)
83
- rake (13.0.6)
84
- regexp_parser (2.6.1)
85
- rexml (3.2.5)
86
- rspec (3.12.0)
87
- rspec-core (~> 3.12.0)
88
- rspec-expectations (~> 3.12.0)
89
- rspec-mocks (~> 3.12.0)
90
- rspec-core (3.12.0)
91
- rspec-support (~> 3.12.0)
92
- rspec-expectations (3.12.0)
112
+ rake (13.2.1)
113
+ rdoc (6.7.0)
114
+ psych (>= 4.0.0)
115
+ regexp_parser (2.9.2)
116
+ reline (0.5.10)
117
+ io-console (~> 0.5)
118
+ rspec (3.13.0)
119
+ rspec-core (~> 3.13.0)
120
+ rspec-expectations (~> 3.13.0)
121
+ rspec-mocks (~> 3.13.0)
122
+ rspec-core (3.13.1)
123
+ rspec-support (~> 3.13.0)
124
+ rspec-expectations (3.13.3)
93
125
  diff-lcs (>= 1.2.0, < 2.0)
94
- rspec-support (~> 3.12.0)
95
- rspec-mocks (3.12.0)
126
+ rspec-support (~> 3.13.0)
127
+ rspec-mocks (3.13.1)
96
128
  diff-lcs (>= 1.2.0, < 2.0)
97
- rspec-support (~> 3.12.0)
98
- rspec-support (3.12.0)
99
- rubocop (1.39.0)
129
+ rspec-support (~> 3.13.0)
130
+ rspec-support (3.13.1)
131
+ rubocop (1.66.1)
100
132
  json (~> 2.3)
133
+ language_server-protocol (>= 3.17.0)
101
134
  parallel (~> 1.10)
102
- parser (>= 3.1.2.1)
135
+ parser (>= 3.3.0.2)
103
136
  rainbow (>= 2.2.2, < 4.0)
104
- regexp_parser (>= 1.8, < 3.0)
105
- rexml (>= 3.2.5, < 4.0)
106
- rubocop-ast (>= 1.23.0, < 2.0)
137
+ regexp_parser (>= 2.4, < 3.0)
138
+ rubocop-ast (>= 1.32.2, < 2.0)
107
139
  ruby-progressbar (~> 1.7)
108
- unicode-display_width (>= 1.4.0, < 3.0)
109
- rubocop-ast (1.23.0)
110
- parser (>= 3.1.1.0)
111
- rubocop-performance (1.15.1)
112
- rubocop (>= 1.7.0, < 2.0)
113
- rubocop-ast (>= 0.4.0)
140
+ unicode-display_width (>= 2.4.0, < 3.0)
141
+ rubocop-ast (1.32.3)
142
+ parser (>= 3.3.1.0)
143
+ rubocop-performance (1.22.1)
144
+ rubocop (>= 1.48.1, < 2.0)
145
+ rubocop-ast (>= 1.31.1, < 2.0)
114
146
  rubocop-rake (0.6.0)
115
147
  rubocop (~> 1.0)
116
- rubocop-rspec (2.15.0)
117
- rubocop (~> 1.33)
118
- ruby-progressbar (1.11.0)
119
- ruby_parser (3.19.1)
148
+ rubocop-rspec (3.0.5)
149
+ rubocop (~> 1.61)
150
+ ruby-progressbar (1.13.0)
151
+ ruby_parser (3.21.1)
152
+ racc (~> 1.5)
120
153
  sexp_processor (~> 4.16)
121
- sexp_processor (4.16.1)
122
- sqlite3 (1.5.4)
154
+ securerandom (0.3.1)
155
+ sexp_processor (4.17.2)
156
+ sqlite3 (2.0.4)
123
157
  mini_portile2 (~> 2.8.0)
124
- thor (1.2.1)
125
- tzinfo (2.0.5)
158
+ stringio (3.1.1)
159
+ thor (1.3.2)
160
+ timeout (0.4.1)
161
+ tzinfo (2.0.6)
126
162
  concurrent-ruby (~> 1.0)
127
- unicode-display_width (2.3.0)
128
- zeitwerk (2.6.6)
163
+ unicode-display_width (2.6.0)
164
+ useragent (0.16.10)
165
+ webrick (1.8.1)
166
+ zeitwerk (2.6.18)
129
167
 
130
168
  PLATFORMS
131
169
  ruby
@@ -146,4 +184,4 @@ DEPENDENCIES
146
184
  sqlite3
147
185
 
148
186
  BUNDLED WITH
149
- 2.3.26
187
+ 2.5.19
data/README.md CHANGED
@@ -26,6 +26,7 @@ Or install it yourself as:
26
26
 
27
27
  * [Setup](#setup)
28
28
  * [Usage](#usage)
29
+ * [ActiveRecord](#active_record)
29
30
 
30
31
  ## Setup
31
32
 
@@ -58,6 +59,7 @@ end
58
59
  ## Usage
59
60
 
60
61
  To access the decorator you need to pass the object to the decorator class.
62
+ PORO's just like active record objects can be decorated as well in this method.
61
63
 
62
64
  #### Instance
63
65
  ```ruby
@@ -73,6 +75,18 @@ collection = UserDecorator.new(users)
73
75
  collection.map(&:full_name) #=> ["John Doe", "Jane Poe"]
74
76
  ```
75
77
 
78
+ ## ActiveRecord
79
+
80
+ Including the record module will automatically lazy delegate methods to decorators
81
+ if available. If neither the class instance and the decorator contain the method,
82
+ a `NoMethodError` just like normal.
83
+
84
+ ```ruby
85
+ class User < ActiveRecord::Base
86
+ include Lite::Decorator::Record
87
+ end
88
+ ```
89
+
76
90
  ## Development
77
91
 
78
92
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lite
4
+ module Decorator
5
+ module Record
6
+
7
+ def decorator_class
8
+ "#{self.class.name}Decorator".safe_constantize
9
+ end
10
+
11
+ def decorator
12
+ @decorator ||= decorator_class&.new(self)
13
+ end
14
+
15
+ private
16
+
17
+ def method_missing(method_name, *args, **kwargs, &)
18
+ if respond_to_method?(method_name)
19
+ decorator.send(method_name, *args, **kwargs, &)
20
+ else
21
+ super
22
+ end
23
+ end
24
+
25
+ def respond_to_method_cache
26
+ @respond_to_method_cache ||= {}
27
+ end
28
+
29
+ def respond_to_method?(method_name)
30
+ return respond_to_method_cache[method_name] if respond_to_method_cache.key?(method_name)
31
+
32
+ respond_to_method_cache[method_name] = decorator.present? && decorator.public_methods.include?(method_name)
33
+ end
34
+
35
+ def respond_to_missing?(method_name, include_private = false)
36
+ respond_to_method?(method_name) || super
37
+ end
38
+
39
+ end
40
+ end
41
+ end
@@ -3,7 +3,7 @@
3
3
  module Lite
4
4
  module Decorator
5
5
 
6
- VERSION = "1.2.0"
6
+ VERSION = "1.3.0"
7
7
 
8
8
  end
9
9
  end
@@ -4,3 +4,4 @@ require "generators/rails/decorator_generator" if defined?(Rails::Generators)
4
4
 
5
5
  require "lite/decorator/version"
6
6
  require "lite/decorator/base"
7
+ require "lite/decorator/record"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lite-decorator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Gomez
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-11-19 00:00:00.000000000 Z
11
+ date: 2024-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -204,6 +204,7 @@ files:
204
204
  - lib/generators/rails/templates/decorator.rb.tt
205
205
  - lib/lite/decorator.rb
206
206
  - lib/lite/decorator/base.rb
207
+ - lib/lite/decorator/record.rb
207
208
  - lib/lite/decorator/version.rb
208
209
  - lite-decorator.gemspec
209
210
  homepage: http://drexed.github.io/lite-decorator
@@ -230,7 +231,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
230
231
  - !ruby/object:Gem::Version
231
232
  version: '0'
232
233
  requirements: []
233
- rubygems_version: 3.3.26
234
+ rubygems_version: 3.5.19
234
235
  signing_key:
235
236
  specification_version: 4
236
237
  summary: Ruby Decorator based framework (aka decorator/presenter objects)