pay_dirt 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 02ffbebfd616ea3615894973a41e9c54844fc270
4
+ data.tar.gz: 13ae80297a56e44103e3f95633b67445dd08543c
5
+ SHA512:
6
+ metadata.gz: b5fcfcbd57874ab7e28232ff5fa2b913981fd187e1dfaffd22563717c3e98690a08491e86dbc9d22958092c5d8d67a528edff8017e48a840e05d66398996de64
7
+ data.tar.gz: 6144b015159bccc341ddf46d86341d540945cc23bf68afddcf5504a6281ec5bd2f7d5817debbeae3993cd324665ab7047c7d2983ba7201f11b2fa6bc2f03faca
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ # See http://help.github.com/ignore-files/ for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile ~/.gitignore_global
6
+
7
+ # Ignore bundler config
8
+ /.bundle
9
+
10
+ *.sw?
11
+ .sw?
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ pay_dirt
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.0.0-p0
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ ## pay_dirt
2
+ #### A Ruby gem based on the "use case" pattern set forth in [opencurriculum-flashcards](https://github.com/isotope11/opencurriculum-flashcards)
3
+
4
+ Provides the basic building blocks of a pattern capable of reducing a towering codebase to modular rubble (or more Ruby gems)
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.pattern = 'test/**/*_test.rb'
6
+ t.libs.push 'test'
7
+ end
8
+
9
+ task :default => :test
@@ -0,0 +1,11 @@
1
+ module PayDirt
2
+ class Base
3
+ def load_option(option, options)
4
+ instance_variable_set("@#{option}", options.fetch(option.to_sym) { raise "Missing required option: #{option}" } )
5
+ end
6
+
7
+ def load_options(*option_names, options)
8
+ option_names.each{|o| load_option(o, options) }
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,33 @@
1
+ module PayDirt
2
+ class Result
3
+ # The response from a use case execution
4
+ #
5
+ # Every use case should return a Result after it runs.
6
+ #
7
+ # @param [options] options_hash
8
+ # A hash specifying the appropriate options
9
+ #
10
+ # @return [PayDirt::Result]
11
+ # the Result instance
12
+ #
13
+ # @example
14
+ # PayDirt::Result.new(success: true, data: {})
15
+ # # => <PayDirt::Result>
16
+ #
17
+ # @api public
18
+ def initialize(options)
19
+ @success = options[:success]
20
+ @data = options[:data]
21
+ end
22
+
23
+ # @api public
24
+ def successful?
25
+ !!@success
26
+ end
27
+
28
+ # @api public
29
+ def data
30
+ @data
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module PayDirt
2
+ VERSION = "0.0.0"
3
+ end
data/lib/pay_dirt.rb ADDED
@@ -0,0 +1,3 @@
1
+ # Load use case files
2
+ require "#{File.dirname(__FILE__)}/pay_dirt/base.rb"
3
+ Dir["#{File.dirname(__FILE__)}/pay_dirt/**/*.rb"].each { |f| require f }
data/pay_dirt.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "pay_dirt/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "pay_dirt"
7
+ s.version = PayDirt::VERSION
8
+ s.authors = ["Tad Hosford"]
9
+ s.email = ["tad.hosford@gmail.com"]
10
+ s.homepage = "http://github.com/rthbound/pay_dirt"
11
+ s.description = %q{
12
+ Provides the basic building blocks
13
+ of a pattern capable of reducing a
14
+ towering codebase to modular rubble
15
+ (or more Ruby gems)
16
+ }
17
+ s.summary = %q{
18
+ Based on a pattern introduced to me
19
+ by knewter.
20
+ }
21
+
22
+ s.files = `git ls-files`.split("\n")
23
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
24
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
25
+ s.require_paths = ["lib"]
26
+
27
+ s.add_development_dependency "minitest"
28
+ s.add_development_dependency "rake"
29
+ s.add_development_dependency "pry"
30
+ end
@@ -0,0 +1,14 @@
1
+ # Set up simplecov
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require "minitest/spec"
5
+ require "minitest/autorun"
6
+
7
+ # Debugger
8
+ require "pry"
9
+
10
+ # The gem
11
+ $: << File.dirname(__FILE__) + "/../lib"
12
+ $: << File.dirname(__FILE__)
13
+
14
+ require "pay_dirt"
File without changes
@@ -0,0 +1,55 @@
1
+ require 'test_helper'
2
+
3
+ describe PayDirt::Base do
4
+ before do
5
+ module UseCase
6
+ class UltimateQuestion < PayDirt::Base
7
+ def initialize(options)
8
+ load_options(:the_secret_to_life_the_universe_and_everything, options)
9
+ end
10
+
11
+ def execute!
12
+ if @the_secret_to_life_the_universe_and_everything == 42
13
+ return PayDirt::Result.new(data: @the_secret_to_life_the_universe_and_everything, success: true)
14
+ else
15
+ return PayDirt::Result.new(data: @the_secret_to_life_the_universe_and_everything, success: false)
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ @use_case = UseCase::UltimateQuestion
22
+ end
23
+
24
+ it "must inherit from PayDirt::Base" do
25
+ assert_operator @use_case, :<, PayDirt::Base
26
+ end
27
+
28
+ it "must error when initialized without required options" do
29
+ begin
30
+ @use_case.new
31
+ rescue => e
32
+ e.must_be_kind_of ArgumentError
33
+ end
34
+ end
35
+
36
+ it "can execute successfully" do
37
+ dependencies = {
38
+ the_secret_to_life_the_universe_and_everything: 42
39
+ }
40
+
41
+ result = @use_case.new(dependencies).execute!
42
+
43
+ result.successful?.must_equal true
44
+ end
45
+
46
+ it "can execute successfully" do
47
+ dependencies = {
48
+ the_secret_to_life_the_universe_and_everything: :i_dunno
49
+ }
50
+
51
+ result = @use_case.new(dependencies).execute!
52
+
53
+ result.successful?.must_equal false
54
+ end
55
+ end
@@ -0,0 +1,13 @@
1
+ require 'test_helper'
2
+
3
+ describe PayDirt::Result do
4
+ it "knows whether it was successful or not" do
5
+ pay_dirt = PayDirt::Result.new(success: true)
6
+ pay_dirt.successful?.must_equal true
7
+ end
8
+
9
+ it "provides access to its data" do
10
+ pay_dirt = PayDirt::Result.new(data: 'foo')
11
+ pay_dirt.data.must_equal 'foo'
12
+ end
13
+ end
@@ -0,0 +1,55 @@
1
+ require 'test_helper'
2
+
3
+ describe PayDirt::Base do
4
+ before do
5
+ module UseCase
6
+ class UltimateQuestion < PayDirt::Base
7
+ def initialize(options)
8
+ load_options(:the_secret_to_life_the_universe_and_everything, options)
9
+ end
10
+
11
+ def execute!
12
+ if @the_secret_to_life_the_universe_and_everything == 42
13
+ return PayDirt::Result.new(data: @the_secret_to_life_the_universe_and_everything, success: true)
14
+ else
15
+ return PayDirt::Result.new(data: @the_secret_to_life_the_universe_and_everything, success: false)
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ @use_case = UseCase::UltimateQuestion
22
+ end
23
+
24
+ it "must inherit from PayDirt::Base" do
25
+ assert_operator @use_case, :<, PayDirt::Base
26
+ end
27
+
28
+ it "must error when initialized without required options" do
29
+ begin
30
+ @use_case.new
31
+ rescue => e
32
+ e.must_be_kind_of ArgumentError
33
+ end
34
+ end
35
+
36
+ it "can execute successfully" do
37
+ dependencies = {
38
+ the_secret_to_life_the_universe_and_everything: 42
39
+ }
40
+
41
+ result = @use_case.new(dependencies).execute!
42
+
43
+ result.successful?.must_equal true
44
+ end
45
+
46
+ it "can execute successfully" do
47
+ dependencies = {
48
+ the_secret_to_life_the_universe_and_everything: :i_dunno
49
+ }
50
+
51
+ result = @use_case.new(dependencies).execute!
52
+
53
+ result.successful?.must_equal false
54
+ end
55
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pay_dirt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Tad Hosford
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-04-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: "\n Provides the basic building blocks\n of
56
+ a pattern capable of reducing a\n towering codebase to modular
57
+ rubble\n (or more Ruby gems)\n "
58
+ email:
59
+ - tad.hosford@gmail.com
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - .gitignore
65
+ - .ruby-gemset
66
+ - .ruby-version
67
+ - Gemfile
68
+ - README.md
69
+ - Rakefile
70
+ - lib/pay_dirt.rb
71
+ - lib/pay_dirt/base.rb
72
+ - lib/pay_dirt/result.rb
73
+ - lib/pay_dirt/version.rb
74
+ - pay_dirt.gemspec
75
+ - test/test_helper.rb
76
+ - test/unit/.gitkeep
77
+ - test/unit/pay_dirt/base_test.rb
78
+ - test/unit/pay_dirt/result_test.rb
79
+ - test/unit/pay_dirt/use_case.rb
80
+ homepage: http://github.com/rthbound/pay_dirt
81
+ licenses: []
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.0.0.rc.2
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: Based on a pattern introduced to me by knewter.
103
+ test_files: []