mighty_struct 0.1.5 → 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
  SHA1:
3
- metadata.gz: abd6b402fa2a8f25232163bb9aa327611d4a0051
4
- data.tar.gz: d571e84a5c3fc9a35d84c691b536b296f90cf852
3
+ metadata.gz: 642f851ca113981d37948247c72b591f899859a8
4
+ data.tar.gz: 299295c4805aef048033602b69507c4c15a6af3d
5
5
  SHA512:
6
- metadata.gz: 942baa545e3901d83bc6a2c1eda98c936325f5ea5a0ce2eae33e81eebfe1dcbf43320d56e2c423c74dbe8b315e79cdfd2564a5c8c86aafbb5c02639d221cb224
7
- data.tar.gz: e4e0ad795fd4676e7035f04a7ca4644a1f83c1ae3f81f89170063c927cf957b0a5bbaf23e7f4b1553f7c0f45a02b940b2fba0457403fe61302c19fa09977cc06
6
+ metadata.gz: 55ff409bb2d69a8c1b701196b3606bac83f02183b7265fcc95639c32cecad7aeed2068bcacb00d3ed342a6e66cce2203a84f41becb5f45b8837b9be40eb32e6c
7
+ data.tar.gz: 694ad977679d128448db968c403222204dcda4caf9a4402264e05be27b5c0b9223a3d2ff51d03de63d084e8b74d501dd1d402c4695264c42ee57f1bfb981efc1
data/README.md CHANGED
@@ -50,7 +50,7 @@ Or play with it on your own. It's just one command (line) away.
50
50
  git clone https://github.com/msievers/mighty_struct.git && cd mighty_struct && bundle && bin/console
51
51
  ```
52
52
 
53
- ## Another of this "method invocation" hashes? Really?!
53
+ ## Another of this "method invocation hashes", really?!
54
54
 
55
55
  Before I started coding this, I tried the following three alternatives
56
56
 
@@ -15,17 +15,16 @@ class MightyStruct
15
15
  raise ArgumentError.new("Cannot create a an instance of #{self.class} for the given object!")
16
16
  end
17
17
 
18
- @cache = {}
19
- @cache_mode = options[:caching] || :enabled
18
+ @cache = options[:caching] == :enabled ? {} : nil
20
19
 
21
20
  if (@object = object).respond_to?(:keys)
22
21
  object.keys.each do |_key|
23
22
  unless respond_to?(_key)
24
23
  define_singleton_method(_key) do
25
- if @cache_mode == :disabled
26
- self.class.new?(value = @object[_key]) ? self.class.new(value) : value
24
+ if @cache
25
+ @cache[_key] ||= self.class.new?(value = @object[_key]) ? self.class.new(value) : value
27
26
  else
28
- @cache[_key] ||= self.class.new?(value = @object[_key]) ? self.class.new(value) : value
27
+ self.class.new?(value = @object[_key]) ? self.class.new(value) : value
29
28
  end
30
29
  end
31
30
  end
@@ -38,7 +37,7 @@ class MightyStruct
38
37
  #
39
38
  def method_missing(method_name, *arguments, &block)
40
39
  if @object.respond_to?(method_name)
41
- @cache.clear if @cache_mode == :smart # clear the properties cache if we are smart
40
+ @cache.clear if @cache # clear the properties cache, because the called method may have side-effects
42
41
  result = @object.send(method_name, *arguments, &block)
43
42
 
44
43
  # ensure that results of called methods are mighty structs again
@@ -1,3 +1,3 @@
1
1
  class MightyStruct
2
- VERSION = "0.1.5"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mighty_struct
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Sievers