mandate 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/LICENCE +19 -0
- data/lib/mandate/call_injector.rb +4 -0
- data/lib/mandate/memoize.rb +22 -5
- data/lib/mandate/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bc2c241c950d6f4b31b4b425bbe49e1a663852a
|
4
|
+
data.tar.gz: 9761af041c6f0c052d04055e5aec6f1be28fef10
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8030c84e5c7a57f1418fa42a6e1e09117af1d14fecf828ff2a741b9d85f593a6c7839f4136603f88ee895be8e42b10956fa943fe461cbeba77bd53448a211c7
|
7
|
+
data.tar.gz: 8db8fa6185037589f6e7573be7da0f60d4e21e0c1edb2fb6d80b29f5a38cbb14095d8e59ee07cc7f19b2e9da99f1e077df96cd9a44dcd6737dead9bbd730b2b1
|
data/LICENCE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2007 Thalamus AI Ltd
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
SOFTWARE.
|
data/lib/mandate/memoize.rb
CHANGED
@@ -1,15 +1,35 @@
|
|
1
1
|
module Mandate
|
2
2
|
module Memoize
|
3
|
+
|
4
|
+
# This method is called on the line before a
|
5
|
+
# define statement. It puts mandate into memoizing mode
|
3
6
|
def memoize
|
4
7
|
@__mandate_memoizing = true
|
5
8
|
end
|
6
9
|
|
10
|
+
# Intercept a method being added.
|
11
|
+
# Create the method as normal, then if we are in
|
12
|
+
# memoize mode, call out to the memozie function and
|
13
|
+
# reset out of memozing mode.
|
7
14
|
def method_added(method_name)
|
8
15
|
super
|
9
|
-
return unless @__mandate_memoizing
|
10
16
|
|
17
|
+
if @__mandate_memoizing
|
18
|
+
__mandate_memoize(method_name)
|
19
|
+
@__mandate_memoizing = false
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Create an anonymous module that defines a method
|
24
|
+
# with the same name as main method being defined.
|
25
|
+
# Add some memoize code to check whether the method
|
26
|
+
# has been previously called or not. If it's not
|
27
|
+
# been then call the underlying method and store the result.
|
28
|
+
#
|
29
|
+
# We then prepend this module so that its method
|
30
|
+
# comes first in the method-lookup chain.
|
31
|
+
def __mandate_memoize(method_name)
|
11
32
|
memoizer = Module.new do
|
12
|
-
p method_name
|
13
33
|
define_method method_name do
|
14
34
|
@__mandate_memoized_results ||= {}
|
15
35
|
|
@@ -20,10 +40,7 @@ module Mandate
|
|
20
40
|
end
|
21
41
|
end
|
22
42
|
end
|
23
|
-
|
24
43
|
prepend memoizer
|
25
|
-
|
26
|
-
@__mandate_memoizing = false
|
27
44
|
end
|
28
45
|
end
|
29
46
|
end
|
data/lib/mandate/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mandate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Walker
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -63,6 +63,7 @@ files:
|
|
63
63
|
- ".gitignore"
|
64
64
|
- ".travis.yml"
|
65
65
|
- Gemfile
|
66
|
+
- LICENCE
|
66
67
|
- README.md
|
67
68
|
- Rakefile
|
68
69
|
- bin/console
|