pay_dirt 1.0.9 → 1.1.0
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 +4 -4
- data/.travis.yml +5 -11
- data/README.md +29 -8
- data/lib/pay_dirt/use_case.rb +3 -0
- data/lib/pay_dirt/version.rb +1 -1
- data/pay_dirt.thor +22 -9
- data/test/test_helper.rb +2 -2
- metadata +9 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ffeeff8d4440f09161c3c3e2a6640f408e94e836
|
4
|
+
data.tar.gz: 2eb8d29fce1ef75e051cabf54f629ccb5dbc911e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5aea0e06d716def907dd6c9e2f0ea1e1d173dcea68daa4675a4aaf8c6422a7ad83f1d40e7d77835f1ac1c190fba834063b4c9ab75099c8b55c5556d0a9db951b
|
7
|
+
data.tar.gz: 97a406eef26f42a45083db37ce6e102f1ca4369953d24b8c7ea3772e34bb21a7950575dc50e42c75a88c1432a7df8493a598a8bed0f9c86698b9830c0bc04643
|
data/.travis.yml
CHANGED
@@ -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.
|
10
|
-
- 2.
|
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
|
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
|
56
|
+
thor pay_dirt:service_object:new FILE
|
57
57
|
|
58
58
|
Options:
|
59
|
-
-d, --dependencies=one two three
|
60
|
-
|
61
|
-
-
|
62
|
-
|
63
|
-
-
|
64
|
-
|
65
|
-
|
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)
|
data/lib/pay_dirt/use_case.rb
CHANGED
@@ -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+)
|
data/lib/pay_dirt/version.rb
CHANGED
data/pay_dirt.thor
CHANGED
@@ -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:
|
8
|
-
aliases:
|
9
|
-
desc:
|
7
|
+
type: :array,
|
8
|
+
aliases: "-d",
|
9
|
+
desc: "specify required dependencies"
|
10
10
|
method_option :test_framework,
|
11
|
-
type:
|
12
|
-
desc:
|
11
|
+
type: :string,
|
12
|
+
desc: "choose a testing framework"
|
13
13
|
method_option :defaults,
|
14
|
-
type:
|
15
|
-
aliases:
|
16
|
-
desc:
|
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)
|
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
|
data/test/test_helper.rb
CHANGED
@@ -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
|
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
|
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:
|
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.
|
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
|