mutability 1.0.0 → 1.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2504afd2226715583357d5ad0b509b4d2317597f
4
- data.tar.gz: d6f1452f30ac8db6005346ca16f0adb1083e3445
3
+ metadata.gz: a58152afaa3f64181624fbe5d87fe552ef741b7f
4
+ data.tar.gz: bb33dce7188e8e74dff1fb7a2bf7aa8def65f767
5
5
  SHA512:
6
- metadata.gz: ee010ec5d6781e8eee1bff969525c8fc4e6b4aabe5e599a2f434412e091af4a2c30a17a2b0d8a9daaeba27d645a6f73a8ac26abeef10a47788c214b3c239f2d4
7
- data.tar.gz: 4a3a12fd41072ca77693064ff2ed70287bcf648998ca6391abb7cea3581a2fdd9e3e5930c523c29c0faa09f724be434fb5520723c2073782403abc291c64c423
6
+ metadata.gz: 8c0bc0028bf22d5f69d2d9c964d71c0d91c04d0f34a8ede8864a4a4c1f0d945f9b61fae3b6baf9ed7c47801947eb7a592ae01b642d4bc6dc8e2d6eccd0225b1c
7
+ data.tar.gz: d8071bc563dcba0e1bf06a216fe930073e38abc92077766f792192bd2bc96d6e81aa98b0730c06071357056a41b6f9b229ac61044368b3bcb376de401a9e591f
@@ -0,0 +1,48 @@
1
+ require 'forwardable'
2
+
3
+ # **************************************************************************
4
+ # Mutability::Mutable
5
+ #
6
+ # This class adds a wrapper around a an object that keeps an unchanged
7
+ # copy of the object. This allows it to be mutated as much as needed and
8
+ # still be compared against the original version, or even reset to the
9
+ # original.
10
+ #
11
+ # Adds the freeze! and revert! methods and delegates most methods to the
12
+ # working version (@self). The following methods act upon the Mutable
13
+ # object itself and not its working version:
14
+ # - #inspect
15
+ # - #=
16
+ # - any equality methods that are not built on #== or #===
17
+ # **************************************************************************
18
+
19
+ module Mutability
20
+ class Mutable
21
+ extend Forwardable
22
+
23
+ def_delegators :@self, *Mutability::DELEGATED_METHODS
24
+
25
+ attr_reader :original
26
+ attr_accessor :self
27
+
28
+ def initialize(original)
29
+ @original = original.freeze # don't modify, even accidentally!
30
+ revert!
31
+ end
32
+
33
+ def freeze!
34
+ @original = @self.dup.freeze
35
+ end
36
+
37
+ def revert!
38
+ @self = @original.dup # we want an unfrozen copy, so cannot clone
39
+ end
40
+
41
+ private
42
+
43
+ # cheap delegation
44
+ def method_missing(sym, *args, &block)
45
+ @self.send(sym, *args, &block)
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,9 @@
1
+ require_relative 'mutable'
2
+
3
+ module Mutability
4
+ class MutableArray < Mutable
5
+ def initialize(array = [])
6
+ super array
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require_relative 'mutable'
2
+
3
+ module Mutability
4
+ class MutableHash < Mutable
5
+ def initialize(hash = {})
6
+ super hash
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module Mutability
2
+ VERSION = '1.0.1'
3
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mutability
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kelli Searfos
@@ -78,6 +78,10 @@ extensions: []
78
78
  extra_rdoc_files: []
79
79
  files:
80
80
  - lib/mutability.rb
81
+ - lib/mutability/mutable.rb
82
+ - lib/mutability/mutable_array.rb
83
+ - lib/mutability/mutable_hash.rb
84
+ - lib/mutability/version.rb
81
85
  homepage: https://github.com/ksearfos/mutability
82
86
  licenses:
83
87
  - MIT