lazyeval 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -19,3 +19,5 @@ rdoc
19
19
  pkg
20
20
 
21
21
  ## PROJECT::SPECIFIC
22
+ bin
23
+ .bundle
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ * 0.0.4
2
+ - fix a bug when calling with args AND a block
3
+
1
4
  * 0.0.3
2
5
  - ruby 1.9 support
3
6
  - bundler instead of jeweler
@@ -1,21 +1,61 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lazyeval (0.0.3)
4
+ lazyeval (0.0.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- rake (10.0.4)
10
- thoughtbot-shoulda (2.11.1)
11
- yard (0.8.6.1)
9
+ celluloid (0.15.2)
10
+ timers (~> 1.1.0)
11
+ coderay (1.0.9)
12
+ columnize (0.3.6)
13
+ debugger (1.6.1)
14
+ columnize (>= 0.3.1)
15
+ debugger-linecache (~> 1.2.0)
16
+ debugger-ruby_core_source (~> 1.2.3)
17
+ debugger-linecache (1.2.0)
18
+ debugger-ruby_core_source (1.2.3)
19
+ ffi (1.9.0)
20
+ formatador (0.2.4)
21
+ guard (2.0.3)
22
+ formatador (>= 0.2.4)
23
+ listen (~> 2.0)
24
+ lumberjack (~> 1.0)
25
+ pry (>= 0.9.12)
26
+ thor (>= 0.18.1)
27
+ guard-minitest (2.0.0)
28
+ guard (~> 2.0)
29
+ minitest (>= 3.0)
30
+ listen (2.0.0)
31
+ celluloid (>= 0.15.1)
32
+ rb-fsevent (>= 0.9.3)
33
+ rb-inotify (>= 0.9)
34
+ lumberjack (1.0.4)
35
+ method_source (0.8.2)
36
+ minitest (4.7.5)
37
+ pry (0.9.12.2)
38
+ coderay (~> 1.0.5)
39
+ method_source (~> 0.8)
40
+ slop (~> 3.4)
41
+ rake (10.1.0)
42
+ rb-fsevent (0.9.3)
43
+ rb-inotify (0.9.2)
44
+ ffi (>= 0.5.0)
45
+ slop (3.4.6)
46
+ terminal-notifier-guard (1.5.3)
47
+ thor (0.18.1)
48
+ timers (1.1.0)
12
49
 
13
50
  PLATFORMS
14
51
  ruby
15
52
 
16
53
  DEPENDENCIES
17
54
  bundler (~> 1.3)
55
+ debugger
56
+ guard
57
+ guard-minitest
18
58
  lazyeval!
59
+ minitest
19
60
  rake
20
- thoughtbot-shoulda
21
- yard
61
+ terminal-notifier-guard
@@ -0,0 +1,6 @@
1
+ guard :minitest do
2
+ # with Minitest::Spec
3
+ watch(%r{^spec/(.*)_spec\.rb})
4
+ watch(%r{^lib/(.+)\.rb}) { |m| "spec/#{m[1]}_spec.rb" }
5
+ watch(%r{^spec/spec_helper\.rb}) { 'spec' }
6
+ end
@@ -1,5 +1,8 @@
1
1
  # Lazyeval
2
2
 
3
+ [![Build Status](https://travis-ci.org/vitaly/lazyeval.png)](https://travis-ci.org/vitaly/lazyeval)
4
+ [![Code Climate](https://codeclimate.com/github/vitaly/lazyeval.png)](https://codeclimate.com/github/vitaly/lazyeval)
5
+
3
6
  Homepage: [http://github.com/vitaly/lazyeval/](http://github.com/vitaly/lazyeval/)
4
7
 
5
8
  This GEM allows to call methods lazily. The actual work will not be performed
data/Rakefile CHANGED
@@ -1,32 +1,10 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rake/testtask"
2
3
 
3
- require 'rake/testtask'
4
- Rake::TestTask.new(:test) do |test|
5
- test.libs << 'lib' << 'test'
6
- test.pattern = 'test/**/test_*.rb'
7
- test.verbose = true
4
+ Rake::TestTask.new(:spec) do |t|
5
+ t.libs << "spec"
6
+ t.verbose = true
7
+ t.pattern = 'spec/**/*_spec.rb'
8
8
  end
9
9
 
10
- begin
11
- require 'rcov/rcovtask'
12
- Rcov::RcovTask.new do |test|
13
- test.libs << 'test'
14
- test.pattern = 'test/**/test_*.rb'
15
- test.verbose = true
16
- end
17
- rescue LoadError
18
- task :rcov do
19
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
20
- end
21
- end
22
-
23
- task :default => :test
24
-
25
- begin
26
- require 'yard'
27
- YARD::Rake::YardocTask.new
28
- rescue LoadError
29
- task :yardoc do
30
- abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
31
- end
32
- end
10
+ task :default => :spec
@@ -5,7 +5,7 @@ require 'lazyeval/version'
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "lazyeval"
8
- s.version = Lazy::VERSION
8
+ s.version = Lazyeval::VERSION
9
9
  s.authors = ["Vitaly Kushner"]
10
10
  s.email = ["vitaly@astrails.com"]
11
11
  s.description = %q{This GEM allows to call methods lazily. The actual
@@ -23,6 +23,9 @@ Gem::Specification.new do |s|
23
23
 
24
24
  s.add_development_dependency 'bundler', '~> 1.3'
25
25
  s.add_development_dependency 'rake'
26
- s.add_development_dependency 'thoughtbot-shoulda'
27
- s.add_development_dependency 'yard'
26
+ s.add_development_dependency 'minitest'
27
+ s.add_development_dependency 'guard'
28
+ s.add_development_dependency 'guard-minitest'
29
+ s.add_development_dependency 'terminal-notifier-guard'
30
+ s.add_development_dependency 'debugger'
28
31
  end
@@ -1,28 +1,3 @@
1
- class Object
2
- def lazy(&block)
3
- Lazy.new(self, &block)
4
- end
5
- end
6
-
7
- class Lazy < (::RUBY_VERSION < '1.9') ? Object : BasicObject
8
- undef_method(*(instance_methods - %w/__id__ __send__ respond_to? debugger/)) if ::RUBY_VERSION < '1.9'
9
-
10
- def initialize(obj, &block)
11
- @obj, @block = obj, block
12
- @args = @done = nil
13
- end
14
-
15
- def method_missing(*args, &block)
16
- unless @done
17
- if !@args && !@block
18
- @args, @block = args, @block
19
- return self
20
- end
21
-
22
- @res = @args ? @obj.send(*@args, &@block) : @block.call(@obj)
23
- @done = true
24
- end
25
-
26
- @res.send(*args, &block)
27
- end
28
- end
1
+ require 'lazyeval/version'
2
+ require 'lazyeval/lazy'
3
+ require 'lazyeval/object'
@@ -0,0 +1,26 @@
1
+ module Lazyeval
2
+ class Lazy < (::RUBY_VERSION < '1.9') ? Object : BasicObject
3
+ undef_method(*(instance_methods - %w/__id__ __send__ respond_to? debugger/)) if ::RUBY_VERSION < '1.9'
4
+
5
+ def initialize(obj, &block)
6
+ @obj, @block = obj, block
7
+ @args = @done = nil
8
+ end
9
+
10
+ def method_missing(*args, &block)
11
+ unless @done
12
+ if !@args && !@block
13
+ # called 1st time, store the args and the block
14
+ @args, @block = args, block
15
+ return self
16
+ end
17
+
18
+ # called 2nd time, execute the lazy call
19
+ @res = @args ? @obj.send(*@args, &@block) : @block.call(@obj)
20
+ @done = true
21
+ end
22
+
23
+ @res.send(*args, &block)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,5 @@
1
+ class Object
2
+ def lazy(&block)
3
+ Lazyeval::Lazy.new(self, &block)
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
- class Lazy
2
- VERSION = '0.0.3'
1
+ module Lazyeval
2
+ VERSION = '0.0.4'
3
3
  end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe Lazyeval::Lazy do
4
+ it "should call a simple method lazily" do
5
+ src = [:a, :b]
6
+ x = src.lazy.shift
7
+ src.must_equal [:a, :b]
8
+ x.must_equal :a
9
+ src.must_equal [:b]
10
+ end
11
+
12
+ it 'should call method with args and block lazily' do
13
+ i = 0
14
+ sum = [1, 2].lazy.inject(3) do |res, x|
15
+ i += 1
16
+ res + x
17
+ end
18
+ i.must_equal 0
19
+ sum.must_equal 6
20
+ i.must_equal 2
21
+ end
22
+
23
+ it "should call a block lazily" do
24
+ src = [1, 2]
25
+ x = src.lazy { |x| x.shift*3 }
26
+
27
+ src.must_equal [1, 2]
28
+ x.must_equal 3
29
+ src.must_equal [2]
30
+ end
31
+ end
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'lazyeval'
3
+
4
+ require 'minitest/autorun'
metadata CHANGED
@@ -2,78 +2,126 @@
2
2
  name: lazyeval
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.3
5
+ version: 0.0.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Vitaly Kushner
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-05 00:00:00.000000000 Z
12
+ date: 2013-10-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
- version_requirements: !ruby/object:Gem::Requirement
17
- none: false
16
+ type: :development
17
+ requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
21
  version: '1.3'
22
- requirement: !ruby/object:Gem::Requirement
23
22
  none: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ~>
26
26
  - !ruby/object:Gem::Version
27
27
  version: '1.3'
28
- type: :development
28
+ none: false
29
29
  prerelease: false
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: rake
32
- version_requirements: !ruby/object:Gem::Requirement
32
+ type: :development
33
+ requirement: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
33
38
  none: false
39
+ version_requirements: !ruby/object:Gem::Requirement
34
40
  requirements:
35
41
  - - ! '>='
36
42
  - !ruby/object:Gem::Version
37
43
  version: '0'
44
+ none: false
45
+ prerelease: false
46
+ - !ruby/object:Gem::Dependency
47
+ name: minitest
48
+ type: :development
38
49
  requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
39
54
  none: false
55
+ version_requirements: !ruby/object:Gem::Requirement
40
56
  requirements:
41
57
  - - ! '>='
42
58
  - !ruby/object:Gem::Version
43
59
  version: '0'
44
- type: :development
60
+ none: false
45
61
  prerelease: false
46
62
  - !ruby/object:Gem::Dependency
47
- name: thoughtbot-shoulda
48
- version_requirements: !ruby/object:Gem::Requirement
63
+ name: guard
64
+ type: :development
65
+ requirement: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
49
70
  none: false
71
+ version_requirements: !ruby/object:Gem::Requirement
50
72
  requirements:
51
73
  - - ! '>='
52
74
  - !ruby/object:Gem::Version
53
75
  version: '0'
76
+ none: false
77
+ prerelease: false
78
+ - !ruby/object:Gem::Dependency
79
+ name: guard-minitest
80
+ type: :development
54
81
  requirement: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
55
86
  none: false
87
+ version_requirements: !ruby/object:Gem::Requirement
56
88
  requirements:
57
89
  - - ! '>='
58
90
  - !ruby/object:Gem::Version
59
91
  version: '0'
60
- type: :development
92
+ none: false
61
93
  prerelease: false
62
94
  - !ruby/object:Gem::Dependency
63
- name: yard
64
- version_requirements: !ruby/object:Gem::Requirement
95
+ name: terminal-notifier-guard
96
+ type: :development
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
65
102
  none: false
103
+ version_requirements: !ruby/object:Gem::Requirement
66
104
  requirements:
67
105
  - - ! '>='
68
106
  - !ruby/object:Gem::Version
69
107
  version: '0'
108
+ none: false
109
+ prerelease: false
110
+ - !ruby/object:Gem::Dependency
111
+ name: debugger
112
+ type: :development
70
113
  requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
71
118
  none: false
119
+ version_requirements: !ruby/object:Gem::Requirement
72
120
  requirements:
73
121
  - - ! '>='
74
122
  - !ruby/object:Gem::Version
75
123
  version: '0'
76
- type: :development
124
+ none: false
77
125
  prerelease: false
78
126
  description: ! "This GEM allows to call methods lazily. The actual\n work will not
79
127
  be performed until the result is used. There's no\n promise/force semantics, just
@@ -98,6 +146,7 @@ files:
98
146
  - CHANGELOG
99
147
  - Gemfile
100
148
  - Gemfile.lock
149
+ - Guardfile
101
150
  - LICENSE.txt
102
151
  - README.markdown
103
152
  - Rakefile
@@ -119,9 +168,11 @@ files:
119
168
  - doc/top-level-namespace.html
120
169
  - lazyeval.gemspec
121
170
  - lib/lazyeval.rb
171
+ - lib/lazyeval/lazy.rb
172
+ - lib/lazyeval/object.rb
122
173
  - lib/lazyeval/version.rb
123
- - test/helper.rb
124
- - test/test_lazyeval.rb
174
+ - spec/lazyeval/lazy_spec.rb
175
+ - spec/spec_helper.rb
125
176
  homepage: http://github.com/vitaly/lazyeval
126
177
  licenses:
127
178
  - MIT
@@ -130,17 +181,23 @@ rdoc_options: []
130
181
  require_paths:
131
182
  - lib
132
183
  required_ruby_version: !ruby/object:Gem::Requirement
133
- none: false
134
184
  requirements:
135
185
  - - ! '>='
136
186
  - !ruby/object:Gem::Version
187
+ segments:
188
+ - 0
189
+ hash: 2487045023423868154
137
190
  version: '0'
138
- required_rubygems_version: !ruby/object:Gem::Requirement
139
191
  none: false
192
+ required_rubygems_version: !ruby/object:Gem::Requirement
140
193
  requirements:
141
194
  - - ! '>='
142
195
  - !ruby/object:Gem::Version
196
+ segments:
197
+ - 0
198
+ hash: 2487045023423868154
143
199
  version: '0'
200
+ none: false
144
201
  requirements: []
145
202
  rubyforge_project:
146
203
  rubygems_version: 1.8.25
@@ -148,5 +205,5 @@ signing_key:
148
205
  specification_version: 3
149
206
  summary: This gem provides a very simple lazy evaluation for Ruby
150
207
  test_files:
151
- - test/helper.rb
152
- - test/test_lazyeval.rb
208
+ - spec/lazyeval/lazy_spec.rb
209
+ - spec/spec_helper.rb
@@ -1,10 +0,0 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
- require 'shoulda'
4
-
5
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
- $LOAD_PATH.unshift(File.dirname(__FILE__))
7
- require 'lazyeval'
8
-
9
- class Test::Unit::TestCase
10
- end
@@ -1,20 +0,0 @@
1
- require 'helper'
2
-
3
- class TestLazyeval < Test::Unit::TestCase
4
- should "call a simple method lazily" do
5
- src = [:a, :b]
6
- x = src.lazy.shift
7
- assert_equal [:a, :b], src
8
- assert x === :a
9
- assert_equal [:b], src
10
- end
11
-
12
- should "call a block lazily" do
13
- src = [1, 2]
14
- x = src.lazy { |x| x.shift*3 }
15
-
16
- assert_equal [1, 2], src
17
- assert x === 3
18
- assert_equal [2], src
19
- end
20
- end