promise.rb 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +4 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +0 -1
- data/Gemfile.devtools +8 -6
- data/config/flay.yml +1 -1
- data/config/reek.yml +3 -2
- data/config/rubocop.yml +1 -0
- data/lib/promise.rb +6 -4
- data/lib/promise/callback.rb +15 -14
- data/lib/promise/version.rb +1 -1
- data/spec/promise_spec.rb +1 -1
- metadata +2 -2
data/.travis.yml
CHANGED
@@ -2,13 +2,17 @@ language: ruby
|
|
2
2
|
rvm:
|
3
3
|
- 1.9.3
|
4
4
|
- 2.0.0
|
5
|
+
- 2.1.0
|
5
6
|
- jruby
|
6
7
|
- rbx
|
7
8
|
- ruby-head
|
8
9
|
- jruby-head
|
9
10
|
matrix:
|
10
11
|
allow_failures:
|
12
|
+
- rvm: 2.1.0 # https://github.com/dkubb/adamantium/issues/30
|
11
13
|
- rvm: ruby-head
|
12
14
|
- rvm: jruby-head
|
13
15
|
fast_finish: true
|
14
16
|
script: bundle exec rake -t metrics:coverage ci
|
17
|
+
before_install:
|
18
|
+
- gem install bundler -v '= 1.5.1'
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/Gemfile.devtools
CHANGED
@@ -11,17 +11,17 @@ group :development do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
group :yard do
|
14
|
-
gem 'kramdown', '~> 1.
|
14
|
+
gem 'kramdown', '~> 1.3.0'
|
15
15
|
end
|
16
16
|
|
17
17
|
group :guard do
|
18
18
|
gem 'guard', '~> 2.2.4'
|
19
19
|
gem 'guard-bundler', '~> 2.0.0'
|
20
|
-
gem 'guard-rspec', '~> 4.0
|
20
|
+
gem 'guard-rspec', '~> 4.2.0'
|
21
21
|
gem 'guard-rubocop', '~> 1.0.0'
|
22
22
|
|
23
23
|
# file system change event handling
|
24
|
-
gem 'listen', '~> 2.
|
24
|
+
gem 'listen', '~> 2.4.0'
|
25
25
|
gem 'rb-fchange', '~> 0.0.6', require: false
|
26
26
|
gem 'rb-fsevent', '~> 0.9.3', require: false
|
27
27
|
gem 'rb-inotify', '~> 0.9.0', require: false
|
@@ -37,13 +37,15 @@ group :metrics do
|
|
37
37
|
gem 'flay', '~> 2.4.0'
|
38
38
|
gem 'flog', '~> 4.2.0'
|
39
39
|
gem 'reek', '~> 1.3.2'
|
40
|
-
gem 'rubocop', '~> 0.
|
40
|
+
gem 'rubocop', '~> 0.16.0'
|
41
41
|
gem 'simplecov', '~> 0.8.2'
|
42
42
|
gem 'yardstick', '~> 0.9.7', git: 'https://github.com/dkubb/yardstick.git'
|
43
43
|
|
44
|
+
platforms :mri do
|
45
|
+
gem 'mutant', '~> 0.3.4'
|
46
|
+
end
|
47
|
+
|
44
48
|
platforms :ruby_19, :ruby_20 do
|
45
|
-
gem 'mutant', '~> 0.3.0.rc3', git: 'https://github.com/mbj/mutant.git'
|
46
|
-
gem 'unparser', '~> 0.1.5', git: 'https://github.com/mbj/unparser.git'
|
47
49
|
gem 'yard-spellcheck', '~> 0.1.5'
|
48
50
|
end
|
49
51
|
|
data/config/flay.yml
CHANGED
data/config/reek.yml
CHANGED
@@ -10,7 +10,8 @@ ClassVariable:
|
|
10
10
|
exclude: []
|
11
11
|
ControlParameter:
|
12
12
|
enabled: true
|
13
|
-
exclude:
|
13
|
+
exclude:
|
14
|
+
- "Promise#reject"
|
14
15
|
DataClump:
|
15
16
|
enabled: true
|
16
17
|
exclude: []
|
@@ -34,7 +35,7 @@ LongParameterList:
|
|
34
35
|
max_params: 2
|
35
36
|
overrides:
|
36
37
|
initialize:
|
37
|
-
max_params:
|
38
|
+
max_params: 4
|
38
39
|
LongYieldList:
|
39
40
|
enabled: true
|
40
41
|
exclude: []
|
data/config/rubocop.yml
CHANGED
data/lib/promise.rb
CHANGED
@@ -6,6 +6,8 @@ require 'promise/callback'
|
|
6
6
|
require 'promise/progress'
|
7
7
|
|
8
8
|
class Promise
|
9
|
+
Error = Class.new(RuntimeError)
|
10
|
+
|
9
11
|
include Promise::Progress
|
10
12
|
|
11
13
|
attr_reader :state, :value, :reason, :backtrace
|
@@ -31,7 +33,7 @@ class Promise
|
|
31
33
|
on_fulfill ||= block
|
32
34
|
next_promise = Promise.new
|
33
35
|
|
34
|
-
add_callback { Callback.new(on_fulfill, on_reject, next_promise) }
|
36
|
+
add_callback { Callback.new(self, on_fulfill, on_reject, next_promise) }
|
35
37
|
next_promise
|
36
38
|
end
|
37
39
|
|
@@ -56,10 +58,10 @@ class Promise
|
|
56
58
|
end
|
57
59
|
end
|
58
60
|
|
59
|
-
def reject(reason =
|
61
|
+
def reject(reason = nil, backtrace = nil)
|
60
62
|
dispatch(backtrace) do
|
61
63
|
@state = :rejected
|
62
|
-
@reason = reason
|
64
|
+
@reason = reason || Error
|
63
65
|
end
|
64
66
|
end
|
65
67
|
|
@@ -73,7 +75,7 @@ class Promise
|
|
73
75
|
end
|
74
76
|
|
75
77
|
def dispatch!(callback)
|
76
|
-
defer { callback.dispatch
|
78
|
+
defer { callback.dispatch }
|
77
79
|
end
|
78
80
|
|
79
81
|
def defer
|
data/lib/promise/callback.rb
CHANGED
@@ -2,39 +2,40 @@
|
|
2
2
|
|
3
3
|
class Promise
|
4
4
|
class Callback
|
5
|
-
def initialize(on_fulfill, on_reject, next_promise)
|
5
|
+
def initialize(promise, on_fulfill, on_reject, next_promise)
|
6
|
+
@promise = promise
|
6
7
|
@on_fulfill, @on_reject = on_fulfill, on_reject
|
7
8
|
@next_promise = next_promise
|
8
9
|
end
|
9
10
|
|
10
|
-
def
|
11
|
-
promise.fulfilled? ? @on_fulfill : @on_reject
|
11
|
+
def block
|
12
|
+
@promise.fulfilled? ? @on_fulfill : @on_reject
|
12
13
|
end
|
13
14
|
|
14
|
-
def
|
15
|
-
promise.fulfilled? ? promise.value : promise.reason
|
15
|
+
def param
|
16
|
+
@promise.fulfilled? ? @promise.value : @promise.reason
|
16
17
|
end
|
17
18
|
|
18
|
-
def dispatch
|
19
|
-
if
|
20
|
-
handle_result
|
19
|
+
def dispatch
|
20
|
+
if block
|
21
|
+
handle_result { execute }
|
21
22
|
else
|
22
|
-
assume_state(promise, @next_promise)
|
23
|
+
assume_state(@promise, @next_promise)
|
23
24
|
end
|
24
25
|
end
|
25
26
|
|
26
|
-
def execute
|
27
|
-
block.call(
|
27
|
+
def execute
|
28
|
+
block.call(param)
|
28
29
|
rescue => ex
|
29
|
-
@next_promise.reject(ex, promise.backtrace)
|
30
|
+
@next_promise.reject(ex, @promise.backtrace)
|
30
31
|
raise
|
31
32
|
end
|
32
33
|
|
33
|
-
def handle_result
|
34
|
+
def handle_result
|
34
35
|
if Promise === (result = yield)
|
35
36
|
assume_state(result, @next_promise)
|
36
37
|
else
|
37
|
-
@next_promise.fulfill(result, promise.backtrace)
|
38
|
+
@next_promise.fulfill(result, @promise.backtrace)
|
38
39
|
end
|
39
40
|
end
|
40
41
|
|
data/lib/promise/version.rb
CHANGED
data/spec/promise_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: promise.rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.1
|
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:
|
12
|
+
date: 2014-01-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|