ripar 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.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.travis.yml +2 -5
- data/README.md +6 -3
- data/lib/ripar/combinder.rb +7 -1
- data/lib/ripar/roller.rb +8 -13
- data/lib/ripar/version.rb +1 -1
- data/spec/combinder_spec.rb +1 -1
- data/spec/roller_spec.rb +21 -10
- metadata +3 -4
- data/.rvmrc +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a368f23a0b937bf21305f5267722f443ede2e71f
|
4
|
+
data.tar.gz: cbc4f90137156069b8c59e3aeaf91f43ff4702ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27d5c711a65ce3f83eb3316e1b9f65675ab76532b6ea0a242419f86939f5703e0f84d501bf86e874e5ac9abd420bcde70ebacbb59885a4af7e1b1ad33f93d327
|
7
|
+
data.tar.gz: 6dcd0917641a94ed792dfd608cdf1106d94543184bfd21be1aec954835c02616f1cb866ebda1cbc57338a63022a0da83906b9bb3d3e62e1573ae77038c3bd970
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
[](http://badge.fury.io/rb/ripar)
|
2
|
-
|
3
|
-
# Ripar
|
1
|
+
# Ripar [](http://badge.fury.io/rb/ripar) [](https://travis-ci.org/djellemah/ripar)
|
4
2
|
|
5
3
|
Think riparian. Think old man river, he jus' keep on rollin'. Think
|
6
4
|
[rive](http://etymonline.com/index.php?search=rive). Also river, reaver,
|
@@ -98,6 +96,11 @@ class << o
|
|
98
96
|
end
|
99
97
|
```
|
100
98
|
|
99
|
+
The mostest lightweightiest
|
100
|
+
``` ruby
|
101
|
+
o = Object.new.extend(Ripar)
|
102
|
+
```
|
103
|
+
|
101
104
|
Monkey-patch
|
102
105
|
``` ruby
|
103
106
|
class Object
|
data/lib/ripar/combinder.rb
CHANGED
@@ -33,7 +33,13 @@ class Ripar::Combinder < BasicObject
|
|
33
33
|
begin
|
34
34
|
return @obj.__ambiguous_method__( @binding.self, meth, *args, &blk )
|
35
35
|
rescue ::NoMethodError => ex
|
36
|
-
::
|
36
|
+
unless ::Object::RUBY_VERSION == '2.0.0'
|
37
|
+
# for some reason, any references to ex.message fail here for 2.0.0
|
38
|
+
# so only for other versions just double-check versions that it was in fact caused by __ambiguous_method__
|
39
|
+
# otherwise just raise whatever was missing.
|
40
|
+
::Kernel.raise unless ex.message =~ /__ambiguous_method__/
|
41
|
+
end
|
42
|
+
::Kernel.raise AmbiguousMethod, "method :#{meth} exists on both #{@binding.self.inspect} (outside) and #{@obj.inspect} (inside)", ex.backtrace[3..-1]
|
37
43
|
end
|
38
44
|
end
|
39
45
|
|
data/lib/ripar/roller.rb
CHANGED
@@ -7,11 +7,13 @@ require 'ripar/combinder.rb'
|
|
7
7
|
class Ripar::Roller < BasicObject
|
8
8
|
def initialize( original, &block )
|
9
9
|
@original = original
|
10
|
-
# clone is for protection
|
10
|
+
# clone is for protection of original - not strictly necessary?
|
11
11
|
@riven = original.clone
|
12
12
|
roll_block( &block ) if block
|
13
13
|
end
|
14
14
|
|
15
|
+
class Undispatchable < ::RuntimeError; end
|
16
|
+
|
15
17
|
# Callback from Combinder.
|
16
18
|
#
|
17
19
|
# This happens when the outside self is_a?(original.class) already,
|
@@ -28,9 +30,8 @@ class Ripar::Roller < BasicObject
|
|
28
30
|
# send it to the roller
|
29
31
|
send meth, *args, &blk
|
30
32
|
else
|
31
|
-
# don't know what to do with it
|
32
|
-
|
33
|
-
raise ::NoMethodError, meth
|
33
|
+
# don't know what to do with it
|
34
|
+
raise Undispatchable, "don't know how to dispatch #{meth}"
|
34
35
|
end
|
35
36
|
end
|
36
37
|
|
@@ -53,20 +54,14 @@ class Ripar::Roller < BasicObject
|
|
53
54
|
new( original, &block ).riven
|
54
55
|
end
|
55
56
|
|
56
|
-
# Forward to riven,
|
57
|
+
# Forward to riven, let it raise a method missing exception if necessary
|
57
58
|
def method_missing(meth, *args, &block)
|
58
|
-
|
59
|
-
interim = @riven.send( meth, *args, &block )
|
60
|
-
# ::Kernel.puts "sending #{meth}(#{args.inspect}) to #{@riven.inspect}: #{interim}"
|
61
|
-
@riven = interim
|
62
|
-
else
|
63
|
-
super
|
64
|
-
end
|
59
|
+
@riven = @riven.send( meth, *args, &block )
|
65
60
|
end
|
66
61
|
|
67
62
|
# used by combinder, so must be defined, otherwise it perturbs method_missing
|
68
63
|
def send( meth, *args, &block )
|
69
|
-
method_missing
|
64
|
+
method_missing meth, *args, &block
|
70
65
|
end
|
71
66
|
|
72
67
|
# used by combinder, so must be defined, otherwise it perturbs method_missing
|
data/lib/ripar/version.rb
CHANGED
data/spec/combinder_spec.rb
CHANGED
@@ -30,7 +30,7 @@ describe Ripar::Combinder do
|
|
30
30
|
|
31
31
|
it 'raise on ambiguous method' do
|
32
32
|
combinder = Ripar::Combinder.new(an_object, binding)
|
33
|
-
->{combinder.instance_eval{ oops }}.should raise_error(Ripar::Combinder::AmbiguousMethod, /exists on both/)
|
33
|
+
->{combinder.instance_eval{ oops }}.should raise_error(Ripar::Combinder::AmbiguousMethod, /oops.*exists on both/)
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'callback on ambiguous method' do
|
data/spec/roller_spec.rb
CHANGED
@@ -121,14 +121,26 @@ describe Ripar::Roller do
|
|
121
121
|
|
122
122
|
it 'syntax error for outside variable and inside method call in-place hash syntax' do
|
123
123
|
multiply = 'go forth and'
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
124
|
+
# This will cause a syntax error because the interpreter
|
125
|
+
# finds the outside variable, and we're trying to call a method.
|
126
|
+
# but only if we're using the in-place hash syntax
|
127
|
+
lambda do
|
128
|
+
eval <<-EOS
|
129
|
+
rlr = collection.roller do
|
130
|
+
multiply factor: 3
|
131
|
+
end
|
132
|
+
EOS
|
133
|
+
end.should raise_error(SyntaxError, /unexpected ':'/)
|
134
|
+
end
|
135
|
+
|
136
|
+
# counter-case for previous example
|
137
|
+
it 'eval outside variable and inside method call in-place hash syntax' do
|
138
|
+
multiply = 'go forth and'
|
139
|
+
begin
|
140
|
+
rlr = collection.roller do
|
141
|
+
eval "multiply factor: 3"
|
142
|
+
end
|
143
|
+
end.riven.should == [3,6,9,12,15,18,21,24]
|
132
144
|
end
|
133
145
|
|
134
146
|
it 'in-place hash syntax with name clash ok with (...)' do
|
@@ -201,12 +213,11 @@ describe Ripar::Roller do
|
|
201
213
|
it 'handles non-nested ambiguity' do
|
202
214
|
class << collection
|
203
215
|
def to_be_duplicated
|
204
|
-
require 'pry'; binding.pry
|
205
216
|
flat_map{|x| [x,x]}
|
206
217
|
end
|
207
218
|
end
|
208
219
|
|
209
|
-
->{collection.roller{ to_be_duplicated }}.should raise_error(Ripar::
|
220
|
+
->{collection.roller{ to_be_duplicated }}.should raise_error(Ripar::Roller::Undispatchable)
|
210
221
|
end
|
211
222
|
|
212
223
|
it 'handles nested rollers' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ripar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Anderson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -117,7 +117,6 @@ extensions: []
|
|
117
117
|
extra_rdoc_files: []
|
118
118
|
files:
|
119
119
|
- ".gitignore"
|
120
|
-
- ".rvmrc"
|
121
120
|
- ".travis.yml"
|
122
121
|
- Gemfile
|
123
122
|
- LICENSE.txt
|
@@ -152,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
152
151
|
version: '0'
|
153
152
|
requirements: []
|
154
153
|
rubyforge_project:
|
155
|
-
rubygems_version: 2.
|
154
|
+
rubygems_version: 2.1.11
|
156
155
|
signing_key:
|
157
156
|
specification_version: 4
|
158
157
|
summary: Chained methods cam be clunky. Use a block instead.
|
data/.rvmrc
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
rvm 2.1.1@ripar --create
|