porcupine 0.1.0 → 0.2.0

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.
data/Jarfile CHANGED
@@ -1,3 +1,2 @@
1
- jar 'com.netflix.rxjava:rxjava-jruby:0.10.1'
2
- jar 'com.netflix.hystrix:hystrix-core:1.3.2'
1
+ jar 'com.netflix.hystrix:hystrix-core:1.3.5'
3
2
  jar 'org.slf4j:slf4j-simple:1.7.5'
data/Jarfile.lock CHANGED
@@ -5,25 +5,22 @@ groups:
5
5
  dependencies:
6
6
  - com.google.code.findbugs:jsr305:jar:2.0.0
7
7
  - com.netflix.archaius:archaius-core:jar:0.4.1
8
- - com.netflix.hystrix:hystrix-core:jar:1.3.2
9
- - com.netflix.rxjava:rxjava-core:jar:0.10.1
10
- - com.netflix.rxjava:rxjava-jruby:jar:0.10.1
8
+ - com.netflix.hystrix:hystrix-core:jar:1.3.5
9
+ - com.netflix.rxjava:rxjava-core:jar:0.13.4
11
10
  - commons-configuration:commons-configuration:jar:1.8
12
11
  - commons-lang:commons-lang:jar:2.6
13
12
  - commons-logging:commons-logging:jar:1.1.1
14
13
  - org.slf4j:slf4j-api:jar:1.7.5
15
14
  - org.slf4j:slf4j-simple:jar:1.7.5
16
15
  artifacts:
17
- - jar:com.netflix.rxjava:rxjava-jruby:jar:0.10.1:
18
- transitive:
19
- com.netflix.rxjava:rxjava-core:jar:0.10.1: {}
20
- - jar:com.netflix.hystrix:hystrix-core:jar:1.3.2:
16
+ - jar:com.netflix.hystrix:hystrix-core:jar:1.3.5:
21
17
  transitive:
22
18
  com.google.code.findbugs:jsr305:jar:2.0.0: {}
23
19
  com.netflix.archaius:archaius-core:jar:0.4.1:
24
20
  commons-configuration:commons-configuration:jar:1.8:
25
21
  commons-logging:commons-logging:jar:1.1.1: {}
26
22
  commons-lang:commons-lang:jar:2.6: {}
23
+ com.netflix.rxjava:rxjava-core:jar:0.13.4: {}
27
24
  - jar:org.slf4j:slf4j-simple:jar:1.7.5:
28
25
  transitive:
29
26
  org.slf4j:slf4j-api:jar:1.7.5: {}
data/README.md CHANGED
@@ -58,7 +58,9 @@ If you provide an onError function, then the function will receive exceptions ra
58
58
 
59
59
  ```ruby
60
60
  observer = porcupine.observe
61
- observer.subscribe("onNext" => lambda {}, "onError" => lambda {|exception| puts exception}) # Will puts any exception
61
+ on_next = lambda {|val| puts "All good: #{val}"}
62
+ on_error = lambda {|exception| puts "Uh oh: #{exception}"}
63
+ observer.subscribe(on_next, on_error)
62
64
  ```
63
65
 
64
66
  ## Contributing
@@ -3,15 +3,15 @@ require "delegate"
3
3
  class Porcupine
4
4
  class Observable < SimpleDelegator
5
5
  def subscribe(*args, &block)
6
- raise ArgumentError unless block_given? || (args.first && args.first["onNext"])
6
+ raise ArgumentError unless block_given? || args.first
7
7
 
8
8
  on_next = if block_given?
9
9
  block
10
10
  else
11
- args.first["onNext"]
11
+ args.shift
12
12
  end
13
13
 
14
- on_error = args.first && args.first["onError"]
14
+ on_error = !block_given? && args.shift
15
15
 
16
16
  wrapped = lambda do |value_or_exception|
17
17
  if value_or_exception.is_a?(Exception)
@@ -21,7 +21,11 @@ class Porcupine
21
21
  end
22
22
  end
23
23
 
24
- __getobj__.subscribe("onNext" => wrapped, "onError" => on_error)
24
+ if on_error
25
+ __getobj__.subscribe(wrapped, on_error, *args)
26
+ else
27
+ __getobj__.subscribe(wrapped)
28
+ end
25
29
  end
26
30
  end
27
31
  end
data/porcupine.gemspec CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "porcupine"
7
- spec.version = "0.1.0"
7
+ spec.version = "0.2.0"
8
8
  spec.authors = ["Mike Ragalie"]
9
9
  spec.email = ["ragalie@gmail.com"]
10
10
  spec.summary = "JRuby wrapper for Hystrix"
@@ -11,59 +11,65 @@ describe Porcupine::Observable do
11
11
  describe "#subscribe" do
12
12
  let(:on_next) { lambda {|v| "pumpkin" } }
13
13
  let(:on_error) { lambda {|v| "apples" } }
14
- let(:arguments) { observable.subscribe("onNext" => on_next, "onError" => on_error) }
14
+ let(:arguments) { observable.subscribe(on_next, on_error) }
15
15
 
16
16
  describe "arguments" do
17
17
  it "accepts a block" do
18
18
  observable.subscribe {}
19
19
  end
20
20
 
21
- it "accepts an onNext parameter" do
22
- observable.subscribe("onNext" => lambda {})
21
+ it "accepts a parameter" do
22
+ observable.subscribe(lambda {})
23
23
  end
24
24
 
25
25
  it "raises otherwise" do
26
- expect { observable.subscribe("cat!") }.to raise_error(ArgumentError)
26
+ expect { observable.subscribe }.to raise_error(ArgumentError)
27
27
  end
28
28
  end
29
29
 
30
30
  it "calls subscribe with a block" do
31
- object.stub(:subscribe) {|arg| arg}
31
+ object.stub(:subscribe) {|*args| args}
32
32
  observable.subscribe(&on_next)
33
- arguments["onNext"].call(1).should == "pumpkin"
33
+ arguments.first.call(1).should == "pumpkin"
34
34
  end
35
35
 
36
36
  it "calls subscribe with the provided onNext method" do
37
- object.stub(:subscribe) {|arg| arg}
38
- arguments["onNext"].call(1).should == "pumpkin"
37
+ object.stub(:subscribe) {|*args| args}
38
+ arguments.first.call(1).should == "pumpkin"
39
39
  end
40
40
 
41
41
  it "calls subscribe with the provided onError method" do
42
- object.stub(:subscribe) {|arg| arg}
43
- arguments["onError"].should == on_error
42
+ object.stub(:subscribe) {|*args| args}
43
+ arguments[1].should == on_error
44
44
  end
45
45
 
46
46
  describe "onNext method" do
47
- before { object.stub(:subscribe) {|arg| arg} }
47
+ before { object.stub(:subscribe) {|*args| args} }
48
48
 
49
49
  it "calls the success method" do
50
- wrapped = arguments["onNext"]
50
+ wrapped = arguments.first
51
51
 
52
52
  on_next.should_receive(:call).with("pony")
53
53
  wrapped.call("pony")
54
54
  end
55
55
 
56
56
  it "calls the error method if the value is an exception" do
57
- wrapped = arguments["onNext"]
57
+ wrapped = arguments.first
58
58
 
59
59
  exception = RuntimeError.new
60
60
  on_error.should_receive(:call).with(exception)
61
61
  wrapped.call(exception)
62
62
  end
63
63
 
64
+ it "passes in the complete method if provided" do
65
+ on_complete = lambda { "pears" }
66
+ object.should_receive(:subscribe).with(kind_of(Proc), on_error, on_complete)
67
+ observable.subscribe(on_next, on_error, on_complete)
68
+ end
69
+
64
70
  it "does nothing if there's no on_error" do
65
71
  arguments = observable.subscribe(&on_next)
66
- wrapped = arguments["onNext"]
72
+ wrapped = arguments.first
67
73
 
68
74
  exception = RuntimeError.new
69
75
  on_error.should_not_receive(:call)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: porcupine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-22 00:00:00.000000000 Z
12
+ date: 2013-09-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: lock_jar