pay_dirt 1.0.3 → 1.0.4

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: f71a66d986dd7306f081a8733941c86732d1241d
4
- data.tar.gz: 6136207dd8d8019fc5d67bad7524603776adbc3c
3
+ metadata.gz: c384f986821d54bb9a87d60d500ca599162c33d0
4
+ data.tar.gz: b608fe834f4050ccabac596c2f577cd32b380b9f
5
5
  SHA512:
6
- metadata.gz: 5c05fc08df625e3233f4483d157ab423494d77c289d106ee1662904aac4d0cc510adef77be92fa37fd1f79c5431987f29da01f11148c03f3eb0892e5aecbca97
7
- data.tar.gz: 19484512b38035bb91d339b1dd4f1ba907129fc78d7b1e2cd1da765db46b67900690a0466149724bcb1fd66a61b3bf9800182cdc86556297a620ea90cfa2286e
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
- Reduce a towering codebase to modular rubble (or more Ruby gems) with **PayDirt**
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
- It'll tell you **how it's used**:
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] # Specify default dependencies
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)
@@ -1,3 +1,3 @@
1
1
  module PayDirt
2
- VERSION = "1.0.3"
2
+ VERSION = "1.0.4"
3
3
  end
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
- defaults = options[:defaults] || []
29
- dependencies = options[:dependencies] || []
27
+ @dependencies = options[:dependencies] || []
30
28
 
31
29
  # Favor 2 spaces
32
- append = Proc.new { |depth, string, rets| rets << (" " * depth) + string }
30
+ @append = Proc.new { |depth, string| (@rets ||= "") << (" " * depth) + string }
33
31
 
34
32
  create_file "lib/service_objects/#{file}.rb" do
35
- rets = append.call(0, "require 'pay_dirt'\n\nmodule ServiceObjects\n", rets)
36
- class_names[0..-2].each_with_index do |mod,i|
37
- rets = append.call(i.next, "module #{mod}\n", rets)
38
- end
33
+ open_class(class_names)
34
+ write_initialize_method
35
+ write_execute_method
39
36
 
40
- class_name, class_depth = class_names.last, class_names.length
37
+ close_class(class_names)
41
38
 
42
- if options[:include]
43
- rets = append.call(class_depth, "class #{class_name}\n", rets)
44
- rets = append.call(class_depth.next, "include PayDirt::UseCase\n", rets)
45
- elsif options[:inherit]
46
- rets = append.call(class_depth, "class #{class_name} < PayDirt::Base\n", rets)
47
- end
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
- inner_depth = class_depth.next
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
- # The initialize method
52
- rets = append.call(inner_depth, "def initialize(options = {})\n", rets)
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
- # Configure dependencies' default values
55
- if options[:defaults]
56
- rets = append.call(inner_depth.next, "options = {\n", rets)
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
- defaults.each do |k,v|
59
- rets = append.call(inner_depth + 2, "#{k}: #{v}" + ",\n", rets)
60
- end
75
+ def write_initialize_method
76
+ @append.call(@inner_depth, "def initialize(options = {})\n")
61
77
 
62
- rets = append.call(inner_depth.next, "}.merge(options)\n\n", rets)
63
- end
78
+ set_defaults if options[:defaults]
79
+ call_load_options
64
80
 
65
- rets = append.call(inner_depth.next, "load_options(", rets)
66
- dependencies.each do |dep|
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
- # The execute! method
73
- rets = append.call(inner_depth, "def execute!\n", rets)
74
- rets = append.call(inner_depth.next, "return PayDirt::Result.new(success: true, data: nil)\n", rets)
75
- rets = append.call(inner_depth, "end\n", rets)
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
- rets = append.call(class_depth, "end\n", rets) # Closes innermost class definition
90
+ def set_defaults
91
+ @append.call(@inner_depth.next, "options = {\n")
78
92
 
79
- class_names[0..-1].each_with_index do |mod,i|
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
- rets
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.3
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-23 00:00:00.000000000 Z
11
+ date: 2013-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest