orc 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5ae6474446adf8b9202cda734de4082253a86b10
4
- data.tar.gz: 0bf59dd848ed82e0c162911b320cc78b6dbfd1f5
3
+ metadata.gz: 130f07b4b6a1684b92f3e5ec8e699e77a852e339
4
+ data.tar.gz: 32ec85549a38e20d8636e4822bfc1354da881ee5
5
5
  SHA512:
6
- metadata.gz: 78a3c8c3e9eb39cfd2576be8c7abe5bb5ba82b76a123cb227af6edeaf7c5d7300584ed3972184056308862e0ed0421961ab478ffa300bae04ee45d15a85d39b0
7
- data.tar.gz: 311fe4fc30114d43a804d9241351981a4ff8eb3d98ed5d3586fceccfa081843dfa8c315cb6d1259bd71382de6b634bdf35651d44d87676baae906e5dfb9137a1
6
+ metadata.gz: eaf9060d1c4e79d2db2392cafe0812d3e8f5a44469652f78b5f98d0dc6b22ac7d60c0f6395d3f78d37549e4f65a115b37debbaf11711672b6f23b53aa948fa3e
7
+ data.tar.gz: 73c50733010f8e60939e8fa69acdc38ee20f194a879f80c30c5f527d3b423488d290128283232c86d1cd9cc1c6d7e5c910d53388276ad8b752eea41e4879b9b9
@@ -1,3 +1,3 @@
1
1
  ---
2
- threshold: 4
3
- total_score: 11
2
+ threshold: 9
3
+ total_score: 14
@@ -1,2 +1,2 @@
1
1
  ---
2
- threshold: 1.6
2
+ threshold: 6.3
data/lib/orc.rb CHANGED
@@ -15,8 +15,8 @@ module Orc
15
15
  # arbitrary data associated with the result
16
16
  #
17
17
  # @return [Success]
18
- def self.success(object)
19
- Success.new(object)
18
+ def self.success(object, status = :success)
19
+ Success.new(object, status)
20
20
  end
21
21
 
22
22
  # Create a result indicating failure
@@ -32,19 +32,24 @@ module Orc
32
32
  Failure.new(object, status)
33
33
  end
34
34
 
35
+ include Concord::Public.new(:object, :status)
35
36
  include AbstractType
36
37
 
37
38
  abstract_method :success?
38
- abstract_method :status
39
-
40
- attr_reader :object
41
39
 
42
40
  alias_method :output, :object
43
41
  alias_method :data, :object
44
42
 
43
+ def failure?
44
+ !success?
45
+ end
46
+
47
+ def update
48
+ self.class.new(yield(object), status)
49
+ end
50
+
45
51
  # Result object indicating success along with associated data
46
52
  class Success < self
47
- include Concord::Public.new(:object)
48
53
 
49
54
  # Indicate success
50
55
  #
@@ -52,18 +57,10 @@ module Orc
52
57
  def success?
53
58
  true
54
59
  end
55
-
56
- # Status description
57
- #
58
- # @return [:success]
59
- def status
60
- :success
61
- end
62
60
  end # Success
63
61
 
64
62
  # Result object indicating failure along with status and context
65
63
  class Failure < self
66
- include Concord::Public.new(:object, :status)
67
64
 
68
65
  # Indicate success
69
66
  #
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Orc
4
- VERSION = '0.0.3'.freeze
4
+ VERSION = '0.0.4'.freeze
5
5
  end # Orc
@@ -4,20 +4,38 @@ require 'spec_helper'
4
4
 
5
5
  describe Orc::Result do
6
6
  describe '.success' do
7
- subject { Orc::Result.success(object) }
7
+ shared_context 'a success result' do
8
+ let(:status) { :alright }
9
+ let(:object) { :context }
8
10
 
9
- let(:object) { :object }
11
+ it 'signals success' do
12
+ expect(subject.success?).to be(true)
13
+ expect(subject.failure?).to be(false)
14
+ end
10
15
 
11
- it 'signals success' do
12
- expect(subject.success?).to be(true)
16
+ it 'exposes the associated #object' do
17
+ expect(subject.object).to be(object)
18
+ end
13
19
  end
14
20
 
15
- it 'returns :success status' do
16
- expect(subject.status).to be(:success)
21
+ context 'when no status is given' do
22
+ subject { Orc::Result.success(object) }
23
+
24
+ include_context 'a success result'
25
+
26
+ it 'exposes a :success status' do
27
+ expect(subject.status).to be(:success)
28
+ end
17
29
  end
18
30
 
19
- it 'exposes the associated object' do
20
- expect(subject.object).to be(object)
31
+ context 'when status is given' do
32
+ subject { Orc::Result.success(object, status) }
33
+
34
+ include_context 'a success result'
35
+
36
+ it 'exposes the given #status' do
37
+ expect(subject.status).to be(status)
38
+ end
21
39
  end
22
40
  end
23
41
 
@@ -28,6 +46,7 @@ describe Orc::Result do
28
46
 
29
47
  it 'signals failure' do
30
48
  expect(subject.success?).to be(false)
49
+ expect(subject.failure?).to be(true)
31
50
  end
32
51
 
33
52
  it 'exposes the associated #object' do
@@ -55,4 +74,24 @@ describe Orc::Result do
55
74
  end
56
75
  end
57
76
  end
77
+
78
+ describe '#update' do
79
+ subject { result.update { |o| o + 1 } }
80
+
81
+ let(:result) { Orc::Result.success(object, status) }
82
+ let(:status) { :alright }
83
+ let(:object) { 1 }
84
+
85
+ it 'updates #object' do
86
+ expect(subject.object).to be(2)
87
+ end
88
+
89
+ it 'does not change #status' do
90
+ expect(subject.status).to be(status)
91
+ end
92
+
93
+ it 'does not change #class' do
94
+ expect(subject.class).to equal(result.class)
95
+ end
96
+ end
58
97
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: orc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Gamsjaeger (snusnu)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-26 00:00:00.000000000 Z
11
+ date: 2014-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concord