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 +4 -4
- data/.rubocop.yml +2 -0
- data/CHANGELOG.md +8 -0
- data/Gemfile.lock +129 -91
- data/README.md +14 -0
- data/lib/lite/decorator/record.rb +41 -0
- data/lib/lite/decorator/version.rb +1 -1
- data/lib/lite/decorator.rb +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1fbe8cde8843bd22d6181ad4aeaebd5fe3e74eab12a970c3862a6615e4e761a1
|
4
|
+
data.tar.gz: 1304f8031585e3500a704bdbb4091816a8966177325c094e24dfa1f02f7654ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9207d3e6a931bc694d25030ae219d88efb8ec99798623a6b0c36ae20f00131034515be2102075b216c2077bee890772cbd00cb46bfe3c556efab3d393c497c4e
|
7
|
+
data.tar.gz: d43cfa5cb11fd7987476229ec6c95b332c75f4c288ff1343cb2ade16e2214e93b91f914d5c790ca7c5c6510f28b4534b32b99bc7c784532c70a71a51f8c205ad
|
data/.rubocop.yml
CHANGED
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.
|
4
|
+
lite-decorator (1.3.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
actionpack (7.
|
10
|
-
actionview (= 7.
|
11
|
-
activesupport (= 7.
|
12
|
-
|
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.
|
15
|
-
rails-html-sanitizer (~> 1.
|
16
|
-
|
17
|
-
|
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.
|
20
|
-
rails-dom-testing (~> 2.
|
21
|
-
rails-html-sanitizer (~> 1.
|
22
|
-
activemodel (7.
|
23
|
-
activesupport (= 7.
|
24
|
-
activerecord (7.
|
25
|
-
activemodel (= 7.
|
26
|
-
activesupport (= 7.
|
27
|
-
|
28
|
-
|
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
|
-
|
41
|
+
securerandom (>= 0.3)
|
42
|
+
tzinfo (~> 2.0, >= 2.0.5)
|
32
43
|
ast (2.4.2)
|
33
|
-
|
34
|
-
|
35
|
-
|
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.
|
38
|
-
database_cleaner-active_record (
|
39
|
-
database_cleaner-active_record (2.0
|
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.
|
44
|
-
|
45
|
-
|
46
|
-
|
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.
|
61
|
+
generator_spec (0.10.0)
|
49
62
|
activesupport (>= 3.0.0)
|
50
63
|
railties (>= 3.0.0)
|
51
|
-
i18n (1.
|
64
|
+
i18n (1.14.6)
|
52
65
|
concurrent-ruby (~> 1.0)
|
53
|
-
|
54
|
-
|
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.
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
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.
|
64
|
-
parser (3.
|
81
|
+
parallel (1.26.3)
|
82
|
+
parser (3.3.5.0)
|
65
83
|
ast (~> 2.4.1)
|
66
|
-
|
67
|
-
|
68
|
-
|
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
|
-
|
71
|
-
|
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.
|
74
|
-
loofah (~> 2.
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
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.
|
109
|
+
thor (~> 1.0, >= 1.2.2)
|
110
|
+
zeitwerk (~> 2.6)
|
82
111
|
rainbow (3.1.1)
|
83
|
-
rake (13.
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
rspec-
|
92
|
-
|
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.
|
95
|
-
rspec-mocks (3.
|
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.
|
98
|
-
rspec-support (3.
|
99
|
-
rubocop (1.
|
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.
|
135
|
+
parser (>= 3.3.0.2)
|
103
136
|
rainbow (>= 2.2.2, < 4.0)
|
104
|
-
regexp_parser (>=
|
105
|
-
|
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 (>=
|
109
|
-
rubocop-ast (1.
|
110
|
-
parser (>= 3.
|
111
|
-
rubocop-performance (1.
|
112
|
-
rubocop (>= 1.
|
113
|
-
rubocop-ast (>=
|
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 (
|
117
|
-
rubocop (~> 1.
|
118
|
-
ruby-progressbar (1.
|
119
|
-
ruby_parser (3.
|
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
|
-
|
122
|
-
|
154
|
+
securerandom (0.3.1)
|
155
|
+
sexp_processor (4.17.2)
|
156
|
+
sqlite3 (2.0.4)
|
123
157
|
mini_portile2 (~> 2.8.0)
|
124
|
-
|
125
|
-
|
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.
|
128
|
-
|
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.
|
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
|
data/lib/lite/decorator.rb
CHANGED
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.
|
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:
|
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.
|
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)
|