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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f44f23505f92820e31ac7f4b67ede9e07e209983
4
- data.tar.gz: 6994a3df9208181c7613edeba903268fe1624df3
3
+ metadata.gz: a368f23a0b937bf21305f5267722f443ede2e71f
4
+ data.tar.gz: cbc4f90137156069b8c59e3aeaf91f43ff4702ef
5
5
  SHA512:
6
- metadata.gz: c7387c6606f90ee3ea131064e2b9f0123d76bc7c7e8427a0a26f9d3f5ec7e3aea06ae64262f7adc1796b8615562346ca1e980b60a6dbc3b85e682cc16112546b
7
- data.tar.gz: 24a3048c49f28abaa233ebeb22b3aba41b085f5711f65faf52e42101832da60fe35d545385058b15b3420f11ee5dfae0379a19067edd3e3ab606159ee0455e67
6
+ metadata.gz: 27d5c711a65ce3f83eb3316e1b9f65675ab76532b6ea0a242419f86939f5703e0f84d501bf86e874e5ac9abd420bcde70ebacbb59885a4af7e1b1ad33f93d327
7
+ data.tar.gz: 6dcd0917641a94ed792dfd608cdf1106d94543184bfd21be1aec954835c02616f1cb866ebda1cbc57338a63022a0da83906b9bb3d3e62e1573ae77038c3bd970
data/.gitignore CHANGED
@@ -15,3 +15,5 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .ruby-gemset
19
+ .ruby-version
data/.travis.yml CHANGED
@@ -1,9 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- # needs bundler-1.3.4, and 1.5 is in gemspec
4
- # and the project uses 2.0 features
5
- #- 1.9.3
6
3
  - 2.0.0
7
- # not supported by travis. yet?
8
- #- 2.1.1
4
+ - 2.1.0
5
+ - 2.1.1
9
6
  script: bundle exec rspec spec
data/README.md CHANGED
@@ -1,6 +1,4 @@
1
- [![Gem Version](https://badge.fury.io/rb/ripar.png)](http://badge.fury.io/rb/ripar)
2
-
3
- # Ripar
1
+ # Ripar [![Gem Version](https://badge.fury.io/rb/ripar.png)](http://badge.fury.io/rb/ripar) [![Build Status](https://travis-ci.org/djellemah/ripar.png?branch=master)](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
@@ -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
- ::Kernel.raise AmbiguousMethod, "method :#{meth} exists on both #{@binding.self.inspect} (outside) and #{@obj.inspect} (inside) #{ex.message}"
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 or original - not strictly necessary?
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, so let Combinder raise an AmbiguousMethod
32
- # TODO too much coupling because this class knows about Combinder internals.
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, if the method exists.
57
+ # Forward to riven, let it raise a method missing exception if necessary
57
58
  def method_missing(meth, *args, &block)
58
- if @riven.respond_to? meth
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( meth, *args, &block )
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
@@ -1,3 +1,3 @@
1
1
  module Ripar
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -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
- rlr = collection.roller do
125
- pending "Not possible for in-place hash syntax"
126
- # This will cause a syntax error because the interpreter
127
- # finds the outside variable, and we're trying to call a method.
128
- # but only if we're using the in-place hash syntax
129
- # multiply factor: 3
130
- end
131
- rlr.riven.should == [3,6,9,12,15,18,21,24]
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::Combinder::AmbiguousMethod)
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.1
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-03-10 00:00:00.000000000 Z
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.2.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