mimi-core 1.1.0 → 1.1.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 +4 -4
- data/lib/mimi/core/struct.rb +38 -4
- data/lib/mimi/core/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed8ff7ca98a2f001f02b9b081222c923663685c4
|
4
|
+
data.tar.gz: fbbedb5ad2985c5d7343c68e6c4fba2aa2c2ab9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64dbbc6a90c4434e2a0ec1fb7c364b31eb454aa349436e7808ffbf370c77bfd044da206ef8112489eaf26abe192b1c96bf3eb7473f20f019a10fd163983fd0fa
|
7
|
+
data.tar.gz: 3f975d0834276f2bfae3de685bd5a2987e32fbbac8df9bbb1edb0992043576125a616c2dcd1097e198fa9557ce9be544292bd3eb7934d7106eae135516f744ad
|
data/lib/mimi/core/struct.rb
CHANGED
@@ -25,10 +25,8 @@ module Mimi
|
|
25
25
|
#
|
26
26
|
def initialize(attrs = {})
|
27
27
|
raise ArgumentError, "Hash is expected as attrs" unless attrs.is_a?(Hash)
|
28
|
-
|
29
|
-
|
30
|
-
define_singleton_method(attr_name) { self[attr_name] }
|
31
|
-
end
|
28
|
+
attributes = attrs.map { |k, v| [k.to_sym, v.dup] }.to_h
|
29
|
+
initialize_attributes(attributes)
|
32
30
|
end
|
33
31
|
|
34
32
|
# Fetches attribute by its name
|
@@ -51,6 +49,42 @@ module Mimi
|
|
51
49
|
def to_h
|
52
50
|
@attributes
|
53
51
|
end
|
52
|
+
|
53
|
+
# Compares two Structs, comparing only their attribute values
|
54
|
+
#
|
55
|
+
# @param other [Hash,Mimi::Core::Struct]
|
56
|
+
# @return [true,false]
|
57
|
+
#
|
58
|
+
def ==(other)
|
59
|
+
if !other.is_a?(Mimi::Core::Struct) && !other.is_a?(Hash)
|
60
|
+
raise TypeError, "Cannot compare Mimi::Core::Struct and #{other.class}"
|
61
|
+
end
|
62
|
+
other_as_hash = other.is_a?(Hash) ? other : other.to_h
|
63
|
+
self.to_h == other_as_hash
|
64
|
+
end
|
65
|
+
|
66
|
+
# Returns a new copy of a Mimi::Core::Struct object, deep copying its attributes
|
67
|
+
#
|
68
|
+
# @return [Mimi::Core::Struct]
|
69
|
+
#
|
70
|
+
def dup
|
71
|
+
new_object = super
|
72
|
+
new_object.send :initialize_attributes, @attributes
|
73
|
+
new_object
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
# Initializes attributes, defining access methods
|
79
|
+
#
|
80
|
+
# @param attributes [Hash]
|
81
|
+
#
|
82
|
+
def initialize_attributes(attributes)
|
83
|
+
@attributes = attributes
|
84
|
+
@attributes.keys.each do |attr_name|
|
85
|
+
define_singleton_method(attr_name) { self[attr_name] }
|
86
|
+
end
|
87
|
+
end
|
54
88
|
end # class Struct
|
55
89
|
end # module Core
|
56
90
|
end # module Mimi
|
data/lib/mimi/core/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mimi-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Kukushkin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-06-
|
11
|
+
date: 2019-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|