pay_dirt 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -3
- data/lib/pay_dirt/version.rb +1 -1
- data/pay_dirt.thor +53 -42
- 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: c384f986821d54bb9a87d60d500ca599162c33d0
|
4
|
+
data.tar.gz: b608fe834f4050ccabac596c2f577cd32b380b9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fc872999a33075bf0d80de2ae90c1d0b4f5fa47cd0229e168ee826d3c16ae02c6966cda408c04ca56761381b2ed04e5ec0cb4c8388ad605dba54366ff553fda
|
7
|
+
data.tar.gz: d44a64394081bd6ede1a1359606c00ed3e0e073fb43252d12a4303ce025aca60444b3e906163df30e3b68598a36e2cc6ecdb2a14bcc9b8de44c8ab65a2835270
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
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
|
+
Provides the basic building blocks of a pattern capable of reducing a towering codebase to modular rubble (or more Ruby gems)
|
6
6
|
|
7
7
|
There are two ways to employ the pattern:
|
8
8
|
|
@@ -13,7 +13,18 @@ service object generator
|
|
13
13
|
------------------------
|
14
14
|
pay_dirt now provides a service object generator,
|
15
15
|
powered by [thor](https://github.com/erikhuda/thor).
|
16
|
-
|
16
|
+
In order to use them in your rails app, you'll need to install the task. Here's how:
|
17
|
+
|
18
|
+
```
|
19
|
+
$ thor install https://raw.github.com/rthbound/pay_dirt/master/pay_dirt.thor
|
20
|
+
...
|
21
|
+
Do you wish to continue [y/N]? y
|
22
|
+
Please specify a name for https://raw.github.com/rthbound/pay_dirt/master/pay_dirt.thor in the system repository [pay_dirt.thor]: pay_dirt
|
23
|
+
Storing thor file in your system repository
|
24
|
+
$
|
25
|
+
```
|
26
|
+
|
27
|
+
After installing, you can use your new generator *anywhere* you can use thor. It'll tell you **how it's used**:
|
17
28
|
```
|
18
29
|
$ thor help pay_dirt:service_object:new
|
19
30
|
Usage:
|
@@ -21,7 +32,7 @@ Usage:
|
|
21
32
|
|
22
33
|
Options:
|
23
34
|
-d, --dependencies=one two three # specify required dependencies
|
24
|
-
-D, [--defaults=key:value] #
|
35
|
+
-D, [--defaults=key:value] # specify default dependencies
|
25
36
|
-i, [--inherit] # inherit from PayDirt::Base class
|
26
37
|
# Default: true
|
27
38
|
-m, [--include] # include the PayDirt::UseCase module (overrides --inherit)
|
data/lib/pay_dirt/version.rb
CHANGED
data/pay_dirt.thor
CHANGED
@@ -23,65 +23,76 @@ module PayDirt
|
|
23
23
|
aliases: "-m",
|
24
24
|
lazy_default: true
|
25
25
|
def new(file)
|
26
|
-
rets = ""
|
27
26
|
class_names = file.split("/").map { |str| str.split("_").map{ |s| (s[0].upcase + s[1..-1]) }.join("") }
|
28
|
-
|
29
|
-
dependencies = options[:dependencies] || []
|
27
|
+
@dependencies = options[:dependencies] || []
|
30
28
|
|
31
29
|
# Favor 2 spaces
|
32
|
-
append = Proc.new { |depth, string
|
30
|
+
@append = Proc.new { |depth, string| (@rets ||= "") << (" " * depth) + string }
|
33
31
|
|
34
32
|
create_file "lib/service_objects/#{file}.rb" do
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
33
|
+
open_class(class_names)
|
34
|
+
write_initialize_method
|
35
|
+
write_execute_method
|
39
36
|
|
40
|
-
|
37
|
+
close_class(class_names)
|
41
38
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
39
|
+
@rets
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
desc "close_class CLASS_NAMES", "hide", hide: true
|
45
|
+
def close_class(class_names)
|
46
|
+
@append.call(@class_depth, "end\n") # Closes innermost class definition
|
47
|
+
|
48
|
+
class_names[0..-1].each_with_index { |m,i| @append.call(@class_depth - (i + 1), "end\n") }
|
49
|
+
end
|
50
|
+
|
51
|
+
desc "open_class CLASS_NAMES", "hide", hide: true
|
52
|
+
def open_class(class_names)
|
53
|
+
@class_name = class_names.last
|
54
|
+
@class_depth = class_names.length
|
55
|
+
@inner_depth = class_names.length + 1
|
48
56
|
|
49
|
-
|
57
|
+
@append.call(0, "require 'pay_dirt'\n\nmodule ServiceObjects\n")
|
58
|
+
class_names[0..-2].each_with_index { |mod,i| @append.call(i.next, "module #{mod}\n") }
|
50
59
|
|
51
|
-
|
52
|
-
|
60
|
+
if options[:include]
|
61
|
+
@append.call(@class_depth, "class #{@class_name}\n")
|
62
|
+
@append.call(@class_depth.next, "include PayDirt::UseCase\n")
|
63
|
+
elsif options[:inherit]
|
64
|
+
@append.call(@class_depth, "class #{@class_name} < PayDirt::Base\n")
|
65
|
+
end
|
66
|
+
end
|
53
67
|
|
54
|
-
|
55
|
-
|
56
|
-
|
68
|
+
def write_execute_method
|
69
|
+
# The execute! method
|
70
|
+
@append.call(@inner_depth, "def execute!\n")
|
71
|
+
@append.call(@inner_depth.next, "return PayDirt::Result.new(success: true, data: nil)\n")
|
72
|
+
@append.call(@inner_depth, "end\n")
|
73
|
+
end
|
57
74
|
|
58
|
-
|
59
|
-
|
60
|
-
end
|
75
|
+
def write_initialize_method
|
76
|
+
@append.call(@inner_depth, "def initialize(options = {})\n")
|
61
77
|
|
62
|
-
|
63
|
-
|
78
|
+
set_defaults if options[:defaults]
|
79
|
+
call_load_options
|
64
80
|
|
65
|
-
|
66
|
-
|
67
|
-
rets = append.call(0, ":#{dep}, ", rets)
|
68
|
-
end
|
69
|
-
rets = append.call(0, "options)\n", rets)
|
70
|
-
rets = append.call(inner_depth, "end\n\n", rets)
|
81
|
+
@append.call(@inner_depth, "end\n\n")
|
82
|
+
end
|
71
83
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
84
|
+
def call_load_options
|
85
|
+
@append.call(@inner_depth.next, "load_options(")
|
86
|
+
@dependencies.each { |dep| @append.call(0, ":#{dep}, ") }
|
87
|
+
@append.call(0, "options)\n")
|
88
|
+
end
|
76
89
|
|
77
|
-
|
90
|
+
def set_defaults
|
91
|
+
@append.call(@inner_depth.next, "options = {\n")
|
78
92
|
|
79
|
-
|
80
|
-
rets = append.call(class_depth - (i + 1), "end\n", rets)
|
81
|
-
end
|
93
|
+
options[:defaults].each { |k,v| @append.call(@inner_depth + 2, "#{k}: #{v}" + ",\n") }
|
82
94
|
|
83
|
-
|
84
|
-
end
|
95
|
+
@append.call(@inner_depth.next, "}.merge(options)\n\n")
|
85
96
|
end
|
86
97
|
end
|
87
98
|
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.
|
4
|
+
version: 1.0.4
|
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-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|