memor 0.0.1 → 0.0.2

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.
@@ -0,0 +1,33 @@
1
+ # Memor
2
+
3
+ ## USAGE
4
+ This lib has one utility method called **memor** which takes *__callee__* as
5
+ first argument and all the host methods other arguments, see the following example:
6
+
7
+ ``` ruby
8
+ require 'memor'
9
+
10
+ class Foo
11
+ include Memor
12
+
13
+ def slow_method1
14
+ memor(__callee__) do
15
+ # slow stuff
16
+ end
17
+ end
18
+
19
+ def slow_method2(a, b)
20
+ memor(__callee__, a, b) do
21
+ # slow stuff
22
+ end
23
+ end
24
+
25
+ def slow_method3(a, *args)
26
+ memor(__callee__, a, args) do
27
+ # slow stuff
28
+ end
29
+ end
30
+ end
31
+ ```
32
+
33
+ Tested in ruby 1.9.2
@@ -1,3 +1,3 @@
1
1
  module Memor
2
- VERSION = "0.0.1"
2
+ VERSION = '0.0.2'
3
3
  end
@@ -1,25 +1,25 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
2
+ $:.push File.expand_path('../lib', __FILE__)
3
3
 
4
- require "memor/version"
4
+ require 'memor/version'
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = "memor"
7
+ s.name = 'memor'
8
8
  s.version = Memor::VERSION
9
- s.authors = ["Aaron Tian"]
10
- s.email = ["Aaron2Ti@gmail.com"]
11
- s.homepage = ""
12
- s.summary = %q{memoize function without alias method chain}
9
+ s.authors = ['Aaron Tian']
10
+ s.email = ['Aaron2Ti@gmail.com']
11
+ s.homepage = 'https://rubygems.org/gems/memor'
12
+ s.summary = %q{simple memoize function without alias method chain}
13
13
  s.description = %q{memoize function without alias method chain}
14
14
 
15
- s.rubyforge_project = "memor"
15
+ s.rubyforge_project = 'memor'
16
16
 
17
17
  s.files = `git ls-files`.split("\n")
18
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
- s.require_paths = ["lib"]
20
+ s.require_paths = ['lib']
21
21
 
22
22
  # specify any dependencies here; for example:
23
- # s.add_development_dependency "rspec"
24
- # s.add_runtime_dependency "rest-client"
23
+ # s.add_runtime_dependency 'rest-client'
24
+ s.add_development_dependency 'rspec'
25
25
  end
@@ -0,0 +1,86 @@
1
+ require 'memor'
2
+
3
+ describe Memor do
4
+ class Foo
5
+ include Memor
6
+
7
+ attr_reader :slows
8
+
9
+ def initialize
10
+ @slows = 0
11
+ end
12
+
13
+ def no_arg
14
+ memor __callee__ do
15
+ slow_method
16
+ end
17
+ end
18
+
19
+ def with_args1(a, b)
20
+ memor __callee__, a, b do
21
+ slow_method
22
+ end
23
+ end
24
+
25
+ def with_args2(*args)
26
+ memor __callee__, args do
27
+ slow_method
28
+ end
29
+ end
30
+
31
+ def query?
32
+ memor __callee__ do
33
+ slow_method
34
+ end
35
+ end
36
+
37
+ def bang!
38
+ memor __callee__ do
39
+ slow_method
40
+ end
41
+ end
42
+
43
+ def slow_method
44
+ @slows += 1
45
+
46
+ 'slow'
47
+ end
48
+ end
49
+
50
+ let(:foo) { Foo.new }
51
+
52
+ it 'no argument' do
53
+ foo.no_arg.should == 'slow'
54
+ foo.no_arg.should == 'slow'
55
+
56
+ foo.slows.should == 1
57
+ end
58
+
59
+ it 'fix arguments' do
60
+ foo.with_args1(1, 2).should == 'slow'
61
+ foo.with_args1(1, 2).should == 'slow'
62
+
63
+ foo.slows.should == 1
64
+ end
65
+
66
+ it 'splat arguments' do
67
+ foo.with_args2('bar').should == 'slow'
68
+ foo.with_args2('bar').should == 'slow'
69
+
70
+ foo.slows.should == 1
71
+ end
72
+
73
+ it '! in method name' do
74
+ foo.bang!.should == 'slow'
75
+ foo.bang!.should == 'slow'
76
+
77
+ foo.slows.should == 1
78
+ end
79
+
80
+ it '? in method name' do
81
+ foo.query?.should == 'slow'
82
+ foo.query?.should == 'slow'
83
+
84
+ foo.slows.should == 1
85
+ end
86
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: memor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,18 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
  date: 2012-02-18 00:00:00.000000000Z
13
- dependencies: []
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &10128280 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *10128280
14
25
  description: memoize function without alias method chain
15
26
  email:
16
27
  - Aaron2Ti@gmail.com
@@ -20,11 +31,13 @@ extra_rdoc_files: []
20
31
  files:
21
32
  - .gitignore
22
33
  - Gemfile
34
+ - README.md
23
35
  - Rakefile
24
36
  - lib/memor.rb
25
37
  - lib/memor/version.rb
26
38
  - memor.gemspec
27
- homepage: ''
39
+ - spec/memor_spec.rb
40
+ homepage: https://rubygems.org/gems/memor
28
41
  licenses: []
29
42
  post_install_message:
30
43
  rdoc_options: []
@@ -47,6 +60,7 @@ rubyforge_project: memor
47
60
  rubygems_version: 1.8.15
48
61
  signing_key:
49
62
  specification_version: 3
50
- summary: memoize function without alias method chain
51
- test_files: []
63
+ summary: simple memoize function without alias method chain
64
+ test_files:
65
+ - spec/memor_spec.rb
52
66
  has_rdoc: