pay_dirt 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +6 -0
- data/README.md +33 -17
- data/lib/pay_dirt/version.rb +1 -1
- data/pay_dirt.thor +28 -30
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf8344185d4a1298169b244cf23f489243eace6b
|
4
|
+
data.tar.gz: 32a3740b097d5e552821911207567a0a2bfa91c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc804ad76e3d60ad5afb2426a19f6880cec4768261e4406859ee8227ff8ff2da891502dba57765177570889490e7726ced468ab7d7dedddb6a97d6d53c05d04d
|
7
|
+
data.tar.gz: dd906232ef74d54c6248d2fbfe844929822b4c08fd65b110b16ed1e290b7f64ce6520111a5205e7dec6574730defd2dc0dd99ed63f491b55c2e951c397c1de60
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -2,27 +2,35 @@
|
|
2
2
|
|
3
3
|
#### A Ruby gem based on the "use case" pattern set forth in [opencurriculum-flashcards](https://github.com/isotope11/opencurriculum-flashcards)
|
4
4
|
|
5
|
-
|
5
|
+
Reduce a towering codebase to modular rubble (or more Ruby gems) with **PayDirt**
|
6
6
|
|
7
7
|
There are two ways to employ the pattern:
|
8
8
|
|
9
9
|
1. use a class that inherits from [PayDirt::Base](https://github.com/rthbound/pay_dirt/blob/master/test/unit/pay_dirt/base_test.rb#L6-L24)
|
10
10
|
2. use a class or module that includes [PayDirt::UseCase](https://github.com/rthbound/pay_dirt/blob/master/test/unit/pay_dirt/use_case_test.rb#L6-L26)
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
12
|
+
service object generator
|
13
|
+
------------------------
|
14
|
+
pay_dirt now provides a service object generator,
|
15
|
+
powered by [thor](https://github.com/erikhuda/thor).
|
16
|
+
It'll tell you **how it's used**:
|
17
|
+
```
|
18
|
+
$ thor help pay_dirt:service_object:new
|
19
|
+
Usage:
|
20
|
+
thor pay_dirt:service_object:new FILE -d, --dependencies=one two three
|
21
|
+
|
22
|
+
Options:
|
23
|
+
-d, --dependencies=one two three # specify required dependencies
|
24
|
+
-D, [--defaults=key:value] # Specify default dependencies
|
25
|
+
-i, [--inherit] # inherit from PayDirt::Base class
|
26
|
+
# Default: true
|
27
|
+
-m, [--include] # include the PayDirt::UseCase module (overrides --inherit)
|
28
|
+
|
29
|
+
create a service object
|
30
|
+
```
|
25
31
|
|
32
|
+
example
|
33
|
+
-------
|
26
34
|
```
|
27
35
|
$ thor pay_dirt:service_object:new digit_check -d fingers toes -D fingers:10 toes:10
|
28
36
|
create lib/service_objects/digit_check.rb
|
@@ -49,10 +57,18 @@ module ServiceObjects
|
|
49
57
|
end
|
50
58
|
end
|
51
59
|
```
|
52
|
-
We can now call `ServiceObjects::DigitCheck.new(fingers: 10, toes: 10).execute!`
|
53
|
-
and see a successful return object. Where you take it from there is up to you.
|
54
60
|
|
55
|
-
###
|
61
|
+
### Usage:
|
62
|
+
```ruby
|
63
|
+
require "service_objects/digit_check" #=> true
|
64
|
+
ServiceObjects::DigitCheck.new.execute!
|
65
|
+
#=> #<PayDirt::Result:0xa0be85c @data=nil, @success=true>
|
66
|
+
```
|
67
|
+
As you can see, we can now call `ServiceObjects::DigitCheck.new(fingers: 10, toes: 10).execute!`
|
68
|
+
and expect a successful return object. Where you take it from there is up to you.
|
69
|
+
|
70
|
+
more examples
|
71
|
+
-------------
|
56
72
|
1. [rubeuler](https://github.com/rthbound/rubeuler)
|
57
73
|
2. [protected_record](https://github.com/rthbound/protected_record)
|
58
74
|
3. [konamio](https://github.com/rthbound/konamio)
|
data/lib/pay_dirt/version.rb
CHANGED
data/pay_dirt.thor
CHANGED
@@ -3,80 +3,78 @@ module PayDirt
|
|
3
3
|
include Thor::Actions
|
4
4
|
|
5
5
|
desc "new FILE", "create a service object"
|
6
|
-
method_option :defaults,
|
7
|
-
type: :hash,
|
8
|
-
aliases: "-D",
|
9
|
-
desc: "Specify default dependencies"
|
10
|
-
|
11
6
|
method_option :dependencies,
|
12
7
|
type: :array,
|
13
8
|
aliases: "-d",
|
14
|
-
desc: "
|
9
|
+
desc: "specify required dependencies",
|
15
10
|
required: true
|
16
|
-
|
11
|
+
method_option :defaults,
|
12
|
+
type: :hash,
|
13
|
+
aliases: "-D",
|
14
|
+
desc: "Specify default dependencies"
|
17
15
|
method_option :inherit,
|
18
16
|
type: :boolean,
|
19
|
-
desc: "
|
17
|
+
desc: "inherit from PayDirt::Base class",
|
20
18
|
aliases: "-i",
|
21
19
|
default: true,
|
22
20
|
lazy_default: true
|
23
|
-
|
24
21
|
method_option :include,
|
25
22
|
type: :boolean,
|
26
|
-
desc: "
|
23
|
+
desc: "include the PayDirt::UseCase module (overrides --inherit)",
|
27
24
|
aliases: "-m",
|
28
25
|
lazy_default: true
|
29
|
-
|
30
26
|
def new(file)
|
31
27
|
rets = ""
|
32
28
|
class_names = file.split("/").map { |str| str.split("_").map{ |s| (s[0].upcase + s[1..-1]) }.join("") }
|
33
29
|
defaults = options[:defaults] || []
|
34
30
|
dependencies = options[:dependencies]
|
35
31
|
|
32
|
+
# Favor 2 spaces
|
33
|
+
append = Proc.new { |depth, string, rets| rets << (" " * depth) + string }
|
34
|
+
|
36
35
|
create_file "lib/service_objects/#{file}.rb" do
|
37
|
-
rets
|
38
|
-
rets << "module ServiceObjects\n"
|
36
|
+
rets = append.call(0, "require 'pay_dirt'\n\nmodule ServiceObjects\n", rets)
|
39
37
|
class_names[0..-2].each_with_index do |mod,i|
|
40
|
-
rets
|
38
|
+
rets = append.call(i.next, "module #{mod}\n", rets)
|
41
39
|
end
|
42
40
|
|
43
|
-
|
41
|
+
class_name, class_depth = class_names.last, class_names.length
|
44
42
|
|
45
43
|
if options[:include]
|
46
|
-
rets
|
47
|
-
rets
|
44
|
+
rets = append.call(class_depth, "class #{class_name}\n", rets)
|
45
|
+
rets = append.call(class_depth.next, "include PayDirt::UseCase\n", rets)
|
48
46
|
elsif options[:inherit]
|
49
|
-
rets
|
47
|
+
rets = append.call(class_depth, "class #{class_name} < PayDirt::Base\n", rets)
|
50
48
|
end
|
51
49
|
|
52
|
-
|
50
|
+
inner_depth = class_depth.next
|
53
51
|
|
54
52
|
# The initialize method
|
55
|
-
rets
|
53
|
+
rets = append.call(inner_depth, "def initialize(options = {})\n", rets)
|
56
54
|
|
57
55
|
# Configure dependencies' default values
|
58
56
|
if options[:defaults]
|
59
|
-
rets
|
57
|
+
rets = append.call(inner_depth.next, "options = {\n", rets)
|
60
58
|
|
61
59
|
defaults.each do |k,v|
|
62
|
-
rets
|
60
|
+
rets = append.call(inner_depth + 2, "#{k}: #{v}" + ",\n", rets)
|
63
61
|
end
|
64
62
|
|
65
|
-
rets
|
63
|
+
rets = append.call(inner_depth.next, "}.merge(options)\n\n", rets)
|
66
64
|
end
|
67
65
|
|
68
|
-
rets
|
69
|
-
rets
|
66
|
+
rets = append.call(inner_depth.next, "load_options(:#{dependencies.join(', :')}, options)\n", rets)
|
67
|
+
rets = append.call(inner_depth, "end\n\n", rets)
|
70
68
|
|
71
69
|
# The execute! method
|
72
|
-
rets
|
73
|
-
rets
|
74
|
-
rets
|
70
|
+
rets = append.call(inner_depth, "def execute!\n", rets)
|
71
|
+
rets = append.call(inner_depth.next, "return PayDirt::Result.new(success: true, data: nil)\n", rets)
|
72
|
+
rets = append.call(inner_depth, "end\n", rets)
|
75
73
|
|
76
|
-
rets
|
74
|
+
rets = append.call(class_depth, "end\n", rets) # Closes innermost class definition
|
77
75
|
|
78
76
|
class_names[0..-1].each_with_index do |mod,i|
|
79
|
-
rets
|
77
|
+
rets = append.call(class_depth - (i + 1), "end\n", rets)
|
80
78
|
end
|
81
79
|
|
82
80
|
rets
|
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.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-06-
|
11
|
+
date: 2013-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|