manufacturable 1.0.1 → 1.3.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
  SHA256:
3
- metadata.gz: 554e6c657da02aee6b562be4f814b2b5c07b084ffb96a788f703a7ac8dcd882e
4
- data.tar.gz: decfafcea45c7577d1188479cafbfb67dc79c12cf9c1b0e9bba80eeaa4f4ced3
3
+ metadata.gz: 91d256244ba5a6999649b8928b291791b1c91b634340e10d72e28c074e0a34f4
4
+ data.tar.gz: fff5150a880e1735a4ca555a42ad1065d2ebe3dfb6a1562fa6dd070345eaf225
5
5
  SHA512:
6
- metadata.gz: 5079fca78679c717c8596779ff6fe5eb3c53f174471aff0d0445c5ac7a2651a73d3ad185bb530bd3ad7dd74679fa86d6a2011aba9b463a079e326eb67185de85
7
- data.tar.gz: 49fdc92529428e396de87edaebb9b1f9802cb7fc3f4b3d12212707c5c3663c1cbd1f17dc562c13d99cd992c4850382cc4f15698348c3ca11f0b5f7fefcf2cbba
6
+ metadata.gz: d60dbbc2b1a367efbdbaab7158cee8b414b3e2ea7cc5e99b26b0d5c53ffa727b1bbef241bbd88db12ddcc575aa60ab8dbc57263d4460352a6ea2683c49cae890
7
+ data.tar.gz: 9f388ffce6f28c349b016afd90adee8357ea202897978714920b7c2acaf1052885c9a3eec19a8166ec071c7baae3063174ad61ee9a5c148ad0caf8898097a87a
@@ -4,3 +4,11 @@ cache: bundler
4
4
  rvm:
5
5
  - 2.7.1
6
6
  before_install: gem install bundler -v 2.1.4
7
+ before_script:
8
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
9
+ - chmod +x ./cc-test-reporter
10
+ - ./cc-test-reporter before-build
11
+ script:
12
+ - bundle exec rspec
13
+ after_script:
14
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  # Manufacturable
4
4
 
5
+ [![Gem Version](https://badge.fury.io/rb/manufacturable.svg)](https://badge.fury.io/rb/manufacturable) [![Build Status](https://travis-ci.org/first-try-software/manufacturable.svg?branch=main)](https://travis-ci.org/first-try-software/manufacturable) [![Maintainability](https://api.codeclimate.com/v1/badges/ecc365446449c0142b0e/maintainability)](https://codeclimate.com/github/first-try-software/manufacturable/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/ecc365446449c0142b0e/test_coverage)](https://codeclimate.com/github/first-try-software/manufacturable/test_coverage)
6
+
5
7
  Manufacturable is a factory that builds self-registering objects.
6
8
 
7
9
  It leverages self-registration to move factory setup from case statements,
@@ -13,8 +15,8 @@ themselves with the factory does two things. It allows the factory to be
13
15
 
14
16
  ## Motivation
15
17
 
16
- We wrote Manufacturable so we wouldn't have to keep modifying our factory
17
- code every time we needed to add functionanlity to our applications. For
18
+ We wrote Manufacturable, so we wouldn't have to keep modifying our factory
19
+ code every time we needed to add functionality to our applications. For
18
20
  example, consider this factory:
19
21
 
20
22
  ```ruby
@@ -70,7 +72,7 @@ end
70
72
  Extending `Manufacturable::Item` adds the Manufacturable DSL to the class.
71
73
  Calling `corresponds_to` with a key registers that class with the factory.
72
74
 
73
- Once registed, a class may be instantiated like this:
75
+ Once registered, a class may be instantiated like this:
74
76
 
75
77
  ```ruby
76
78
  Manufacturable.build(Object, :four_door, *args)
@@ -238,7 +240,7 @@ Or install it yourself as:
238
240
  $ gem install manufacturable
239
241
 
240
242
  If you are using Manufacturable with Rails, you'll need an initializer to tell
241
- manufacturable where the classes are so they can be autoloaded.
243
+ manufacturable where the classes are, so they can be autoloaded.
242
244
 
243
245
  ```ruby
244
246
  Manufacturable.config do |config|
@@ -278,6 +280,6 @@ opportunity to work on things we're still proud of today.
278
280
  [nop]: https://en.wikipedia.org/wiki/Null_object_pattern
279
281
  [gem]: https://rubygems.org
280
282
  [git]: https://github.com/first-try-software/manufacturable
281
- [cod]: https://github.com/first-try-software/manufacturable/blob/master/CODE_OF_CONDUCT.md
283
+ [cod]: https://github.com/first-try-software/manufacturable/blob/main/CODE_OF_CONDUCT.md
282
284
  [mit]: https://opensource.org/licenses/MIT
283
- [ind]: https://github.com/entelo/industrialist
285
+ [ind]: https://github.com/entelo/industrialist
@@ -6,8 +6,20 @@ require 'manufacturable/object_factory'
6
6
  require 'manufacturable/railtie' if defined?(Rails)
7
7
 
8
8
  module Manufacturable
9
- def self.build(*args)
10
- Builder.build(*args)
9
+ def self.build(*args, **kwargs)
10
+ Builder.build(*args, **kwargs)
11
+ end
12
+
13
+ def self.build_one(*args, **kwargs)
14
+ Builder.build_one(*args, **kwargs)
15
+ end
16
+
17
+ def self.build_many(*args, **kwargs)
18
+ Builder.build_all(*args, **kwargs)
19
+ end
20
+
21
+ def self.build_all(*args, **kwargs)
22
+ Builder.build_all(*args, **kwargs)
11
23
  end
12
24
 
13
25
  def self.registered_types
@@ -18,6 +30,10 @@ module Manufacturable
18
30
  Registrar.registered_keys(type)
19
31
  end
20
32
 
33
+ def self.reset!
34
+ Registrar.reset!
35
+ end
36
+
21
37
  def self.config
22
38
  yield(Config)
23
39
  Config.load_paths
@@ -2,32 +2,56 @@ require 'manufacturable/registrar'
2
2
 
3
3
  module Manufacturable
4
4
  class Builder
5
- def self.build(*args)
6
- self.new(*args).build
5
+ def self.build(*args, **kwargs)
6
+ self.new(*args, **kwargs).build
7
+ end
8
+
9
+ def self.build_one(*args, **kwargs)
10
+ self.new(*args, **kwargs).build_one
11
+ end
12
+
13
+ def self.build_all(*args, **kwargs)
14
+ self.new(*args, **kwargs).build_all
7
15
  end
8
16
 
9
17
  def build
10
18
  return_first? ? instances.first : instances
11
19
  end
12
20
 
21
+ def build_one
22
+ last_instance
23
+ end
24
+
25
+ def build_all
26
+ instances
27
+ end
28
+
13
29
  private
14
30
 
15
- attr_reader :type, :key, :args
31
+ attr_reader :type, :key, :args, :kwargs
32
+
33
+ def initialize(type, key, *args, **kwargs)
34
+ @type, @key, @args, @kwargs = type, key, args, kwargs
35
+ end
16
36
 
17
- def initialize(type, key, *args)
18
- @type, @key, @args = type, key, args
37
+ def return_first?
38
+ instances.size < 2
39
+ end
40
+
41
+ def instances
42
+ @instances ||= klasses.map { |klass| klass&.new(*args, **kwargs) }
19
43
  end
20
44
 
21
45
  def klasses
22
46
  Registrar.get(type, key)
23
47
  end
24
48
 
25
- def instances
26
- @instances ||= klasses.map { |klass| klass&.new(*args) }
49
+ def last_instance
50
+ last_klass&.new(*args, **kwargs)
27
51
  end
28
52
 
29
- def return_first?
30
- instances.size < 2
53
+ def last_klass
54
+ klasses.to_a.last
31
55
  end
32
56
  end
33
57
  end
@@ -11,5 +11,21 @@ module Manufacturable
11
11
 
12
12
  Builder.build(@type, key, *args)
13
13
  end
14
+
15
+ def build_one(key, *args)
16
+ return if @type.nil?
17
+
18
+ Builder.build_one(@type, key, *args)
19
+ end
20
+
21
+ def build_many(key, *args)
22
+ build_all(key, *args)
23
+ end
24
+
25
+ def build_all(key, *args)
26
+ return [] if @type.nil?
27
+
28
+ Builder.build_all(@type, key, *args)
29
+ end
14
30
  end
15
31
  end
@@ -20,6 +20,10 @@ module Manufacturable
20
20
  registry[type].keys
21
21
  end
22
22
 
23
+ def reset!
24
+ registry.clear
25
+ end
26
+
23
27
  private
24
28
 
25
29
  def registry
@@ -1,3 +1,3 @@
1
1
  module Manufacturable
2
- VERSION = "1.0.1"
2
+ VERSION = "1.3.2"
3
3
  end
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
7
7
  spec.email = ["administators@firsttry.software"]
8
8
 
9
9
  spec.summary = %q{Manufacturable is a factory that builds self-registering objects.}
10
- spec.description = %q{Manufacturable leverages self-registration to move factory setup from case statements, hashes, and configuration files to a simple DSL within the instantiable classes themselves. Giving classes the responsibility of registering themselves with the factory does two things. It allows the factory to be extended without modification. And, it leaves the factory with only one responsibility: building objects.}
10
+ spec.description = %q{Manufacturable is a factory that builds self-registering objects. It leverages self-registration to move factory setup from case statements, hashes, and configuration files to a simple DSL within the instantiable classes themselves. Giving classes the responsibility of registering themselves with the factory does two things. It allows the factory to be extended without modification. And, it leaves the factory with only one responsibility: building objects.}
11
11
  spec.homepage = "https://github.com/first-try-software/manufacturable"
12
12
  spec.license = "MIT"
13
13
  spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
@@ -30,5 +30,5 @@ Gem::Specification.new do |spec|
30
30
  spec.add_development_dependency "rake", "~> 12.0"
31
31
  spec.add_development_dependency "rspec", "~> 3.0"
32
32
  spec.add_development_dependency "rspec_junit_formatter", "~>0.4"
33
- spec.add_development_dependency "simplecov", "~>0.16"
33
+ spec.add_development_dependency "simplecov", "~>0.17.0"
34
34
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: manufacturable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.3.2
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: 2020-06-16 00:00:00.000000000 Z
12
+ date: 2020-08-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -73,19 +73,20 @@ dependencies:
73
73
  requirements:
74
74
  - - "~>"
75
75
  - !ruby/object:Gem::Version
76
- version: '0.16'
76
+ version: 0.17.0
77
77
  type: :development
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
81
  - - "~>"
82
82
  - !ruby/object:Gem::Version
83
- version: '0.16'
84
- description: 'Manufacturable leverages self-registration to move factory setup from
85
- case statements, hashes, and configuration files to a simple DSL within the instantiable
86
- classes themselves. Giving classes the responsibility of registering themselves
87
- with the factory does two things. It allows the factory to be extended without modification.
88
- And, it leaves the factory with only one responsibility: building objects.'
83
+ version: 0.17.0
84
+ description: 'Manufacturable is a factory that builds self-registering objects. It
85
+ leverages self-registration to move factory setup from case statements, hashes,
86
+ and configuration files to a simple DSL within the instantiable classes themselves.
87
+ Giving classes the responsibility of registering themselves with the factory does
88
+ two things. It allows the factory to be extended without modification. And, it leaves
89
+ the factory with only one responsibility: building objects.'
89
90
  email:
90
91
  - administators@firsttry.software
91
92
  executables: []