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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b6896d2f520dec61ad2c41b8b03ec227410480d26629fa030ed116f854deb10c
4
- data.tar.gz: b22366e310251383cb1ebbb50ff6f39b49a6e479ef61820d8dae78b6375d7812
3
+ metadata.gz: 52725a53667c02e8762fbf0494b52f7641fc5d8228eddc83ceb8e8b6899b4ed7
4
+ data.tar.gz: f997ebbf9cf7c114cf2db237f3b8042d585d50ae210426ee8c7f78cc42f204c8
5
5
  SHA512:
6
- metadata.gz: ea866283956880c3b2930a306333fc88df70461eba90454a517da8867abf62987d79f38477a7ba2635b628ff7189012a8e14d26163386785bf37667488a42b3a
7
- data.tar.gz: 5bef6b84951f6c5b6db5c16ae00a7e6db76f426decb3542311ac49688d1c0bbb748f462b972ef076ee3b27e506a3cdeaab2d66d496b7dbd2f94509d11925138b
6
+ metadata.gz: 0d31a8cd00da586bd1b1708fffe04b6319a0892127da935f91bbba38043356611ac482ad25eb921a595a6d7ebedbf841a1cb10f4784762ebc77aa2d1ac79d797
7
+ data.tar.gz: dc370f42d41c9d7df0a655d0ab591aabeac612221d98162bbf491eb68a582a217f4d634aea2111e95448c573768b15cc5a6c322f419ed31de57305feba524dec
@@ -0,0 +1,6 @@
1
+ # Changelog
2
+
3
+ ## 0.3.0
4
+
5
+ - added a `update` method to all `Valued` and `Valued::Mutable` objects that
6
+ allows creating a duplicate of an object with changed attributes
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- valued (0.2.1)
4
+ valued (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -82,7 +82,18 @@ p quantity
82
82
  => #<Quantity amount=2 unit="m">
83
83
  ```
84
84
 
85
- For a mutable object, just use `Valued::Mutable` instead of `Valued`.
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'
@@ -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)
@@ -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)
@@ -1,3 +1,3 @@
1
1
  module Valued
2
- VERSION = '0.2.1'
2
+ VERSION = '0.3.0'
3
3
  end
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.2.1
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-16 00:00:00.000000000 Z
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