mimi-core 1.1.0 → 1.1.1

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
  SHA1:
3
- metadata.gz: db5931bbbdf22818f96d2979dac52cbc4d4058ed
4
- data.tar.gz: d8b666e59ec1d340233f7b9a95ca7624dc06b22d
3
+ metadata.gz: ed8ff7ca98a2f001f02b9b081222c923663685c4
4
+ data.tar.gz: fbbedb5ad2985c5d7343c68e6c4fba2aa2c2ab9f
5
5
  SHA512:
6
- metadata.gz: bbc4fe8b0d0150fc7181d050de3c037885f90a85c12a4fa55d6e00339151a7adf93506f44026533f91ab6a9f90132a79b72ae463bd5fbe696df8ae17c6a66aad
7
- data.tar.gz: 0b5e725a4844406bf1cefbd98c1e7f3bee2a358195c4041dcb0f8cf4e00b5059905845d22ef08543e663725b84e045d643d648656c78fbb0ab0e46dda4eaf040
6
+ metadata.gz: 64dbbc6a90c4434e2a0ec1fb7c364b31eb454aa349436e7808ffbf370c77bfd044da206ef8112489eaf26abe192b1c96bf3eb7473f20f019a10fd163983fd0fa
7
+ data.tar.gz: 3f975d0834276f2bfae3de685bd5a2987e32fbbac8df9bbb1edb0992043576125a616c2dcd1097e198fa9557ce9be544292bd3eb7934d7106eae135516f744ad
@@ -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
- @attributes = attrs.map { |k, v| [k.to_sym, v.dup] }.to_h
29
- @attributes.keys.each do |attr_name|
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
@@ -1,5 +1,5 @@
1
1
  module Mimi
2
2
  module Core
3
- VERSION = '1.1.0'.freeze
3
+ VERSION = '1.1.1'.freeze
4
4
  end
5
5
  end
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.0
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-28 00:00:00.000000000 Z
11
+ date: 2019-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler