evt-collection 2.3.0.0 → 2.4.0.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: 41b5abd8c9b23084b29c701eaad95f9b175a5b0dfeec6bb7a5298c7f90ef48d9
4
- data.tar.gz: a5978352d642af44dca0c31b96c1a91dd7b44c225381a3be1fbdb99f7c3ffcba
3
+ metadata.gz: 922a2fa4912c4f8a3778994ed975dfc184bb728343159529dc299c3352888f13
4
+ data.tar.gz: d3c07b56ef57547eaf553ff34e28735b73a2188a6d69ccae64994ee8a5c42cb2
5
5
  SHA512:
6
- metadata.gz: 61b55f4b39f901858ee8f623ce105bfebd49093aa9495e39fc1851d096f29b8422d6c730e19d95b8f122f0a0b77d346362cfc79c08ab6b4f0fd86c9d5ef26848
7
- data.tar.gz: 902731c7fa012e623ff11424db7b38de0e97ff09b2fca2d4f979d2a90916cd0e933bb25de3a235a2b6c544799d66c6d5b0c66415aed2aa66fda8cd94e03bf6e2
6
+ metadata.gz: 7a40a6bca7e341f5d29bee4210fe5be181d8c5dac9bdc64e2e3b14936fce0ff86684cfc802e4c7eb5d701b261214085b9daab9f40934140fcf8ee11882a17944
7
+ data.tar.gz: 3c37fcc99ed713c70f7d14051acaebe4c4fa9da7ed63d49554097a0c5e0a5b577b225d32df7dd2ea5eca2c906dbafe60200c4c48b356b5dc4fe6d6d1f8db6a08
data/lib/collection.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'set'
2
2
 
3
- require 'collection/set'
3
+ require 'collection/generic'
4
4
  require 'collection/collection'
5
+ require 'collection/set'
@@ -1,4 +1,44 @@
1
1
  module Collection
2
+ def self.included(cls)
3
+ cls.include Enumerable
4
+ cls.extend Generic
5
+ end
6
+
7
+ attr_reader :type_parameter
8
+
9
+ def initialize(type_parameter)
10
+ @type_parameter = type_parameter
11
+ end
12
+
13
+ def add(val)
14
+ if not val.is_a?(type_parameter)
15
+ raise ArgumentError, "#{val.inspect} must be a #{type_parameter.name}"
16
+ end
17
+
18
+ content.add(val)
19
+
20
+ self
21
+ end
22
+ alias :<< :add
23
+
24
+ def each(&action)
25
+ content.each(&action)
26
+ end
27
+
28
+ def empty?
29
+ content.empty?
30
+ end
31
+
32
+ def clear
33
+ content.clear
34
+ self
35
+ end
36
+
37
+ def ==(other)
38
+ other.class == self.class && other.type_parameter == self.type_parameter && other.content == self.content
39
+ end
40
+ alias :eql? :==
41
+
2
42
  def self.Set(items)
3
43
  items = Array(items)
4
44
 
@@ -0,0 +1,45 @@
1
+ module Collection
2
+ module Generic
3
+ def [](type_parameter)
4
+ type_parameter_name = constant_name(type_parameter)
5
+
6
+ cls = nil
7
+ unless self.const_defined?(type_parameter_name, false)
8
+ cls = define_class(type_parameter)
9
+ set_collection_constant(type_parameter, cls)
10
+ else
11
+ cls = const_get(type_parameter_name)
12
+ end
13
+
14
+ cls
15
+ end
16
+
17
+ def define_class(type_parameter)
18
+ cls = Class.new(self) do
19
+ def initialize; end
20
+
21
+ define_method :type_parameter do
22
+ type_parameter
23
+ end
24
+ end
25
+
26
+ set_collection_constant(type_parameter, cls)
27
+
28
+ cls
29
+ end
30
+
31
+ def constant_name(constant)
32
+ constant.name.gsub('::', '_')
33
+ end
34
+
35
+ def set_collection_constant(constant, cls)
36
+ class_name = constant_name(constant)
37
+
38
+ unless self.const_defined?(class_name, false)
39
+ self.const_set(class_name, cls)
40
+ end
41
+
42
+ class_name
43
+ end
44
+ end
45
+ end
@@ -1,110 +1,6 @@
1
1
  module Collection
2
2
  class Set
3
- include Enumerable
4
-
5
- attr_reader :type_parameter
6
-
7
- def initialize(type_parameter)
8
- @type_parameter = type_parameter
9
- end
10
-
11
- def self.[](type_parameter)
12
- type_parameter_name = constant_name(type_parameter)
13
-
14
- cls = nil
15
- unless self.const_defined?(type_parameter_name, false)
16
- cls = define_class(type_parameter)
17
- set_collection_constant(type_parameter, cls)
18
- else
19
- cls = const_get(type_parameter_name)
20
- end
21
-
22
- cls
23
- end
24
-
25
- def self.define_class(type_parameter)
26
- cls = Class.new(self) do
27
- def initialize; end
28
-
29
- define_method :type_parameter do
30
- type_parameter
31
- end
32
- end
33
-
34
- set_collection_constant(type_parameter, cls)
35
-
36
- cls
37
- end
38
-
39
- def self.constant_name(constant)
40
- constant.name.gsub('::', '_')
41
- end
42
-
43
- def self.set_collection_constant(constant, cls)
44
- class_name = constant_name(constant)
45
-
46
- unless self.const_defined?(class_name, false)
47
- self.const_set(class_name, cls)
48
- end
49
-
50
- class_name
51
- end
52
-
53
- def ==(other)
54
- other.class == self.class && other.type_parameter == self.type_parameter && other.content == self.content
55
- end
56
- alias :eql? :==
57
-
58
- def add(val)
59
- vals = Array(val)
60
-
61
- vals.each do |val|
62
- raise ArgumentError, "#{val.inspect} must be a #{type_parameter.name}" unless val.is_a? type_parameter
63
- content.add(val)
64
- end
65
-
66
- self
67
- end
68
- alias :<< :add
69
-
70
- def entry?(val=nil, &predicate)
71
- if !block_given?
72
- predicate = lambda { |m| m == val }
73
- end
74
-
75
- entries(&predicate).length > 0
76
- end
77
-
78
- def entries(&predicate)
79
- content.select(&predicate)
80
- end
81
-
82
- def entry(&predicate)
83
- content.find(&predicate)
84
- end
85
-
86
- def each(&action)
87
- content.each(&action)
88
- end
89
-
90
- def entries?
91
- !content.empty?
92
- end
93
-
94
- def empty?
95
- content.empty?
96
- end
97
-
98
- def length
99
- content.length
100
- end
101
- alias :size :length
102
-
103
- def clear
104
- content.clear
105
-
106
- self
107
- end
3
+ include Collection
108
4
 
109
5
  def content
110
6
  @content ||= ::Set.new
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.3.0.0
4
+ version: 2.4.0.0
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: 2021-03-12 00:00:00.000000000 Z
11
+ date: 2021-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test_bench
@@ -35,6 +35,7 @@ files:
35
35
  - lib/collection/controls.rb
36
36
  - lib/collection/controls/array.rb
37
37
  - lib/collection/controls/member.rb
38
+ - lib/collection/generic.rb
38
39
  - lib/collection/set.rb
39
40
  homepage: https://github.com/eventide-project/collection
40
41
  licenses: