pay_dirt 1.0.9 → 1.1.0

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: b57e758bcc9b93c274185526b7aab9e36088447d
4
- data.tar.gz: 06b703b2c97f3d2d9073e2b72a15e1b5f3400b74
3
+ metadata.gz: ffeeff8d4440f09161c3c3e2a6640f408e94e836
4
+ data.tar.gz: 2eb8d29fce1ef75e051cabf54f629ccb5dbc911e
5
5
  SHA512:
6
- metadata.gz: d4fc4a28cd10416757ef6a6eae0da1c47c655493f445ef1f51146f080fee3ae331d8f18bef6d8fafe5f2960cbc1b515aa78289c9c4c54d2720ac0745d0b28be2
7
- data.tar.gz: bb56fe12bc73ea1cbdb5bf18cc25343d00bcd6acdd7630e75d666e45ddf3fee3fd2eebef71c0909eb85e60f0d468693f2d743c2f30afa7708ffa01d0c899b8b1
6
+ metadata.gz: 5aea0e06d716def907dd6c9e2f0ea1e1d173dcea68daa4675a4aaf8c6422a7ad83f1d40e7d77835f1ac1c190fba834063b4c9ab75099c8b55c5556d0a9db951b
7
+ data.tar.gz: 97a406eef26f42a45083db37ce6e102f1ca4369953d24b8c7ea3772e34bb21a7950575dc50e42c75a88c1432a7df8493a598a8bed0f9c86698b9830c0bc04643
@@ -1,18 +1,12 @@
1
1
  language: ruby
2
2
 
3
- matrix:
4
- allow_failures:
5
- - rvm: ree
6
-
7
-
8
3
  rvm:
9
- - 2.2.1
10
- - 2.1.4
4
+ - 2.4.0
5
+ - 2.3.3
6
+ - 2.2.6
7
+ - 2.1.10
11
8
  - 2.0.0
12
- - 1.9.3
13
- - 1.9.2
14
9
  - jruby
15
10
  - ruby-head
16
- - rbx
17
11
 
18
- script: bundle exec rake test; bundle exec rake test # run twice to test generated classest & tests
12
+ script: bundle exec rake test; bundle exec rake test # run twice to test the generator (thor scripts) via generated classes & tests
data/README.md CHANGED
@@ -53,16 +53,18 @@ After installing, you can use your new generator *anywhere* you can use thor. It
53
53
  ```
54
54
  $ thor help pay_dirt:service_object:new
55
55
  Usage:
56
- thor pay_dirt:service_object:new FILE -d, --dependencies=one two three
56
+ thor pay_dirt:service_object:new FILE
57
57
 
58
58
  Options:
59
- -d, --dependencies=one two three # specify required dependencies
60
- -D, [--defaults=key:value] # specify default dependencies
61
- -i, [--inherit] # inherit from PayDirt::Base class
62
- # Default: true
63
- -m, [--include] # include the PayDirt::UseCase module (overrides --inherit)
64
-
65
- create a service object
59
+ -d, [--dependencies=one two three] # specify required dependencies
60
+ [--test-framework=TEST_FRAMEWORK] # choose a testing framework
61
+ -D, [--defaults=key:value] # Specify default dependencies
62
+ -V, [--validations=VALIDATIONS] # Add validations
63
+ -i, [--inherit], [--no-inherit] # inherit from PayDirt::Base class
64
+ # Default: true
65
+ -m, [--include], [--no-include] # include the PayDirt::UseCase module (overrides --inherit)
66
+
67
+ create a fully tested object (optionally, requires dependencies)
66
68
  ```
67
69
 
68
70
  example
@@ -141,6 +143,25 @@ Quick::DigitCheck.new(nose: true).call
141
143
  As you can see, we can now call `Quick::DigitCheck.new(nose: true).call`
142
144
  and expect a successful return object. Where you take it from there is up to you.
143
145
 
146
+ ### Validations
147
+
148
+ Version 1.1.0 adds validations, and does so in a backward compatible way. This was accomplished by
149
+ modifying the `#load_options` to yield a block if given, otherwise it will return the options hash
150
+ as normal. The following shows how to validate service objects using the example from class earlier
151
+ in this README.
152
+
153
+ def initialize(options = {})
154
+ options = {
155
+ fingers: 10,
156
+ toes: 10,
157
+ }.merge(options)
158
+
159
+ load_options(:fingers, :toes, :nose, options) do
160
+ raise "Oh noes!" unless @fingers == @toes
161
+ raise "No nose?" if !!@nose
162
+ end
163
+ end
164
+
144
165
  more examples
145
166
  -------------
146
167
  1. [rubeuler](https://github.com/rthbound/rubeuler)
@@ -5,6 +5,7 @@ module PayDirt
5
5
  # Load instance variables from the provided hash of dependencies.
6
6
  #
7
7
  # Raises if any required dependencies (+required_options+) are missing from +options+ hash.
8
+ # Optionally, takes and yields a block after loading options. Use this to validate dependencies.
8
9
  #
9
10
  # @param [List<String,Symbol>]
10
11
  # option_names list of keys representing required dependencies
@@ -19,6 +20,8 @@ module PayDirt
19
20
 
20
21
  # Load remaining options
21
22
  options.each_key { |k| options = load_option(k, options) }
23
+
24
+ block_given? ? yield : options
22
25
  end
23
26
 
24
27
  # Returns a result object conveying success or failure (+success+)
@@ -1,3 +1,3 @@
1
1
  module PayDirt
2
- VERSION = "1.0.9"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -4,16 +4,21 @@ module PayDirt
4
4
 
5
5
  desc "new FILE", "create a fully tested object (optionally, requires dependencies)"
6
6
  method_option :dependencies,
7
- type: :array,
8
- aliases: "-d",
9
- desc: "specify required dependencies"
7
+ type: :array,
8
+ aliases: "-d",
9
+ desc: "specify required dependencies"
10
10
  method_option :test_framework,
11
- type: :string,
12
- desc: "choose a testing framework"
11
+ type: :string,
12
+ desc: "choose a testing framework"
13
13
  method_option :defaults,
14
- type: :hash,
15
- aliases: "-D",
16
- desc: "Specify default dependencies"
14
+ type: :hash,
15
+ aliases: "-D",
16
+ desc: "Specify default dependencies"
17
+ method_option :validations,
18
+ type: :boolean,
19
+ aliases: "-V",
20
+ lazy_default: true,
21
+ desc: "Add validations"
17
22
  method_option :inherit,
18
23
  type: :boolean,
19
24
  desc: "inherit from PayDirt::Base class",
@@ -77,7 +82,15 @@ module PayDirt
77
82
  append(@inner_depth.next, "# will fail if any keys given before options aren't in options\n")
78
83
  append(@inner_depth.next, "load_options(")
79
84
  @dependencies.each { |dep| append(0, ":#{dep}, ") }
80
- append(0, "options)\n")
85
+ append(0, "options)")
86
+
87
+ if options[:validations]
88
+ append(0, " do\n")
89
+ append(@inner_depth.next, "end\n")
90
+ else
91
+ append(0,"\n")
92
+ end
93
+
81
94
  end
82
95
 
83
96
  def set_defaults
@@ -7,5 +7,5 @@ require "minitest/autorun"
7
7
  $: << File.dirname(__FILE__) + "/../lib"
8
8
  $: << File.dirname(__FILE__)
9
9
 
10
- `thor pay_dirt:service_object:new quick/digit_check -d fingers toes nose -D fingers:10 toes:10`
11
-
10
+ `thor pay_dirt:service_object:new quick/digit_check -d fingers toes nose -D fingers:10 toes:10`
11
+ `thor pay_dirt:service_object:new quick/digit_guarantee -d fingers toes nose -D fingers:10 toes:10 -V`
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.9
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tad Hosford
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-04 00:00:00.000000000 Z
11
+ date: 2017-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -114,8 +114,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
114
  version: '0'
115
115
  requirements: []
116
116
  rubyforge_project:
117
- rubygems_version: 2.4.5
117
+ rubygems_version: 2.6.8
118
118
  signing_key:
119
119
  specification_version: 4
120
120
  summary: Reduce a towering codebase to modular rubble (or more rubygems) with pay_dirt
121
- test_files: []
121
+ test_files:
122
+ - test/test_helper.rb
123
+ - test/unit/.gitkeep
124
+ - test/unit/pay_dirt/base_test.rb
125
+ - test/unit/pay_dirt/result_test.rb
126
+ - test/unit/pay_dirt/use_case_test.rb