manufacturable 1.0.1 → 1.1.0

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: 856e222a76811ce7b2364c48ed3d745781286a420e33ae3ea76916970b66b110
4
+ data.tar.gz: ebd0b6cdd375008078807c398835e31cb4b68a31eedd491665d7cae486431995
5
5
  SHA512:
6
- metadata.gz: 5079fca78679c717c8596779ff6fe5eb3c53f174471aff0d0445c5ac7a2651a73d3ad185bb530bd3ad7dd74679fa86d6a2011aba9b463a079e326eb67185de85
7
- data.tar.gz: 49fdc92529428e396de87edaebb9b1f9802cb7fc3f4b3d12212707c5c3663c1cbd1f17dc562c13d99cd992c4850382cc4f15698348c3ca11f0b5f7fefcf2cbba
6
+ metadata.gz: 663381ef9ab7abad64a7863cf15ba7a4e5f028cb01c0cb758ee91ce6e326cd7654135956e0750f6f84e785ab161db84f701649553b4b59e7247d529ccca695eb
7
+ data.tar.gz: 68c778221748374c79facccdf02ab609918c5f0fd0d39035fb7ca57ef389c4eaa22394d6f1d718d4884e8ea91916a293c27aac97a5c05c2d3b7fca6e368ff0e0
@@ -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|
@@ -10,6 +10,14 @@ module Manufacturable
10
10
  Builder.build(*args)
11
11
  end
12
12
 
13
+ def self.build_one(*args)
14
+ Builder.build_one(*args)
15
+ end
16
+
17
+ def self.build_many(*args)
18
+ Builder.build_many(*args)
19
+ end
20
+
13
21
  def self.registered_types
14
22
  Registrar.registered_types
15
23
  end
@@ -6,10 +6,26 @@ module Manufacturable
6
6
  self.new(*args).build
7
7
  end
8
8
 
9
+ def self.build_one(*args)
10
+ self.new(*args).build_one
11
+ end
12
+
13
+ def self.build_many(*args)
14
+ self.new(*args).build_many
15
+ end
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_many
26
+ instances
27
+ end
28
+
13
29
  private
14
30
 
15
31
  attr_reader :type, :key, :args
@@ -18,16 +34,24 @@ module Manufacturable
18
34
  @type, @key, @args = type, key, args
19
35
  end
20
36
 
21
- def klasses
22
- Registrar.get(type, key)
37
+ def return_first?
38
+ instances.size < 2
23
39
  end
24
40
 
25
41
  def instances
26
42
  @instances ||= klasses.map { |klass| klass&.new(*args) }
27
43
  end
28
44
 
29
- def return_first?
30
- instances.size < 2
45
+ def klasses
46
+ Registrar.get(type, key)
47
+ end
48
+
49
+ def last_instance
50
+ last_klass&.new(*args)
51
+ end
52
+
53
+ def last_klass
54
+ klasses.to_a.last
31
55
  end
32
56
  end
33
57
  end
@@ -11,5 +11,17 @@ 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
+ return [] if @type.nil?
23
+
24
+ Builder.build_many(@type, key, *args)
25
+ end
14
26
  end
15
27
  end
@@ -1,3 +1,3 @@
1
1
  module Manufacturable
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.0"
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.1.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: 2020-06-16 00:00:00.000000000 Z
12
+ date: 2020-06-19 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: []