template_class 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +26 -0
- data/lib/template_class/bulk_instantiable.rb +21 -0
- data/lib/template_class/version.rb +1 -1
- data/lib/template_class.rb +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4c0985a84c4d73b07449fea319cd108c0a78477fa0975a0a946dcb82d05dbda
|
4
|
+
data.tar.gz: 35cc326a7341985c9d3a416fcad8b58a9465f4e72a083d7c4e9d153ed4f312d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1cc67fea8a072fd2fcf64a7bb7b17d22ae801b1547dd92cccd27a0e6f4c939870b032112bf845dc0974d8860d797f4e12c104f19437be369de70e8d0009ff21a
|
7
|
+
data.tar.gz: f756b227610d4503557b949dde1ed5f908fac9da1f3353a7dd55a7772f84e145eb419a1fad568f0a497d08d772a29a340b20fc839910ceee92baeedda9cc8065
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -82,6 +82,32 @@ List[:any] = Array
|
|
82
82
|
|
83
83
|
Notice that the parameter isn't constrained to classes: you can use any object.
|
84
84
|
|
85
|
+
### Bulk Instantiation
|
86
|
+
|
87
|
+
A module (or class) containing multiple templates can include `TemplateClass::BulkInstanceable` to be able to instantiate them in bulk using the same parameter.
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
module Templates
|
91
|
+
include TemplateClass::BulkInstantiable
|
92
|
+
|
93
|
+
class Template1
|
94
|
+
...
|
95
|
+
end
|
96
|
+
|
97
|
+
class Template2
|
98
|
+
...
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
module Instances
|
103
|
+
Templates.bulk_instance Integer, into: self
|
104
|
+
end
|
105
|
+
```
|
106
|
+
|
107
|
+
The new constants `Instances::Template1` and `Instances::Template2` are now defined, and they point respectively to `Templates::Template1[Integer]` and `Templates::Template2[Integer]`.
|
108
|
+
|
109
|
+
The optional keyword argument `with_overrides`, which defaults to `true` if `Zeitwerk` is defined and to `false` otherwise, allows you to automatically access and reopen the instances in files that follow the Zeitwerk naming conventions (eg. you can reopen `Instances::Template1` in the file `instances/template1.rb`). If `with_overrides` is `false`, you can still reopen the instances, but you need to manually handle the appropriate `requires` in the appropriate order.
|
110
|
+
|
85
111
|
## Plans for future development
|
86
112
|
|
87
113
|
- Multiple specialization parameters
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module TemplateClass
|
2
|
+
module BulkInstantiable
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
class_methods do
|
6
|
+
def bulk_instantiate(*args, into:, with_overrides: defined?(Zeitwerk))
|
7
|
+
constants(false)
|
8
|
+
.map { |constant_name| const_get(constant_name) }
|
9
|
+
.map do |constant|
|
10
|
+
into.const_set constant.name.demodulize.to_sym, constant[*args]
|
11
|
+
end
|
12
|
+
.tap { return unless with_overrides } # rubocop:disable Lint/NonLocalExitFromIterator
|
13
|
+
.each do |instance|
|
14
|
+
require instance.name.underscore
|
15
|
+
rescue LoadError
|
16
|
+
nil
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/template_class.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: template_class
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Moku S.r.l.
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2024-08-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -47,6 +47,7 @@ files:
|
|
47
47
|
- README.md
|
48
48
|
- Rakefile
|
49
49
|
- lib/template_class.rb
|
50
|
+
- lib/template_class/bulk_instantiable.rb
|
50
51
|
- lib/template_class/template.rb
|
51
52
|
- lib/template_class/version.rb
|
52
53
|
- sig/lib/template_class/template.rbs
|
@@ -72,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
73
|
- !ruby/object:Gem::Version
|
73
74
|
version: '0'
|
74
75
|
requirements: []
|
75
|
-
rubygems_version: 3.
|
76
|
+
rubygems_version: 3.5.11
|
76
77
|
signing_key:
|
77
78
|
specification_version: 4
|
78
79
|
summary: A way to define templated classes, in a similar fashion to C++ templates.
|