sonofhash 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.
- data/lib/sonofhash.rb +49 -0
- metadata +55 -0
data/lib/sonofhash.rb
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
require 'set'
|
|
2
|
+
|
|
3
|
+
class SonOfHash
|
|
4
|
+
|
|
5
|
+
def initialize(parent={})
|
|
6
|
+
@store = {}
|
|
7
|
+
@deletions = Set.new
|
|
8
|
+
@parent = parent
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def new_child
|
|
12
|
+
return SonOfHash.new(self)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def [](key)
|
|
16
|
+
return nil if @deletions.member?(key)
|
|
17
|
+
return @store[key] if @store.has_key?(key)
|
|
18
|
+
@parent[key]
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def []=(key, value)
|
|
22
|
+
@store[key] = value
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def has_key?(key)
|
|
26
|
+
return member?(key)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def member?(key)
|
|
30
|
+
return false if @deletions.member?(key);
|
|
31
|
+
return @store.member?(key) || @parent.member?(key)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def delete(key)
|
|
35
|
+
@deletions.add(key)
|
|
36
|
+
return @store.delete(key)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def commit
|
|
40
|
+
@store.each {|key, value| @parent[key] = value}
|
|
41
|
+
@deletions.each {|key| @parent.delete(key)}
|
|
42
|
+
|
|
43
|
+
# I want to clear the state here, but I don't know
|
|
44
|
+
# a good spec for it yet
|
|
45
|
+
# @store.clear
|
|
46
|
+
# @deletions.clear
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: sonofhash
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: "0.1"
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Tushar Pokle
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2010-03-11 00:00:00 +11:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies: []
|
|
15
|
+
|
|
16
|
+
description: Isolate changes to a Hash
|
|
17
|
+
email: tushar.pokle@gmail.com
|
|
18
|
+
executables: []
|
|
19
|
+
|
|
20
|
+
extensions: []
|
|
21
|
+
|
|
22
|
+
extra_rdoc_files: []
|
|
23
|
+
|
|
24
|
+
files:
|
|
25
|
+
- lib/sonofhash.rb
|
|
26
|
+
has_rdoc: true
|
|
27
|
+
homepage: http://gemcutter.org/gems/partition
|
|
28
|
+
licenses: []
|
|
29
|
+
|
|
30
|
+
post_install_message:
|
|
31
|
+
rdoc_options: []
|
|
32
|
+
|
|
33
|
+
require_paths:
|
|
34
|
+
- lib
|
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: "0"
|
|
40
|
+
version:
|
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
42
|
+
requirements:
|
|
43
|
+
- - ">="
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: "0"
|
|
46
|
+
version:
|
|
47
|
+
requirements: []
|
|
48
|
+
|
|
49
|
+
rubyforge_project:
|
|
50
|
+
rubygems_version: 1.3.5
|
|
51
|
+
signing_key:
|
|
52
|
+
specification_version: 3
|
|
53
|
+
summary: Track the changes to a Hash, and then re-apply them to other hashes.
|
|
54
|
+
test_files: []
|
|
55
|
+
|