industrialist 0.2.0 → 0.2.1
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/Gemfile.lock +1 -1
- data/README.md +4 -4
- data/lib/industrialist/manufacturable.rb +14 -4
- data/lib/industrialist/version.rb +1 -1
- data/lib/industrialist/warning_helper.rb +10 -0
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3a3998881cb741baf0f4f3a06a2f8c8343c480c552c87db6b60bc0d47fb82bfb
|
|
4
|
+
data.tar.gz: 6751295253162859167d9fe8e5309c6efb08dd1c771b6e5d24994eb865036269
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9f293cbdf92b0c815d935bd083198a1b775077a7b445c00d24d18e482e896ff9e6dd82b2170772e00d164d9e2241e994592730ce6c5e7e9f86d286c97bb2aec0
|
|
7
|
+
data.tar.gz: 3bb06cf274487d4dac2027f981de51186c44262cc7dd9ac4b5008041df8bc6ed538b039a6289d9326b3b05ce52d3c57bdec3d2da4ca5ac29d57855bd71eb5303
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -14,7 +14,7 @@ At the heart of your typical Gang of Four factory method is a case statement:
|
|
|
14
14
|
```ruby
|
|
15
15
|
class Sedan; end
|
|
16
16
|
class Coupe; end
|
|
17
|
-
class
|
|
17
|
+
class Cabriolet; end
|
|
18
18
|
|
|
19
19
|
class AutomobileFactory
|
|
20
20
|
def self.build(automobile_type)
|
|
@@ -28,7 +28,7 @@ class AutomobileFactory
|
|
|
28
28
|
when :coupe
|
|
29
29
|
Coupe
|
|
30
30
|
when :convertible
|
|
31
|
-
|
|
31
|
+
Cabriolet
|
|
32
32
|
end
|
|
33
33
|
end
|
|
34
34
|
end
|
|
@@ -41,13 +41,13 @@ The Ruby way to do this is with a Hash:
|
|
|
41
41
|
```ruby
|
|
42
42
|
class Sedan; end
|
|
43
43
|
class Coupe; end
|
|
44
|
-
class
|
|
44
|
+
class Cabriolet; end
|
|
45
45
|
|
|
46
46
|
class AutomobileFactory
|
|
47
47
|
AUTOMOBILE_KLASSES = {
|
|
48
48
|
sedan: Sedan,
|
|
49
49
|
coupe: Coupe,
|
|
50
|
-
convertible:
|
|
50
|
+
convertible: Cabriolet
|
|
51
51
|
}.freeze
|
|
52
52
|
|
|
53
53
|
def self.build(automobile_type)
|
|
@@ -1,20 +1,30 @@
|
|
|
1
1
|
require 'industrialist/factory'
|
|
2
|
+
require 'industrialist/warning_helper'
|
|
2
3
|
|
|
3
4
|
module Industrialist
|
|
4
5
|
module Manufacturable
|
|
6
|
+
extend WarningHelper
|
|
7
|
+
|
|
8
|
+
ALREADY_INCLUDED_WARNING_MESSAGE = 'warning: a factory is already defined on this class hierarchy'.freeze
|
|
9
|
+
|
|
5
10
|
def self.included(base)
|
|
11
|
+
warning(ALREADY_INCLUDED_WARNING_MESSAGE) if base.class_variable_defined?(:@@factory)
|
|
12
|
+
|
|
6
13
|
base.extend ClassMethods
|
|
14
|
+
base.class_variable_set(:@@factory, Industrialist::Factory.new)
|
|
7
15
|
end
|
|
8
16
|
|
|
9
17
|
module ClassMethods
|
|
10
|
-
@@factory = Industrialist::Factory.new
|
|
11
|
-
|
|
12
18
|
def create_factory(identifier)
|
|
13
|
-
Object.const_set(identifier,
|
|
19
|
+
Object.const_set(identifier, factory)
|
|
14
20
|
end
|
|
15
21
|
|
|
16
22
|
def corresponds_to(key)
|
|
17
|
-
|
|
23
|
+
factory.register(key, self)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def factory
|
|
27
|
+
class_variable_get(:@@factory)
|
|
18
28
|
end
|
|
19
29
|
end
|
|
20
30
|
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
module Industrialist
|
|
2
|
+
module WarningHelper
|
|
3
|
+
def warning(message)
|
|
4
|
+
most_recent_caller = caller(2..2).first.split(':')
|
|
5
|
+
file_name = most_recent_caller[0]
|
|
6
|
+
line_number = most_recent_caller[1]
|
|
7
|
+
warn("#{file_name}:#{line_number}: #{message}")
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
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.2.
|
|
4
|
+
version: 0.2.1
|
|
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-22 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: bundler
|
|
@@ -107,6 +107,7 @@ files:
|
|
|
107
107
|
- lib/industrialist/factory.rb
|
|
108
108
|
- lib/industrialist/manufacturable.rb
|
|
109
109
|
- lib/industrialist/version.rb
|
|
110
|
+
- lib/industrialist/warning_helper.rb
|
|
110
111
|
homepage: https://github.com/entelo/industrialist
|
|
111
112
|
licenses:
|
|
112
113
|
- MIT
|