industrialist 0.1.0 → 0.2.0
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 +4 -4
- data/.circleci/config.yml +64 -0
- data/.ruby-version +1 -0
- data/CODEOWNERS +1 -0
- data/Gemfile.lock +11 -0
- data/README.md +71 -13
- data/industrialist.gemspec +3 -1
- data/lib/industrialist/{factory_registrar.rb → manufacturable.rb} +2 -2
- data/lib/industrialist/version.rb +1 -1
- data/lib/industrialist.rb +1 -1
- metadata +36 -6
- data/.travis.yml +0 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cd7fb7720135907dea79b0cc53027f01a00560c4ec2bed8f29ace258b2e80ad7
|
|
4
|
+
data.tar.gz: 21571fffac5950a35e72ea1f417e7879b25d6ca76b5b3a1de5d762c61632f78e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 41f072ae7c53a9a279117823451fa177000e32ea1a3916114501dcce8054fcd3327a423f3f4bde136c57d8d7e4a2e3ece44eb0463cb46cbcb7a6245fcce73e22
|
|
7
|
+
data.tar.gz: ffd5b00604b5173c93a9b59ceeec269a7346bc1a974feeb753377c2d8a177e32bcfac296b7ba497c4699cf40037a61755eb3c9c48d5c43deaf397f470f78d075
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Ruby CircleCI 2.0 configuration file
|
|
2
|
+
#
|
|
3
|
+
# Check https://circleci.com/docs/2.0/language-ruby/ for more details
|
|
4
|
+
#
|
|
5
|
+
version: 2
|
|
6
|
+
jobs:
|
|
7
|
+
build:
|
|
8
|
+
environment:
|
|
9
|
+
- CC_TEST_REPORTER_ID: fdc7741becf91330a972b2c91131a0de3712a308e40ee051ab902eda0fb260d0
|
|
10
|
+
|
|
11
|
+
docker:
|
|
12
|
+
# specify the version you desire here
|
|
13
|
+
- image: circleci/ruby:2.6.0
|
|
14
|
+
|
|
15
|
+
# Specify service dependencies here if necessary
|
|
16
|
+
# CircleCI maintains a library of pre-built images
|
|
17
|
+
# documented at https://circleci.com/docs/2.0/circleci-images/
|
|
18
|
+
# - image: circleci/postgres:9.4
|
|
19
|
+
|
|
20
|
+
working_directory: ~/repo
|
|
21
|
+
|
|
22
|
+
steps:
|
|
23
|
+
- checkout
|
|
24
|
+
|
|
25
|
+
# Download and cache dependencies
|
|
26
|
+
- restore_cache:
|
|
27
|
+
keys:
|
|
28
|
+
- v1-dependencies-{{ checksum "Gemfile.lock" }}
|
|
29
|
+
# fallback to using the latest cache if no exact match is found
|
|
30
|
+
- v1-dependencies-
|
|
31
|
+
|
|
32
|
+
- run: gem install bundler
|
|
33
|
+
- run:
|
|
34
|
+
name: install dependencies
|
|
35
|
+
command: |
|
|
36
|
+
bundle install --jobs=4 --retry=3 --path vendor/bundle
|
|
37
|
+
|
|
38
|
+
- save_cache:
|
|
39
|
+
paths:
|
|
40
|
+
- ./vendor/bundle
|
|
41
|
+
key: v1-dependencies-{{ checksum "Gemfile.lock" }}
|
|
42
|
+
|
|
43
|
+
# run tests!
|
|
44
|
+
- run:
|
|
45
|
+
name: run tests and report results to code climate
|
|
46
|
+
command: |
|
|
47
|
+
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
|
48
|
+
chmod +x ./cc-test-reporter
|
|
49
|
+
|
|
50
|
+
mkdir /tmp/test-results
|
|
51
|
+
|
|
52
|
+
bundle exec rspec \
|
|
53
|
+
--format progress \
|
|
54
|
+
--format RspecJunitFormatter \
|
|
55
|
+
--out /tmp/test-results/rspec.xml
|
|
56
|
+
|
|
57
|
+
./cc-test-reporter after-build -t simplecov
|
|
58
|
+
|
|
59
|
+
# collect reports
|
|
60
|
+
- store_test_results:
|
|
61
|
+
path: /tmp/test-results
|
|
62
|
+
- store_artifacts:
|
|
63
|
+
path: /tmp/test-results
|
|
64
|
+
destination: test-results
|
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
2.6.0
|
data/CODEOWNERS
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
* @aridlehoover @Fito
|
data/Gemfile.lock
CHANGED
|
@@ -7,6 +7,8 @@ GEM
|
|
|
7
7
|
remote: https://rubygems.org/
|
|
8
8
|
specs:
|
|
9
9
|
diff-lcs (1.3)
|
|
10
|
+
docile (1.3.1)
|
|
11
|
+
json (2.2.0)
|
|
10
12
|
rake (10.5.0)
|
|
11
13
|
rspec (3.8.0)
|
|
12
14
|
rspec-core (~> 3.8.0)
|
|
@@ -21,6 +23,13 @@ GEM
|
|
|
21
23
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
22
24
|
rspec-support (~> 3.8.0)
|
|
23
25
|
rspec-support (3.8.0)
|
|
26
|
+
rspec_junit_formatter (0.4.1)
|
|
27
|
+
rspec-core (>= 2, < 4, != 2.12.0)
|
|
28
|
+
simplecov (0.16.1)
|
|
29
|
+
docile (~> 1.1)
|
|
30
|
+
json (>= 1.8, < 3)
|
|
31
|
+
simplecov-html (~> 0.10.0)
|
|
32
|
+
simplecov-html (0.10.2)
|
|
24
33
|
|
|
25
34
|
PLATFORMS
|
|
26
35
|
ruby
|
|
@@ -30,6 +39,8 @@ DEPENDENCIES
|
|
|
30
39
|
industrialist!
|
|
31
40
|
rake (~> 10.0)
|
|
32
41
|
rspec (~> 3.0)
|
|
42
|
+
rspec_junit_formatter (~> 0.4)
|
|
43
|
+
simplecov (~> 0.16)
|
|
33
44
|
|
|
34
45
|
BUNDLED WITH
|
|
35
46
|
2.0.1
|
data/README.md
CHANGED
|
@@ -1,31 +1,73 @@
|
|
|
1
|
-
|
|
1
|
+
[](https://badge.fury.io/rb/industrialist)
|
|
2
|
+
[](https://codeclimate.com/github/entelo/industrialist/maintainability)
|
|
3
|
+
[](https://codeclimate.com/github/entelo/industrialist/test_coverage)
|
|
4
|
+
[](https://circleci.com/gh/entelo/industrialist)
|
|
2
5
|
|
|
3
|
-
|
|
6
|
+
# Industrialist
|
|
4
7
|
|
|
5
|
-
|
|
8
|
+
Industrialist manufactures factories that build self-registered classes.
|
|
6
9
|
|
|
7
|
-
##
|
|
10
|
+
## Background
|
|
8
11
|
|
|
9
|
-
|
|
12
|
+
At the heart of your typical Gang of Four factory method is a case statement:
|
|
10
13
|
|
|
11
14
|
```ruby
|
|
12
|
-
|
|
15
|
+
class Sedan; end
|
|
16
|
+
class Coupe; end
|
|
17
|
+
class Convertible; end
|
|
18
|
+
|
|
19
|
+
class AutomobileFactory
|
|
20
|
+
def self.build(automobile_type)
|
|
21
|
+
automobile_klass(automobile_type)&.new
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def self.automobile_klass(automobile_type)
|
|
25
|
+
case automobile_type
|
|
26
|
+
when :sedan
|
|
27
|
+
Sedan
|
|
28
|
+
when :coupe
|
|
29
|
+
Coupe
|
|
30
|
+
when :convertible
|
|
31
|
+
Convertible
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
AutomobileFactory.build(:sedan)
|
|
13
37
|
```
|
|
14
38
|
|
|
15
|
-
|
|
39
|
+
The Ruby way to do this is with a Hash:
|
|
16
40
|
|
|
17
|
-
|
|
41
|
+
```ruby
|
|
42
|
+
class Sedan; end
|
|
43
|
+
class Coupe; end
|
|
44
|
+
class Convertible; end
|
|
45
|
+
|
|
46
|
+
class AutomobileFactory
|
|
47
|
+
AUTOMOBILE_KLASSES = {
|
|
48
|
+
sedan: Sedan,
|
|
49
|
+
coupe: Coupe,
|
|
50
|
+
convertible: Convertible
|
|
51
|
+
}.freeze
|
|
52
|
+
|
|
53
|
+
def self.build(automobile_type)
|
|
54
|
+
AUTOMOBILE_KLASSES[automobile_type]&.new
|
|
55
|
+
end
|
|
56
|
+
end
|
|
18
57
|
|
|
19
|
-
|
|
58
|
+
AutomobileFactory.build(:coupe)
|
|
59
|
+
```
|
|
20
60
|
|
|
21
|
-
|
|
61
|
+
But, both of these approaches require you to maintain your factory by hand. In order to extend these factories, you must modify them, which violates the Open/Closed Principle.
|
|
22
62
|
|
|
23
63
|
## Usage
|
|
24
64
|
|
|
65
|
+
Industrialist creates factories for you. Just include the Manufacturable module in a base class and give the factory a name. Industrialist also allows children of the base class to register themselves with the factory by specifying their corresponding key. Like this:
|
|
66
|
+
|
|
25
67
|
```ruby
|
|
26
68
|
class Automobile
|
|
27
|
-
include Industrialist::
|
|
28
|
-
|
|
69
|
+
include Industrialist::Manufacturable
|
|
70
|
+
create_factory :AutomobileFactory
|
|
29
71
|
end
|
|
30
72
|
|
|
31
73
|
class Sedan < Automobile
|
|
@@ -36,13 +78,29 @@ class Coupe < Automobile
|
|
|
36
78
|
corresponds_to :coupe
|
|
37
79
|
end
|
|
38
80
|
|
|
39
|
-
class
|
|
81
|
+
class Cabriolet < Automobile
|
|
40
82
|
corresponds_to :convertible
|
|
41
83
|
end
|
|
42
84
|
|
|
43
85
|
AutomobileFactory.build(:convertible)
|
|
44
86
|
```
|
|
45
87
|
|
|
88
|
+
## Installation
|
|
89
|
+
|
|
90
|
+
Add this line to your application's Gemfile:
|
|
91
|
+
|
|
92
|
+
```ruby
|
|
93
|
+
gem 'industrialist'
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
And then execute:
|
|
97
|
+
|
|
98
|
+
$ bundle
|
|
99
|
+
|
|
100
|
+
Or install it yourself as:
|
|
101
|
+
|
|
102
|
+
$ gem install industrialist
|
|
103
|
+
|
|
46
104
|
## Development
|
|
47
105
|
|
|
48
106
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/industrialist.gemspec
CHANGED
|
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
|
9
9
|
spec.authors = ["Alan Ridlehoover", "Fito von Zastrow"]
|
|
10
10
|
spec.email = ["dev@entelo.com"]
|
|
11
11
|
|
|
12
|
-
spec.summary = "Industrialist
|
|
12
|
+
spec.summary = "Industrialist manufactures factories that build self-registered classes."
|
|
13
13
|
spec.homepage = "https://github.com/entelo/industrialist"
|
|
14
14
|
spec.license = "MIT"
|
|
15
15
|
|
|
@@ -29,4 +29,6 @@ Gem::Specification.new do |spec|
|
|
|
29
29
|
spec.add_development_dependency "bundler", "~> 2.0"
|
|
30
30
|
spec.add_development_dependency "rake", "~> 10.0"
|
|
31
31
|
spec.add_development_dependency "rspec", "~> 3.0"
|
|
32
|
+
spec.add_development_dependency "rspec_junit_formatter", "~>0.4"
|
|
33
|
+
spec.add_development_dependency "simplecov", "~>0.16"
|
|
32
34
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require 'industrialist/factory'
|
|
2
2
|
|
|
3
3
|
module Industrialist
|
|
4
|
-
module
|
|
4
|
+
module Manufacturable
|
|
5
5
|
def self.included(base)
|
|
6
6
|
base.extend ClassMethods
|
|
7
7
|
end
|
|
@@ -9,7 +9,7 @@ module Industrialist
|
|
|
9
9
|
module ClassMethods
|
|
10
10
|
@@factory = Industrialist::Factory.new
|
|
11
11
|
|
|
12
|
-
def
|
|
12
|
+
def create_factory(identifier)
|
|
13
13
|
Object.const_set(identifier, @@factory)
|
|
14
14
|
end
|
|
15
15
|
|
data/lib/industrialist.rb
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
require "industrialist/version"
|
|
2
|
-
require "industrialist/
|
|
2
|
+
require "industrialist/manufacturable"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: industrialist
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Alan Ridlehoover
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: exe
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2019-03-
|
|
12
|
+
date: 2019-03-12 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: bundler
|
|
@@ -53,6 +53,34 @@ dependencies:
|
|
|
53
53
|
- - "~>"
|
|
54
54
|
- !ruby/object:Gem::Version
|
|
55
55
|
version: '3.0'
|
|
56
|
+
- !ruby/object:Gem::Dependency
|
|
57
|
+
name: rspec_junit_formatter
|
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
|
59
|
+
requirements:
|
|
60
|
+
- - "~>"
|
|
61
|
+
- !ruby/object:Gem::Version
|
|
62
|
+
version: '0.4'
|
|
63
|
+
type: :development
|
|
64
|
+
prerelease: false
|
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
66
|
+
requirements:
|
|
67
|
+
- - "~>"
|
|
68
|
+
- !ruby/object:Gem::Version
|
|
69
|
+
version: '0.4'
|
|
70
|
+
- !ruby/object:Gem::Dependency
|
|
71
|
+
name: simplecov
|
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
|
73
|
+
requirements:
|
|
74
|
+
- - "~>"
|
|
75
|
+
- !ruby/object:Gem::Version
|
|
76
|
+
version: '0.16'
|
|
77
|
+
type: :development
|
|
78
|
+
prerelease: false
|
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
80
|
+
requirements:
|
|
81
|
+
- - "~>"
|
|
82
|
+
- !ruby/object:Gem::Version
|
|
83
|
+
version: '0.16'
|
|
56
84
|
description:
|
|
57
85
|
email:
|
|
58
86
|
- dev@entelo.com
|
|
@@ -60,10 +88,12 @@ executables: []
|
|
|
60
88
|
extensions: []
|
|
61
89
|
extra_rdoc_files: []
|
|
62
90
|
files:
|
|
91
|
+
- ".circleci/config.yml"
|
|
63
92
|
- ".gitignore"
|
|
64
93
|
- ".rspec"
|
|
65
94
|
- ".rubocop.yml"
|
|
66
|
-
- ".
|
|
95
|
+
- ".ruby-version"
|
|
96
|
+
- CODEOWNERS
|
|
67
97
|
- CODE_OF_CONDUCT.md
|
|
68
98
|
- Gemfile
|
|
69
99
|
- Gemfile.lock
|
|
@@ -75,7 +105,7 @@ files:
|
|
|
75
105
|
- industrialist.gemspec
|
|
76
106
|
- lib/industrialist.rb
|
|
77
107
|
- lib/industrialist/factory.rb
|
|
78
|
-
- lib/industrialist/
|
|
108
|
+
- lib/industrialist/manufacturable.rb
|
|
79
109
|
- lib/industrialist/version.rb
|
|
80
110
|
homepage: https://github.com/entelo/industrialist
|
|
81
111
|
licenses:
|
|
@@ -99,8 +129,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
99
129
|
- !ruby/object:Gem::Version
|
|
100
130
|
version: '0'
|
|
101
131
|
requirements: []
|
|
102
|
-
rubygems_version: 3.0.
|
|
132
|
+
rubygems_version: 3.0.1
|
|
103
133
|
signing_key:
|
|
104
134
|
specification_version: 4
|
|
105
|
-
summary: Industrialist
|
|
135
|
+
summary: Industrialist manufactures factories that build self-registered classes.
|
|
106
136
|
test_files: []
|