evt-collection 2.4.4.1 → 2.4.4.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: 1382787f77f9cf877782c6d299d737df126dac69ed3d793001d10001e1a0bd75
4
- data.tar.gz: b491cf4e131f9bd9645fc6d39ca76979e116847c5e1dba08a2f083d3beb693f4
3
+ metadata.gz: c3c0236190e801658ae9b8caa4a44afecfd165c210d217babfa19fb7a5c6e5bb
4
+ data.tar.gz: 802cdca0655f52a893d0dda1b7f104b1e033f8d7995a31da2476a4670a417caa
5
5
  SHA512:
6
- metadata.gz: 34cffee6f74c1f7cc3bfa17a4bd251f7ccd9629af5d541b7810fd510b7440f9a3e8fc26181dd0706ba87a1df7903cc992454af180cb328c35ca9af32fa568923
7
- data.tar.gz: 67148c48ec1ee9e771bbb225c9ae67eaf0ad441df61695ad57fea8abd65f6403778fe0267276f3fdeffb0f1ff0c65a209d1c49a759cfc05ea98f68adf8144c81
6
+ metadata.gz: b1e114ebb8e32ca1a94ecbec0784df572e6a06bcf19bfd7cc04cd57e6efa6e4d421dbb41d48c763a9355f721a57dfd23cea8ffc8540b703ee715026a4787f001
7
+ data.tar.gz: 55e475ec4fda87a9c239e3dce4b47bd77a88b3cb39a8208378c9d1b8538ce949a5e604877ea09b96290eb916a1ec980870c2f113779ec95684926027200125a0
@@ -6,27 +6,26 @@ module Collection
6
6
  end
7
7
 
8
8
  def self.member_class
9
- Member::Class.example
9
+ Class.example
10
10
  end
11
11
 
12
12
  module RandomMemberClass
13
- def self.example
14
- cls = member_class
15
- [cls.new, cls.new]
16
- end
13
+ def self.example(homogeneous_classes: nil)
14
+ homogeneous_classes ||= false
17
15
 
18
- def self.member_class
19
- Member::Class.random
20
- end
21
- end
16
+ if homogeneous_classes
17
+ cls_1 = member_class
18
+ cls_2 = cls_1
19
+ else
20
+ cls_1 = member_class
21
+ cls_2 = member_class
22
+ end
22
23
 
23
- module Anomaly
24
- def self.example
25
- [member_class.new, member_class.new]
24
+ [cls_1.new, cls_2.new]
26
25
  end
27
26
 
28
27
  def self.member_class
29
- Member::Class.random
28
+ Class::Random.example
30
29
  end
31
30
  end
32
31
  end
@@ -0,0 +1,37 @@
1
+ module Collection
2
+ module Controls
3
+ module Class
4
+ def self.example
5
+ Example
6
+ end
7
+
8
+ Example = ::Class.new
9
+
10
+ module Random
11
+ def self.example(root: nil)
12
+ root ||= false
13
+
14
+ class_name = "Class#{SecureRandom.hex(2).upcase}"
15
+
16
+ namespace = namespace(root)
17
+
18
+ namespace.const_set(class_name, ::Class.new)
19
+ end
20
+
21
+ def self.namespace(root)
22
+ if root
23
+ Object
24
+ else
25
+ Collection::Controls::Class
26
+ end
27
+ end
28
+ end
29
+
30
+ module Root
31
+ def self.example
32
+ Random.example(root: true)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,2 +1,2 @@
1
- require 'collection/controls/member'
1
+ require 'collection/controls/class'
2
2
  require 'collection/controls/array'
@@ -3,15 +3,11 @@ module Collection
3
3
  def [](type_parameter, &implementation)
4
4
  type_parameter_name = constant_name(type_parameter)
5
5
 
6
- cls = nil
7
- unless self.const_defined?(type_parameter_name, false)
8
- cls = define_class(type_parameter, &implementation)
9
- set_collection_constant(type_parameter, cls)
6
+ if implementation.nil? && self.const_defined?(type_parameter_name, false)
7
+ return const_get(type_parameter_name)
10
8
  else
11
- cls = const_get(type_parameter_name)
9
+ return define_class(type_parameter, &implementation)
12
10
  end
13
-
14
- cls
15
11
  end
16
12
 
17
13
  def define_class(type_parameter, &implementation)
@@ -37,23 +33,29 @@ module Collection
37
33
  cls.class_exec(&implementation)
38
34
  end
39
35
 
40
- set_collection_constant(type_parameter, cls)
36
+ randomize = !implementation.nil?
37
+ set_collection_constant(type_parameter, cls, randomize)
41
38
 
42
39
  cls
43
40
  end
44
41
 
45
- def constant_name(constant)
46
- constant.name.gsub('::', '_')
47
- end
42
+ def set_collection_constant(constant, cls, randomize=nil)
43
+ randomize ||= false
48
44
 
49
- def set_collection_constant(constant, cls)
50
- class_name = constant_name(constant)
45
+ constant_name = constant_name(constant)
51
46
 
52
- unless self.const_defined?(class_name, false)
53
- self.const_set(class_name, cls)
47
+ if randomize
48
+ suffix = SecureRandom.hex.upcase
49
+ constant_name = "#{constant_name}_#{suffix}"
54
50
  end
55
51
 
56
- class_name
52
+ self.const_set(constant_name, cls)
53
+
54
+ constant_name
55
+ end
56
+
57
+ def constant_name(constant)
58
+ constant.name.gsub('::', '_')
57
59
  end
58
60
  end
59
61
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evt-collection
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.4.1
4
+ version: 2.4.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - The Eventide Project
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-24 00:00:00.000000000 Z
11
+ date: 2024-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test_bench
@@ -35,7 +35,7 @@ files:
35
35
  - lib/collection/collection.rb
36
36
  - lib/collection/controls.rb
37
37
  - lib/collection/controls/array.rb
38
- - lib/collection/controls/member.rb
38
+ - lib/collection/controls/class.rb
39
39
  - lib/collection/generic.rb
40
40
  - lib/collection/set.rb
41
41
  homepage: https://github.com/eventide-project/collection
@@ -57,7 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
57
57
  - !ruby/object:Gem::Version
58
58
  version: '0'
59
59
  requirements: []
60
- rubygems_version: 3.4.6
60
+ rubygems_version: 3.5.3
61
61
  signing_key:
62
62
  specification_version: 4
63
63
  summary: Type-checked set and array
@@ -1,29 +0,0 @@
1
- module Collection
2
- module Controls
3
- module Member
4
- def self.example
5
- Class.example.new
6
- end
7
-
8
- module Root
9
- def self.example
10
- Class.random
11
- end
12
- end
13
-
14
- module Class
15
- def self.example
16
- Member
17
- end
18
-
19
- def self.random
20
- class_name = "Class#{SecureRandom.hex(2).upcase}"
21
- Object.const_set(class_name, ::Class.new)
22
- end
23
-
24
- class Member
25
- end
26
- end
27
- end
28
- end
29
- end