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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0b0248574c00871f3ef6676055ad9fb7c48acd35
4
- data.tar.gz: 8337f0b5fe6377dfaa00183b62465ecec055f17a
3
+ metadata.gz: cf8344185d4a1298169b244cf23f489243eace6b
4
+ data.tar.gz: 32a3740b097d5e552821911207567a0a2bfa91c2
5
5
  SHA512:
6
- metadata.gz: 7f21b11cf6ae2914e06fdc48c7ae2e7e3de1f6f4f6f47ea79ecbc22ea3ce6cb8e1325e380e7bb97ed4237333810b820cb6d9d1d017c3c51adda455dec8e5ff4d
7
- data.tar.gz: bc92bbb77e64ad90bad2c5a0a521174d5b6f38c0e3ae827927f62f8d1698ca89f9d2d4a43d8b88557739e10c026123f95e23e3d26b0ebfd0de9c276aeb640283
6
+ metadata.gz: fc804ad76e3d60ad5afb2426a19f6880cec4768261e4406859ee8227ff8ff2da891502dba57765177570889490e7726ced468ab7d7dedddb6a97d6d53c05d04d
7
+ data.tar.gz: dd906232ef74d54c6248d2fbfe844929822b4c08fd65b110b16ed1e290b7f64ce6520111a5205e7dec6574730defd2dc0dd99ed63f491b55c2e951c397c1de60
data/.travis.yml CHANGED
@@ -1,4 +1,9 @@
1
1
  language: ruby
2
+
3
+ matrix:
4
+ allow_failures:
5
+ - rvm: ruby-head
6
+
2
7
  rvm:
3
8
  - 2.0.0
4
9
  - 1.9.3
@@ -6,4 +11,5 @@ rvm:
6
11
  - jruby-19mode
7
12
  - ruby-head
8
13
  - jruby-head
14
+
9
15
  script: bundle exec rake test
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
- Provides the basic building blocks of a pattern capable of reducing a towering codebase to modular rubble (or more Ruby gems)
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
- ### Generators
13
-
14
- PayDirt now provides a service object generator, powered by [thor](https://github.com/erikhuda/thor). It takes a few options
15
-
16
- `--dependencies` or `-d` : An array of required dependencies (this option is required)
17
-
18
- `--defaults` or `-D` : An optional hash of default values for dependencies
19
-
20
- `--inherit` or `-i` : A boolean flag, raise it for an implementation that inherits from `PayDirt::Base` (this is default behavior)
21
-
22
- `--include` or `-m` : A boolean flag, raise it for an implementation that includes `PayDirt::UseCase`
23
-
24
- Example:
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
- ### Other examples
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)
@@ -1,3 +1,3 @@
1
1
  module PayDirt
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
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: "Specify required dependencies",
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: "Should inherit from PayDirt::Base (default)",
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: "Should include the PayDirt::UseCase module",
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 << "require 'pay_dirt'\n\n"
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 << (" " * ( (i+1) * 2 )) + "module #{mod}\n"
38
+ rets = append.call(i.next, "module #{mod}\n", rets)
41
39
  end
42
40
 
43
- klass, klass_index = class_names[-1], class_names.length
41
+ class_name, class_depth = class_names.last, class_names.length
44
42
 
45
43
  if options[:include]
46
- rets << (" " * ( klass_index * 2)) + "class #{class_names[-1]}\n"
47
- rets << (" " * ((klass_index + 1) * 2)) + "include PayDirt::UseCase\n"
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 << (" " * ( klass_index * 2)) + "class #{class_names[-1]} < PayDirt::Base\n"
47
+ rets = append.call(class_depth, "class #{class_name} < PayDirt::Base\n", rets)
50
48
  end
51
49
 
52
- inner_index = klass_index + 1
50
+ inner_depth = class_depth.next
53
51
 
54
52
  # The initialize method
55
- rets << (" " * ( inner_index * 2 )) + "def initialize(options = {})\n"
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 << (" " * ( (inner_index + 1) * 2 )) + "options = {\n"
57
+ rets = append.call(inner_depth.next, "options = {\n", rets)
60
58
 
61
59
  defaults.each do |k,v|
62
- rets << (" " * ( (inner_index + 2) * 2 )) + "#{k}: #{v}" + ",\n"
60
+ rets = append.call(inner_depth + 2, "#{k}: #{v}" + ",\n", rets)
63
61
  end
64
62
 
65
- rets << (" " * ( (inner_index + 1) * 2 )) + "}.merge(options)\n\n"
63
+ rets = append.call(inner_depth.next, "}.merge(options)\n\n", rets)
66
64
  end
67
65
 
68
- rets << (" " * ( (inner_index + 1) * 2 )) + "load_options(:#{dependencies.join(', :')}, options)\n"
69
- rets << (" " * ( inner_index * 2 )) + "end\n\n"
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 << (" " * ( inner_index * 2 )) + "def execute!\n"
73
- rets << (" " * ( (inner_index + 1) * 2 )) + "return PayDirt::Result.new(success: true, data: nil)\n"
74
- rets << (" " * ( inner_index * 2 )) + "end\n"
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 << (" " * ( klass_index * 2)) + "end\n"
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 << (" " * ( (class_names.length - (i + 1)).abs * 2 )) + "end\n"
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.1
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-21 00:00:00.000000000 Z
11
+ date: 2013-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest