valued 0.2.1 → 0.3.0
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/CHANGELOG.md +6 -0
- data/Gemfile.lock +1 -1
- data/README.md +12 -1
- data/lib/valued.rb +8 -0
- data/lib/valued/mutable.rb +8 -0
- data/lib/valued/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52725a53667c02e8762fbf0494b52f7641fc5d8228eddc83ceb8e8b6899b4ed7
|
4
|
+
data.tar.gz: f997ebbf9cf7c114cf2db237f3b8042d585d50ae210426ee8c7f78cc42f204c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d31a8cd00da586bd1b1708fffe04b6319a0892127da935f91bbba38043356611ac482ad25eb921a595a6d7ebedbf841a1cb10f4784762ebc77aa2d1ac79d797
|
7
|
+
data.tar.gz: dc370f42d41c9d7df0a655d0ab591aabeac612221d98162bbf491eb68a582a217f4d634aea2111e95448c573768b15cc5a6c322f419ed31de57305feba524dec
|
data/CHANGELOG.md
ADDED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -82,7 +82,18 @@ p quantity
|
|
82
82
|
=> #<Quantity amount=2 unit="m">
|
83
83
|
```
|
84
84
|
|
85
|
-
|
85
|
+
You can create a duplicate of your object with updated attributes by using `update`.
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
quantity = Quantity.new(unit: 'm', amount: 2)
|
89
|
+
p quantity
|
90
|
+
=> #<Quantity amount=2 unit="m">
|
91
|
+
updated_quantity = quantity.update(unit: 'yard')
|
92
|
+
p updated_quantity
|
93
|
+
=> #<Quantity amount=2 unit="yard">
|
94
|
+
```
|
95
|
+
|
96
|
+
If you really need a mutable object, just use `Valued::Mutable` instead of `Valued`.
|
86
97
|
|
87
98
|
```ruby
|
88
99
|
require 'valued'
|
data/lib/valued.rb
CHANGED
@@ -56,6 +56,14 @@ module Valued
|
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
+
def update(new_attributes)
|
60
|
+
self.class.new(
|
61
|
+
_attributes.each_with_object({}) do |attribute, result|
|
62
|
+
result[attribute] = new_attributes[attribute] || self.send(attribute)
|
63
|
+
end
|
64
|
+
)
|
65
|
+
end
|
66
|
+
|
59
67
|
def ==(other)
|
60
68
|
_attributes.all? do |attribute|
|
61
69
|
other.respond_to?(attribute) && send(attribute) == other.send(attribute)
|
data/lib/valued/mutable.rb
CHANGED
@@ -57,6 +57,14 @@ module Valued
|
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
+
def update(new_attributes)
|
61
|
+
self.class.new(
|
62
|
+
_attributes.each_with_object({}) do |attribute, result|
|
63
|
+
result[attribute] = new_attributes[attribute] || self.send(attribute)
|
64
|
+
end
|
65
|
+
)
|
66
|
+
end
|
67
|
+
|
60
68
|
def ==(other)
|
61
69
|
_attributes.all? do |attribute|
|
62
70
|
other.respond_to?(attribute) && send(attribute) == other.send(attribute)
|
data/lib/valued/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: valued
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mario Mainz
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-04-
|
11
|
+
date: 2020-04-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -91,6 +91,7 @@ files:
|
|
91
91
|
- ".rspec"
|
92
92
|
- ".rubocop.yml"
|
93
93
|
- ".travis.yml"
|
94
|
+
- CHANGELOG.md
|
94
95
|
- Gemfile
|
95
96
|
- Gemfile.lock
|
96
97
|
- LICENSE.txt
|