promise.rb 0.6.0 → 0.6.1

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/.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
@@ -1,5 +1,10 @@
1
1
  # promise.rb changelog
2
2
 
3
+ ## 0.6.1 (January 14, 2014)
4
+
5
+ * The rejection reason now defaults to Promise::Error.
6
+ * Promise::Callback got refactored.
7
+
3
8
  ## 0.6.0 (December 21, 2013)
4
9
 
5
10
  * Most of Promise and Callback have been rewritten. Less code.
data/Gemfile CHANGED
@@ -11,7 +11,6 @@ gem 'awesome_print'
11
11
 
12
12
  platform :rbx do
13
13
  gem 'rubysl', '~> 2.0'
14
- gem 'rubysl-json', '~> 2.0'
15
14
  gem 'rubinius', '~> 2.0'
16
15
  end
17
16
 
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.2.0'
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.4'
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.2.0'
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.15.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
@@ -1,3 +1,3 @@
1
1
  ---
2
2
  threshold: 10
3
- total_score: 55
3
+ total_score: 44
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: 3
38
+ max_params: 4
38
39
  LongYieldList:
39
40
  enabled: true
40
41
  exclude: []
data/config/rubocop.yml CHANGED
@@ -11,6 +11,7 @@ AllCops:
11
11
  ParameterLists:
12
12
  Max: 3
13
13
  CountKeywordArgs: true
14
+ Enabled: false
14
15
 
15
16
  # Avoid more than `Max` levels of nesting.
16
17
  BlockNesting:
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 = RuntimeError, backtrace = nil)
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(self) }
78
+ defer { callback.dispatch }
77
79
  end
78
80
 
79
81
  def defer
@@ -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 block_for(promise)
11
- promise.fulfilled? ? @on_fulfill : @on_reject
11
+ def block
12
+ @promise.fulfilled? ? @on_fulfill : @on_reject
12
13
  end
13
14
 
14
- def param_for(promise)
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(promise)
19
- if (block = block_for(promise))
20
- handle_result(promise) { execute(promise, block) }
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(promise, block)
27
- block.call(param_for(promise))
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(promise)
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
 
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  class Promise
4
- VERSION = '0.6.0'
4
+ VERSION = '0.6.1'
5
5
  end
data/spec/promise_spec.rb CHANGED
@@ -380,7 +380,7 @@ describe Promise do
380
380
 
381
381
  it 'does not require a reason' do
382
382
  subject.reject
383
- expect(subject.reason).to be(RuntimeError)
383
+ expect(subject.reason).to be(Promise::Error)
384
384
  end
385
385
 
386
386
  it 'sets the backtrace' do
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.0
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: 2013-12-21 00:00:00.000000000 Z
12
+ date: 2014-01-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec