lazy_load_attributes 0.1.0 → 0.2.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 +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/lazy_load_attributes/version.rb +1 -1
- data/lib/lazy_load_attributes.rb +10 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77077be042f7f2b89e8742883132d75013b137b6d062bc6ad62be873e56873a6
|
4
|
+
data.tar.gz: 355688d90be092bb2a82bed59c12a4caed31b954639496a4a53d513ef30911fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1af551e9c15502e1fb5abc8b27da1469396c8ffa78d353cf302981177ae8cbc597d254639558b8fd4cd07772b6e9e0a7e011bf255cb28d070ef2efef8fbd4f50
|
7
|
+
data.tar.gz: 9a57623803cd3f1a8afad20e87c7662c00d69a30c7e7dec511a515944de6d24f91d9fb6c76dc9a88bfdad3be34ae6bd75a3e367565047f5f2c57d5d7c9f89a61
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
## [Unreleased Changes]
|
2
2
|
|
3
|
+
## 0.2.0
|
4
|
+
|
5
|
+
- add .lazy_attr_accessor
|
6
|
+
- .lazy_attr_reader and .lazy_attr_accessor return the same value as their normal counterparts
|
7
|
+
- #eager_load_attributes! returns the names of only the attributes which were eager-loaded
|
8
|
+
|
3
9
|
## 0.1.0
|
4
10
|
|
5
11
|
- initial release
|
data/lib/lazy_load_attributes.rb
CHANGED
@@ -22,6 +22,11 @@ module LazyLoadAttributes
|
|
22
22
|
.reduce(&:|)
|
23
23
|
end
|
24
24
|
|
25
|
+
def lazy_attr_accessor(attribute, &initializer)
|
26
|
+
lazy_attr_reader(attribute, &initializer)
|
27
|
+
attr_writer attribute
|
28
|
+
end
|
29
|
+
|
25
30
|
def lazy_attr_reader(attribute, &initializer) # rubocop:disable Metrics/MethodLength
|
26
31
|
raise NameError, "bad attribute name '#{attribute}' (use a-z, 0-9, _)" unless attribute.match? ATTR_NAME_REGEX
|
27
32
|
raise ArgumentError, "no initializer block given in lazy-loaded attribute definition" if initializer.nil?
|
@@ -36,12 +41,16 @@ module LazyLoadAttributes
|
|
36
41
|
instance_variable_set(instance_variable, instance_eval(&initializer))
|
37
42
|
end
|
38
43
|
end
|
44
|
+
|
45
|
+
nil
|
39
46
|
end
|
40
47
|
end
|
41
48
|
|
42
49
|
module InstanceMethods
|
43
50
|
def eager_load_attributes!
|
44
|
-
self.class.all_lazy_attributes
|
51
|
+
self.class.all_lazy_attributes
|
52
|
+
.reject { |attribute| instance_variable_defined?(:"@#{attribute}") }
|
53
|
+
.each { |attribute| send(attribute) }
|
45
54
|
end
|
46
55
|
end
|
47
56
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lazy_load_attributes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nate Eizenga
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry-byebug
|