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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ad7ccf90af014e09150c0445aa798702fbdcff84203562aa2c7cd5fc960ed090
4
- data.tar.gz: 3bd0d5a98e55beb2ef2c7c0e58c65b0be5ccff570ef262a43a134804566837c8
3
+ metadata.gz: 77077be042f7f2b89e8742883132d75013b137b6d062bc6ad62be873e56873a6
4
+ data.tar.gz: 355688d90be092bb2a82bed59c12a4caed31b954639496a4a53d513ef30911fa
5
5
  SHA512:
6
- metadata.gz: e0a48e5efc3240a93dc0624d572188b1ab88a02eb80b1e3ab7733d76c8a08e6eefbfd8034af8f11c0785255efbc6a900e68557c2f47480b9e304d2e244511fd5
7
- data.tar.gz: 403da3d15930f376b7fef7965f37e5e57a99d322d45746f4729659cd161b12ba08fed34530e96c45783f67cbdf88d2346aac80e36e4cd35e9907ba342d4829d7
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LazyLoadAttributes
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
@@ -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.each { |attribute| send(attribute) }
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.1.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: 2022-10-31 00:00:00.000000000 Z
11
+ date: 2023-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry-byebug