simple_memoizer 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +4 -0
  3. data/lib/simple_memoizer.rb +31 -0
  4. metadata +63 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5b7c380dc223236e621e2d7b27eb68095025c5fc
4
+ data.tar.gz: b622b2dc81e6804a6b4f271bf57095ae7e82c2ac
5
+ SHA512:
6
+ metadata.gz: 17a9ace0feccb10d1366fd228105d954e13170ba55b2486c9d5a22e96e45619019989f7be60ebf75de841457cf4f51b14ed26b09df93607b4f71dec4a4a36381
7
+ data.tar.gz: 212c2309d4e4e3fb8f029b80acc3bccef1761f0127b96f22e96cf6070ed10de97ed1ceb19b6157f7db310be09976e70a16911e5b98ee74f236f95b5f047a9d03
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ Simple Memoizer
2
+ =====================
3
+
4
+ Allows you to memoize simple methods and works only on ruby 2
@@ -0,0 +1,31 @@
1
+ module SimpleMemoizer
2
+ extend ActiveSupport::Concern
3
+
4
+ module ClassMethods
5
+ def memoize(*method_names)
6
+ method_names.flatten!
7
+ memoized_module = Module.new do
8
+ method_names.each do |name|
9
+ memoized_ivar = SimpleMemoizer.memoized_ivar_for(name)
10
+ module_eval <<-EVAL
11
+ def #{name}
12
+ unless #{memoized_ivar}
13
+ #{memoized_ivar} = [super]
14
+ end
15
+ #{memoized_ivar}[0]
16
+ end
17
+
18
+ def #{name}=(value)
19
+ #{memoized_ivar} = [super(value)]
20
+ end
21
+ EVAL
22
+ end
23
+ end
24
+ prepend memoized_module
25
+ end
26
+ end
27
+
28
+ def self.memoized_ivar_for(symbol)
29
+ "@_memoized_#{symbol.to_s.sub(/\?\Z/, '_query').sub(/!\Z/, '_bang')}".to_sym
30
+ end
31
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_memoizer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Máximo Mussini
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Simple Memoizer is a helper module that encapsulates a modern memoization
28
+ technique.
29
+ email:
30
+ - maximomussini@gmail.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files:
34
+ - README.md
35
+ files:
36
+ - README.md
37
+ - lib/simple_memoizer.rb
38
+ homepage: https://github.com/ElMassimo/simple_memoizer
39
+ licenses:
40
+ - MIT
41
+ metadata: {}
42
+ post_install_message:
43
+ rdoc_options:
44
+ - --charset=UTF-8
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '2.0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubyforge_project:
59
+ rubygems_version: 2.2.2
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: Simple memoization for simple methods
63
+ test_files: []