octothorpe 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.hgignore +2 -1
- data/lib/octothorpe.rb +15 -13
- metadata +3 -4
- data/.ruby-version +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04716672658edfc3209de1cf393dd97f6bc8704a
|
4
|
+
data.tar.gz: 87efb8325fbe599b1ee0c17ac3dd854a2190a601
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95250990bf652fef1126436b8f86cfebc049cac2074f59355a819847b9f5fde15d85cf151930df174d48fb095be3b8fd8293c8cf6f6f60329fd40f5ca286a35f
|
7
|
+
data.tar.gz: 931b5b36ee0e1976831ee8f9d6ee8a7d3df86a7557407229c0010fc9ab3469700089496ddd505b6a42a243db1d4cc1945eedab7bcc5ce82bbdcfcd986d668712
|
data/.hgignore
CHANGED
data/lib/octothorpe.rb
CHANGED
@@ -14,7 +14,7 @@ require 'forwardable'
|
|
14
14
|
# Meant to facilitate message-passing between classes.
|
15
15
|
#
|
16
16
|
# Simple example:
|
17
|
-
# ot =
|
17
|
+
# ot = Octothorpe.new(one: 1, "two" => 2, "weird key" => 3)
|
18
18
|
# ot.>>.one # -> 1
|
19
19
|
# ot.>>.two # -> 2
|
20
20
|
# ot.get("weird key") # -> 3
|
@@ -41,7 +41,7 @@ class Octothorpe
|
|
41
41
|
def_delegators :@inner_hash, :select, :map, :reject, :inject
|
42
42
|
|
43
43
|
# Gem version number
|
44
|
-
VERSION = '0.1.
|
44
|
+
VERSION = '0.1.2'
|
45
45
|
|
46
46
|
|
47
47
|
# Generic Octothorpe error class
|
@@ -59,15 +59,15 @@ class Octothorpe
|
|
59
59
|
# names. Not exposed to Octothorpe's caller.
|
60
60
|
#
|
61
61
|
class Storage
|
62
|
-
attr_reader :
|
62
|
+
attr_reader :octothorpe_store
|
63
63
|
|
64
64
|
def initialize(hash)
|
65
|
-
@
|
65
|
+
@octothorpe_store = hash
|
66
66
|
end
|
67
67
|
|
68
68
|
def method_missing(method, *attrs)
|
69
69
|
super if (block_given? || !attrs.empty?)
|
70
|
-
@
|
70
|
+
@octothorpe_store[method.to_sym]
|
71
71
|
end
|
72
72
|
|
73
73
|
end
|
@@ -88,7 +88,7 @@ class Octothorpe
|
|
88
88
|
#
|
89
89
|
def initialize(hash=nil)
|
90
90
|
@store = Storage.new( symbol_hash(hash || {}) )
|
91
|
-
@inner_hash = @store.
|
91
|
+
@inner_hash = @store.octothorpe_store
|
92
92
|
end
|
93
93
|
|
94
94
|
|
@@ -112,13 +112,14 @@ class Octothorpe
|
|
112
112
|
# :call-seq:
|
113
113
|
# ot.get(key)
|
114
114
|
# ot.send(key)
|
115
|
+
# ot[key]
|
115
116
|
#
|
116
117
|
# You can use get to access member object values instead of the >> syntax.
|
117
118
|
#
|
118
119
|
# Unlike >>, this works for keys with spaces, or keys that have the same name
|
119
120
|
# as methods on Object.
|
120
121
|
#
|
121
|
-
def get(key); @store.
|
122
|
+
def get(key); @store.octothorpe_store[key.to_sym]; end
|
122
123
|
|
123
124
|
alias send get
|
124
125
|
alias [] get
|
@@ -127,7 +128,7 @@ class Octothorpe
|
|
127
128
|
##
|
128
129
|
# Returns a hash of the object.
|
129
130
|
#
|
130
|
-
def to_h; @store.
|
131
|
+
def to_h; @store.octothorpe_store; end
|
131
132
|
|
132
133
|
|
133
134
|
##
|
@@ -146,7 +147,7 @@ class Octothorpe
|
|
146
147
|
#
|
147
148
|
def guard(klass, *keys)
|
148
149
|
raise Frozen if self.frozen?
|
149
|
-
keys.map(&:to_sym).each{|k| @store.
|
150
|
+
keys.map(&:to_sym).each{|k| @store.octothorpe_store[k] ||= klass.new }
|
150
151
|
self
|
151
152
|
end
|
152
153
|
|
@@ -156,22 +157,23 @@ class Octothorpe
|
|
156
157
|
# ot.merge(other) -> new_ot
|
157
158
|
# ot.merge(other){|key, oldval, newval| block} -> new_ot
|
158
159
|
#
|
159
|
-
# Exactly
|
160
|
+
# Exactly as _Hash.merge_, but returns a new Octothorpe object.
|
160
161
|
#
|
161
162
|
# You may pass a hash or an octothorpe. Raises Octothorpe::BadHash
|
162
163
|
# if it is anything else.
|
163
164
|
#
|
164
165
|
def merge(other)
|
166
|
+
thisHash = @store.octothorpe_store
|
165
167
|
otherHash = symbol_hash(other)
|
166
168
|
|
167
169
|
merged =
|
168
170
|
if block_given?
|
169
|
-
|
171
|
+
thisHash.merge(otherHash) {|key,old,new| yield key, old, new }
|
170
172
|
else
|
171
|
-
|
173
|
+
thisHash.merge(otherHash)
|
172
174
|
end
|
173
175
|
|
174
|
-
|
176
|
+
Octothorpe.new(merged)
|
175
177
|
end
|
176
178
|
|
177
179
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: octothorpe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Jones
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -95,7 +95,6 @@ extra_rdoc_files: []
|
|
95
95
|
files:
|
96
96
|
- ".hgignore"
|
97
97
|
- ".rspec"
|
98
|
-
- ".ruby-version"
|
99
98
|
- Gemfile
|
100
99
|
- LICENSE.txt
|
101
100
|
- README.md
|
@@ -125,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
124
|
version: '0'
|
126
125
|
requirements: []
|
127
126
|
rubyforge_project:
|
128
|
-
rubygems_version: 2.
|
127
|
+
rubygems_version: 2.5.1
|
129
128
|
signing_key:
|
130
129
|
specification_version: 4
|
131
130
|
summary: Like a Hash. Better for message passing between classes, I hope.
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.2.2
|