pay_dirt 0.0.1 → 0.0.2

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: 225b334258cfa4c5dc7836bcc7bd8b58a19c6119
4
- data.tar.gz: ec7e1f4d3e4aa5e210d33a239eb95279e9fe7f9d
3
+ metadata.gz: f7ff86dfbc9179c07a08070206bc43f1715d0e36
4
+ data.tar.gz: eab83e620f4897c405cf4f3fa5a0cb949978da7e
5
5
  SHA512:
6
- metadata.gz: f78dbd7abbe33e65260f9b823dcb9f0c0cfbacad5ad36517cf30bc9064e2785c7ab99a0f419989390c198fa44c36b6840d2c21d98142aef3f8114c148b46bb7e
7
- data.tar.gz: c5aa125838ca42dda0c14a1857eafba7ed60322c9d8fb10120b0fcb9b2f1e30a8fc675fc0f100afa6604e68660fa6b5eb1111814d88558e2d8be33bbc9b6dddf
6
+ metadata.gz: 75104e49d44c143d955932427e8e89cb6b4b05ba1e7c7840228d32889f500eb7d05c2e51476c00b2b6849d0e11692fef058292d64bcda6c6a1bf2436d5dd5951
7
+ data.tar.gz: 5560575c53412632cc24eedfc015c0d81cb38d67bab4084f9fc7c75c87d105092afed5a91aefddb8c06b25b99e78f0b4004e706ff2cae753c6444eff7480f7b4
data/lib/pay_dirt/base.rb CHANGED
@@ -1,11 +1,10 @@
1
+ require_relative "#{File.dirname(__FILE__)}/use_case.rb"
2
+ require_relative "#{File.dirname(__FILE__)}/base.rb"
3
+
4
+
5
+ # Here's something you can inherit from
1
6
  module PayDirt
2
7
  class Base
3
- def load_option(option, options)
4
- instance_variable_set("@#{option}", options.fetch(option.to_sym) { raise "Missing required option: #{option}" } )
5
- end
6
-
7
- def load_options(*option_names, options)
8
- option_names.each{|o| load_option(o, options) }
9
- end
8
+ include PayDirt::UseCase
10
9
  end
11
10
  end
@@ -1,3 +1,4 @@
1
+ require_relative "#{File.dirname(__FILE__)}/result.rb"
1
2
  module PayDirt
2
3
  class Result
3
4
  # The response from a use case execution
@@ -17,7 +18,7 @@ module PayDirt
17
18
  # @api public
18
19
  def initialize(options)
19
20
  @success = options[:success]
20
- @data = options[:data]
21
+ @data = options[:data]
21
22
  end
22
23
 
23
24
  # @api public
@@ -0,0 +1,16 @@
1
+ require_relative "#{File.dirname(__FILE__)}/use_case.rb"
2
+ module PayDirt
3
+ module UseCase
4
+ def self.included(base)
5
+ def load_option(option, options)
6
+ instance_variable_set("@#{option}", options.fetch(option.to_sym) {
7
+ raise "Missing required option: #{option}"
8
+ })
9
+ end
10
+
11
+ def load_options(*option_names, options)
12
+ option_names.each { |o| load_option(o, options) }
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,3 +1,3 @@
1
1
  module PayDirt
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/pay_dirt.rb CHANGED
@@ -1,3 +0,0 @@
1
- # Load use case files
2
- require "#{File.dirname(__FILE__)}/pay_dirt/base.rb"
3
- Dir["#{File.dirname(__FILE__)}/pay_dirt/**/*.rb"].each { |f| require f }
data/test/test_helper.rb CHANGED
@@ -11,4 +11,3 @@ require "pry"
11
11
  $: << File.dirname(__FILE__) + "/../lib"
12
12
  $: << File.dirname(__FILE__)
13
13
 
14
- require "pay_dirt"
@@ -1,11 +1,16 @@
1
1
  require 'test_helper'
2
+ require_relative "../../../lib/pay_dirt/base"
2
3
 
3
4
  describe PayDirt::Base do
4
5
  before do
5
6
  module UseCase
6
7
  class UltimateQuestion < PayDirt::Base
7
8
  def initialize(options)
8
- load_options(:the_secret_to_life_the_universe_and_everything, options)
9
+ options = {
10
+ the_question: "What is the secret to life, the universe, and everything?"
11
+ }.merge(options)
12
+
13
+ load_options(:the_question, :the_secret_to_life_the_universe_and_everything, options)
9
14
  end
10
15
 
11
16
  def execute!
@@ -22,7 +27,8 @@ describe PayDirt::Base do
22
27
  end
23
28
 
24
29
  it "must inherit from PayDirt::Base" do
25
- assert_operator @use_case, :<, PayDirt::Base
30
+ lineage = UseCase::UltimateQuestion.ancestors.map(&:to_s)
31
+ assert lineage.include?("PayDirt::Base")
26
32
  end
27
33
 
28
34
  it "must error when initialized without required options" do
@@ -33,6 +39,10 @@ describe PayDirt::Base do
33
39
  end
34
40
  end
35
41
 
42
+ it "it won't error if defaults were supplied for an omitted option" do
43
+ @use_case.new(the_secret_to_life_the_universe_and_everything: :not_telling).must_respond_to :execute!
44
+ end
45
+
36
46
  it "can execute successfully" do
37
47
  dependencies = {
38
48
  the_secret_to_life_the_universe_and_everything: 42
@@ -41,9 +51,10 @@ describe PayDirt::Base do
41
51
  result = @use_case.new(dependencies).execute!
42
52
 
43
53
  result.successful?.must_equal true
54
+ result.must_be_kind_of PayDirt::Result
44
55
  end
45
56
 
46
- it "can execute successfully" do
57
+ it "can execute unsuccessfully" do
47
58
  dependencies = {
48
59
  the_secret_to_life_the_universe_and_everything: :i_dunno
49
60
  }
@@ -1,4 +1,5 @@
1
1
  require 'test_helper'
2
+ require_relative "../../../lib/pay_dirt/result"
2
3
 
3
4
  describe PayDirt::Result do
4
5
  it "knows whether it was successful or not" do
@@ -0,0 +1,61 @@
1
+ require 'test_helper'
2
+ require_relative "../../../lib/pay_dirt/use_case"
3
+
4
+ describe PayDirt::UseCase do
5
+ before do
6
+ module UseCase
7
+ class UltimateQuestion
8
+ include PayDirt::UseCase
9
+
10
+ def initialize(options)
11
+ options = {
12
+ the_secret_to_life_the_universe_and_everything: 42
13
+ }.merge(options)
14
+
15
+ load_options(:the_secret_to_life_the_universe_and_everything, options)
16
+ end
17
+
18
+ def execute!
19
+ if @the_secret_to_life_the_universe_and_everything == 42
20
+ return PayDirt::Result.new(data: @the_secret_to_life_the_universe_and_everything, success: true)
21
+ else
22
+ return PayDirt::Result.new(data: @the_secret_to_life_the_universe_and_everything, success: false)
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ @use_case = UseCase::UltimateQuestion
29
+ end
30
+
31
+ it "need not inherit from PayDirt::Base" do
32
+ #lineage = UseCase::UltimateQuestion.ancestors.map(&:to_s)
33
+ #assert !lineage.include?("PayDirt::Base")
34
+
35
+ # NOTE this test only passes when base_test is removed.
36
+ end
37
+
38
+ it "must not error when options with defaults are omitted" do
39
+ @use_case.new({}).must_respond_to :execute!
40
+ end
41
+
42
+ it "can execute successfully" do
43
+ dependencies = {
44
+ }
45
+
46
+ result = @use_case.new(dependencies).execute!
47
+
48
+ result.successful?.must_equal true
49
+ result.must_be_kind_of PayDirt::Result
50
+ end
51
+
52
+ it "can execute unsuccessfully" do
53
+ dependencies = {
54
+ the_secret_to_life_the_universe_and_everything: :i_dunno
55
+ }
56
+
57
+ result = @use_case.new(dependencies).execute!
58
+
59
+ result.successful?.must_equal false
60
+ end
61
+ 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: 0.0.1
4
+ version: 0.0.2
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-04-23 00:00:00.000000000 Z
11
+ date: 2013-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -71,12 +71,14 @@ files:
71
71
  - lib/pay_dirt.rb
72
72
  - lib/pay_dirt/base.rb
73
73
  - lib/pay_dirt/result.rb
74
+ - lib/pay_dirt/use_case.rb
74
75
  - lib/pay_dirt/version.rb
75
76
  - pay_dirt.gemspec
76
77
  - test/test_helper.rb
77
78
  - test/unit/.gitkeep
78
79
  - test/unit/pay_dirt/base_test.rb
79
80
  - test/unit/pay_dirt/result_test.rb
81
+ - test/unit/pay_dirt/use_case_test.rb
80
82
  homepage: http://github.com/rthbound/pay_dirt
81
83
  licenses: []
82
84
  metadata: {}