memorandum 2.1.0 → 2.1.1

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: c77ed8d5aeacd512262cfb151e072aec4d627b99
4
- data.tar.gz: 2a8208f28a00b268bc3113425e6e963dc0e7c8c0
3
+ metadata.gz: 8d3980188220f33f7940fc8b959308b0bbd38f8e
4
+ data.tar.gz: 5296434b08e758ad82b5813cf389ed8029db3297
5
5
  SHA512:
6
- metadata.gz: 8bb498553bc570cf01ab1b5f7827cb1c1164c26914ff231ad5b14100447df748094b9de931f2a2cc67fbdb2a90beb0c949e3fbb6fc4a7ab60b769bc747961997
7
- data.tar.gz: 58d9478464993bdefde98fd5266de5e7aeb9d427fd215b361a2dd6182fd4c683ef76247d242ba2aa4ca6544776c6281657e50dcdf8d7333e1a4787348aa719ee
6
+ metadata.gz: fbad7ea1fe756c936a463c7bbb520e925db00f83877fe5146c95217872c245bbd26b733303437398038da7db850d47323559ec08b1eec19f928852f5bc80690f
7
+ data.tar.gz: 159b25d64d9d61e559ccbe51a506d6bb50d4273a470f9adde14a6667e5b01a80bcf6a23c0ee157d02debc55a5f48d94bdb371575045b239f7f771d755ae30dcb
@@ -1,3 +1,3 @@
1
1
  module Memorandum
2
- VERSION = '2.1.0'.freeze
2
+ VERSION = '2.1.1'.freeze
3
3
  end
data/lib/memorandum.rb CHANGED
@@ -1,22 +1,23 @@
1
1
  require 'ice_nine'
2
2
 
3
3
  module Memorandum
4
+ def self.extended base
5
+ base.send :include, InstanceMethods
6
+ end
7
+
4
8
  def memo *arguments
5
9
  name = arguments.pop
6
10
  flags = arguments
7
11
 
8
- memoized_statuses = "@memoized_statuses_for_#{name}"
9
- memoized_values = "@memoized_values_for_#{name}"
10
- unmemoized_name = "unmemoized_#{name}"
12
+ memoized_statuses = memorandum_ivar_name MEMORANDUM_STATUSES, name
13
+ memoized_values = memorandum_ivar_name MEMORANDUM_VALUES, name
14
+ unmemoized_name = "#{MEMORANDUM_UNMEMOIZED}_#{name}"
11
15
 
12
16
  alias_method unmemoized_name, name
13
17
 
14
18
  define_method name do |*args|
15
- statuses = instance_variable_get(memoized_statuses) \
16
- || instance_variable_set(memoized_statuses, Hash[])
17
-
18
- values = instance_variable_get(memoized_values) \
19
- || instance_variable_set(memoized_values, Hash[])
19
+ statuses = memorandum_fetch memoized_statuses, Hash[]
20
+ values = memorandum_fetch memoized_values, Hash[]
20
21
 
21
22
  unless statuses[args]
22
23
  value = send unmemoized_name, *args
@@ -31,4 +32,25 @@ module Memorandum
31
32
  values[args]
32
33
  end
33
34
  end
35
+
36
+ private
37
+
38
+ MEMORANDUM_MEMOIZED = 'memoized'.freeze
39
+ MEMORANDUM_STATUSES = 'statuses'.freeze
40
+ MEMORANDUM_UNMEMOIZED = 'unmemoized'.freeze
41
+ MEMORANDUM_VALUES = 'values'.freeze
42
+ MEMORANDUM_BANG = '__BANG__'.freeze
43
+ MEMORANDUM_BOOL = '__BOOL__'.freeze
44
+
45
+ def memorandum_ivar_name name, method_name
46
+ "@#{MEMORANDUM_MEMOIZED}_#{name}_for_#{method_name}"
47
+ .gsub('!', MEMORANDUM_BANG)
48
+ .gsub('?', MEMORANDUM_BOOL)
49
+ end
50
+
51
+ module InstanceMethods
52
+ def memorandum_fetch name, default
53
+ instance_variable_get(name) || instance_variable_set(name, default)
54
+ end
55
+ end
34
56
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: memorandum
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Lude