manufacturable 1.4.0 → 1.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 89a955dbe25bfe0a0409045c03e9349d06c4ce710b6cb3a2bf0cbe95ea2c088b
4
- data.tar.gz: efbc6e1f0f512d7306d1b343bd2ff957728ac72e3abddf54b8e6efe0d3446451
3
+ metadata.gz: ed7ea8785e7afdcc33f4071742a85a6e4074b64cb54a19274df867a6ac6cff8f
4
+ data.tar.gz: a3d15704c9600dfa8f7565c4f8eb43979b3e97d945c91dcbaf4e29fe0794a6e1
5
5
  SHA512:
6
- metadata.gz: 3fd2846ae381bea9934e498c15e202e1d6b72e17bbdbea22d2742a214772edbaa71c02e1f2364dd5e2c88d06e5a7017ce734dde10676a1297206d2a7310378dc
7
- data.tar.gz: e909d7f0234635b01fec866a020e61b5815276024aad25b0a22e96dfbb1dfe7bb80c89d68ce44ff400b61d525bf8fe640a894d535d373166b5ae102902420ffd
6
+ metadata.gz: d93e23562e81927917d9313b18c9a0ae0678716b4d718d62d8ada471e539e32f1ae5705c2ac33cc7bbc5f82f32a7fb4120ed314d0f11c06600653be825e63a9e
7
+ data.tar.gz: 9038acc6b59bbf7792bdae8a556753fb42c3f4f65f7ce17e565952585bed3f99ac8a25cea20c558c867e8e9f957a7e3c4e73eafefaafe634fd37a993ec7b6dc0
@@ -2,16 +2,16 @@ require 'manufacturable/registrar'
2
2
 
3
3
  module Manufacturable
4
4
  class Builder
5
- def self.build(*args, **kwargs)
6
- self.new(*args, **kwargs).build
5
+ def self.build(*args, **kwargs, &block)
6
+ self.new(*args, **kwargs, &block).build
7
7
  end
8
8
 
9
- def self.build_one(*args, **kwargs)
10
- self.new(*args, **kwargs).build_one
9
+ def self.build_one(*args, **kwargs, &block)
10
+ self.new(*args, **kwargs, &block).build_one
11
11
  end
12
12
 
13
- def self.build_all(*args, **kwargs)
14
- self.new(*args, **kwargs).build_all
13
+ def self.build_all(*args, **kwargs, &block)
14
+ self.new(*args, **kwargs, &block).build_all
15
15
  end
16
16
 
17
17
  def build
@@ -28,10 +28,11 @@ module Manufacturable
28
28
 
29
29
  private
30
30
 
31
- attr_reader :type, :key, :args, :kwargs
31
+ attr_reader :type, :key, :args, :kwargs, :block
32
32
 
33
- def initialize(type, key, *args, **kwargs)
34
- @type, @key, @args, @kwargs = type, key, args, kwargs
33
+ def initialize(*args, **kwargs, &block)
34
+ @type, @key, *@args = args
35
+ @kwargs, @block = kwargs, block
35
36
  end
36
37
 
37
38
  def return_first?
@@ -39,15 +40,17 @@ module Manufacturable
39
40
  end
40
41
 
41
42
  def instances
42
- @instances ||= klasses.map { |klass| klass&.new(*args, **kwargs_with_key) }
43
+ @instances ||= klasses.map do |klass|
44
+ klass.new(*args, **kwargs_with_key).tap { |instance| block&.call(instance) }
45
+ end
43
46
  end
44
47
 
45
- def klasses
46
- Registrar.get(type, key)
48
+ def last_instance
49
+ last_klass&.new(*args, **kwargs_with_key)&.tap { |instance| block&.call(instance) }
47
50
  end
48
51
 
49
- def last_instance
50
- last_klass&.new(*args, **kwargs_with_key)
52
+ def klasses
53
+ Registrar.get(type, key).to_a
51
54
  end
52
55
 
53
56
  def kwargs_with_key
@@ -55,7 +58,7 @@ module Manufacturable
55
58
  end
56
59
 
57
60
  def last_klass
58
- klasses.to_a.last
61
+ klasses.last
59
62
  end
60
63
  end
61
64
  end
@@ -2,32 +2,32 @@ require 'manufacturable/registrar'
2
2
 
3
3
  module Manufacturable
4
4
  module Item
5
- def self.extended(base)
6
- base.instance_eval do
7
- def corresponds_to(key, type = self.superclass)
8
- key = key == type ? Registrar::ALL_KEY : key
9
- Registrar.register(type, key, self)
10
- end
5
+ def new(*args, **kwargs, &block)
6
+ key = kwargs.delete(:manufacturable_item_key)
7
+ instance = kwargs.empty? ? super(*args, &block) : super
8
+ instance.instance_variable_set(:@manufacturable_item_key, key)
9
+ instance
10
+ end
11
+
12
+ def corresponds_to(key, type = self.superclass)
13
+ key = key == type ? Registrar::ALL_KEY : key
14
+ Registrar.register(type, key, self)
15
+ end
11
16
 
12
- def corresponds_to_all(type = self.superclass)
13
- corresponds_to(Registrar::ALL_KEY, type)
14
- end
17
+ def corresponds_to_all(type = self.superclass)
18
+ corresponds_to(Registrar::ALL_KEY, type)
19
+ end
15
20
 
16
- def default_manufacturable(type = self.superclass)
17
- corresponds_to(Registrar::DEFAULT_KEY, type)
18
- end
21
+ def default_manufacturable(type = self.superclass)
22
+ corresponds_to(Registrar::DEFAULT_KEY, type)
23
+ end
19
24
 
20
- def new(*args, **kwargs, &block)
21
- key = kwargs.delete(:manufacturable_item_key)
22
- instance = kwargs.empty? ? super(*args, &block) : super
23
- instance.instance_variable_set(:@manufacturable_item_key, key)
24
- instance
25
- end
26
- end
25
+ def self.extended(base)
26
+ base.include(InstanceMethods)
27
+ end
27
28
 
28
- base.class_eval do
29
- attr_reader :manufacturable_item_key
30
- end
29
+ module InstanceMethods
30
+ attr_reader :manufacturable_item_key
31
31
  end
32
32
  end
33
33
  end
@@ -1,9 +1,21 @@
1
1
  require 'manufacturable/config'
2
2
 
3
3
  module Manufacturable
4
- class Railtie < Rails::Railtie
5
- initializer "manufacturable.require_paths" do |app|
6
- Manufacturable::Config.require_method = app.config.eager_load ? :require : :require_dependency
4
+ class Railtie
5
+ def self.load
6
+ load_railtie if rails_defined?
7
+ end
8
+
9
+ def self.load_railtie
10
+ Class.new(Rails::Railtie).initializer('manufacturable.require_paths') do |app|
11
+ Manufacturable::Config.require_method = app.config.eager_load ? :require : :require_dependency
12
+ end
13
+ end
14
+
15
+ def self.rails_defined?
16
+ defined?(Rails)
7
17
  end
8
18
  end
9
19
  end
20
+
21
+ Manufacturable::Railtie.load
@@ -1,3 +1,5 @@
1
+ require 'set'
2
+
1
3
  module Manufacturable
2
4
  class Registrar
3
5
  ALL_KEY = :__all__
@@ -1,3 +1,3 @@
1
1
  module Manufacturable
2
- VERSION = "1.4.0"
2
+ VERSION = "1.5.1"
3
3
  end
@@ -3,23 +3,23 @@ require 'manufacturable/config'
3
3
  require 'manufacturable/factory'
4
4
  require 'manufacturable/item'
5
5
  require 'manufacturable/object_factory'
6
- require 'manufacturable/railtie' if defined?(Rails)
6
+ require 'manufacturable/railtie'
7
7
 
8
8
  module Manufacturable
9
- def self.build(*args, **kwargs)
10
- Builder.build(*args, **kwargs)
9
+ def self.build(*args, **kwargs, &block)
10
+ Builder.build(*args, **kwargs, &block)
11
11
  end
12
12
 
13
- def self.build_one(*args, **kwargs)
14
- Builder.build_one(*args, **kwargs)
13
+ def self.build_one(*args, **kwargs, &block)
14
+ Builder.build_one(*args, **kwargs, &block)
15
15
  end
16
16
 
17
- def self.build_many(*args, **kwargs)
18
- Builder.build_all(*args, **kwargs)
17
+ def self.build_many(*args, **kwargs, &block)
18
+ Builder.build_all(*args, **kwargs, &block)
19
19
  end
20
20
 
21
- def self.build_all(*args, **kwargs)
22
- Builder.build_all(*args, **kwargs)
21
+ def self.build_all(*args, **kwargs, &block)
22
+ Builder.build_all(*args, **kwargs, &block)
23
23
  end
24
24
 
25
25
  def self.registered_types
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  }
20
20
 
21
21
  spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|assets)/}) }
23
23
  end
24
24
 
25
25
  spec.bindir = "exe"
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: manufacturable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alan Ridlehoover
8
8
  - Fito von Zastrow
9
- autorequire:
9
+ autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2020-09-10 00:00:00.000000000 Z
12
+ date: 2021-09-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -101,7 +101,6 @@ files:
101
101
  - LICENSE.txt
102
102
  - README.md
103
103
  - Rakefile
104
- - assets/factory.png
105
104
  - bin/console
106
105
  - bin/setup
107
106
  - lib/manufacturable.rb
@@ -121,7 +120,7 @@ metadata:
121
120
  bug_tracker_uri: https://github.com/first-try-software/manufacturable/issues
122
121
  homepage_uri: https://github.com/first-try-software/manufacturable
123
122
  source_code_uri: https://github.com/first-try-software/manufacturable
124
- post_install_message:
123
+ post_install_message:
125
124
  rdoc_options: []
126
125
  require_paths:
127
126
  - lib
@@ -136,8 +135,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
135
  - !ruby/object:Gem::Version
137
136
  version: '0'
138
137
  requirements: []
139
- rubygems_version: 3.1.2
140
- signing_key:
138
+ rubygems_version: 3.2.15
139
+ signing_key:
141
140
  specification_version: 4
142
141
  summary: Manufacturable is a factory that builds self-registering objects.
143
142
  test_files: []
data/assets/factory.png DELETED
Binary file