pay_dirt 1.0.6 → 1.0.7

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: 497b43e39556e1bd2161989fc36d09fd5bf90198
4
- data.tar.gz: a32175d9aca9538979e4136b5284cf8cb7e1d45f
3
+ metadata.gz: 80daedc2e23621dd1692c5092c9cce375baf07a3
4
+ data.tar.gz: 6db425bb6a5785adb71396cfa42ef26fdc29ecf0
5
5
  SHA512:
6
- metadata.gz: 833a274e4dd2970dc8c2c658f79c9e68750d3209d6b9d2ffb7ce269afdd6e48e8463be589a91e799236904edaadc7bab0ad2fab10412922d6cb78376403fa3ba
7
- data.tar.gz: b9057b19d1f34058b458b6c8f82b634cb676f003a8ccf65f55d5a3dff5d4593aa44b7d8de62bcb6294a24f0f74403da1bedc519eb5c8c40bffcaafd7554e8790
6
+ metadata.gz: 6d5956acf790c96f0086e66b0312cbfe4037e421ff3f902a23386f937fe265f458738c299c8d0fd183efd942e860a2cc305cbf25bbf0f8d749806f95c05b6277
7
+ data.tar.gz: 6cb08a75659b00259a7b273d6c0107c9f30a669817710fb97c2814984788cacb9065e4c4b000fa70622039eea600d7d6aaf20334197254123b687d7e8bda1183
data/README.md CHANGED
@@ -65,7 +65,7 @@ module ServiceObjects
65
65
  end
66
66
 
67
67
  def execute!
68
- return PayDirt::Result.new(success: true, data: nil)
68
+ result(true)
69
69
  end
70
70
  end
71
71
  end
@@ -20,6 +20,19 @@ module PayDirt
20
20
  options.each_key { |o| options = load_option(o, options) }
21
21
  end
22
22
 
23
+ # Returns a result object representing success.
24
+ #
25
+ # @param [List<String,Symbol>]
26
+ # success should the result be +#successful?+
27
+ #
28
+ # @param [Object]
29
+ # data (nil) optional, an object containing information
30
+ #
31
+ # @public
32
+ def result(success, data = nil)
33
+ PayDirt::Result.new(success: success, data: data)
34
+ end
35
+
23
36
  private
24
37
  # @private
25
38
  def load_option(option, options)
@@ -1,3 +1,3 @@
1
1
  module PayDirt
2
- VERSION = "1.0.6"
2
+ VERSION = "1.0.7"
3
3
  end
@@ -68,7 +68,7 @@ module PayDirt
68
68
  def write_execute_method
69
69
  # The execute! method
70
70
  @append.call(@inner_depth, "def execute!\n")
71
- @append.call(@inner_depth.next, "return PayDirt::Result.new(success: true, data: nil)\n")
71
+ @append.call(@inner_depth.next, "return result(true)\n")
72
72
  @append.call(@inner_depth, "end\n")
73
73
  end
74
74
 
@@ -10,15 +10,12 @@ describe PayDirt::Base do
10
10
  the_question: "What is the secret to life, the universe, and everything?"
11
11
  }.merge(options)
12
12
 
13
- load_options(:the_question, :the_secret_to_life_the_universe_and_everything, options)
13
+ load_options(:the_question, :the_secret, options)
14
14
  end
15
15
 
16
16
  def execute!
17
- if @the_secret_to_life_the_universe_and_everything == 42
18
- return PayDirt::Result.new(data: @the_secret_to_life_the_universe_and_everything, success: true)
19
- else
20
- return PayDirt::Result.new(data: @the_secret_to_life_the_universe_and_everything, success: false)
21
- end
17
+ @the_secret == 42 and return result(true, @the_secret )
18
+ return result(false)
22
19
  end
23
20
  end
24
21
  end
@@ -31,17 +28,17 @@ describe PayDirt::Base do
31
28
  assert lineage.include?("PayDirt::Base")
32
29
  end
33
30
 
34
- it "must error when initialized without required options" do
31
+ it "will error when initialized without required options" do
35
32
  proc { @use_case.new }.must_raise ArgumentError
36
33
  end
37
34
 
38
- it "it won't error if defaults were supplied for an omitted option" do
39
- @use_case.new(the_secret_to_life_the_universe_and_everything: :not_telling).must_respond_to :execute!
35
+ it "won't error if defaults were supplied for an omitted option" do
36
+ @use_case.new(the_secret: :not_telling).must_respond_to :execute!
40
37
  end
41
38
 
42
39
  it "can execute successfully" do
43
40
  dependencies = {
44
- the_secret_to_life_the_universe_and_everything: 42
41
+ the_secret: 42
45
42
  }
46
43
 
47
44
  result = @use_case.new(dependencies).execute!
@@ -52,7 +49,7 @@ describe PayDirt::Base do
52
49
 
53
50
  it "can execute unsuccessfully" do
54
51
  dependencies = {
55
- the_secret_to_life_the_universe_and_everything: :i_dunno
52
+ the_secret: :i_dunno
56
53
  }
57
54
 
58
55
  result = @use_case.new(dependencies).execute!
@@ -11,4 +11,32 @@ describe PayDirt::Result do
11
11
  pay_dirt = PayDirt::Result.new(data: 'foo')
12
12
  pay_dirt.data.must_equal 'foo'
13
13
  end
14
+
15
+ describe "has a little helper method" do
16
+ before do
17
+ class Subject < PayDirt::Base
18
+ def initialize(options)
19
+ load_options(:success, :data, options)
20
+ end
21
+
22
+ def execute!
23
+ result(@success, @data)
24
+ end
25
+ end
26
+
27
+ @pay_dirt = Subject
28
+ end
29
+
30
+ it "can succeed" do
31
+ @pay_dirt.new(success: true, data: "yum").execute!.successful?.must_equal true
32
+ end
33
+
34
+ it "can be unsuccessful" do
35
+ @pay_dirt.new(success: false, data: "gross").execute!.successful?.must_equal false
36
+ end
37
+
38
+ it "provides access to data" do
39
+ @pay_dirt.new(success: true, data: "yum").execute!.data.must_equal "yum"
40
+ end
41
+ end
14
42
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pay_dirt
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tad Hosford
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-25 00:00:00.000000000 Z
11
+ date: 2013-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest