octothorpe 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4eb5a75a4f6e96e372ad54747fd18dbe5246e0e6
4
- data.tar.gz: d8c0c8a82fef44e3c160bd327d4d1d32f6ce3e50
3
+ metadata.gz: 75ff578c9887b8a62a0effcc8e51233eefb7743e
4
+ data.tar.gz: c449257f2bed3d03ee82b53653771e22711d312e
5
5
  SHA512:
6
- metadata.gz: 7abfb6d20290533da8a8a8e3357bf6244748c8479b1c5da22b1b7c852d4ca33e792ee72423dc48caf845209261b083494d11ab9642de5ad7fc331b91a7a05579
7
- data.tar.gz: af00c9772425af4d6d4b40b729305af4126e2d8155bc15d438e6b8d2dd519c6bc5755463492a51fd64b52ff3d1b1579a754c83b1b976f0d3f32b1353e60eb6bb
6
+ metadata.gz: 3cb263ec2df833ac54a34cc838b267bd198062cb93c3db6c6ee383fdce4943eb06c9b34f0e0703d79f53aa8c056c8899172fb32339c029fc61b4ad94685911d9
7
+ data.tar.gz: 34b01fb89862be06e9c92e2e801c11247b14f4a6cb61b29027d9cec421610225aa4ccde24fbbc55e400de67397c0f6087b3d755bf04db5b3570bebb5772494ab
data/.hgtags CHANGED
@@ -1,2 +1,3 @@
1
1
  a17ae5a3dedd4d2b74b0840a7161e153efd72741 0.2.0
2
2
  a7a29ac9aca7023491b7bb58e0516c115b7f2511 0.3.0
3
+ e83c059c376d0baa5ab79c95b7516b1d35747fe2 0.4.0
data/README.md CHANGED
@@ -30,7 +30,7 @@ Or install it yourself as:
30
30
  Simple example:
31
31
 
32
32
  ```ruby
33
- ot = Octotghorpe.new(one: 1, "two" => 2, "weird key" => 3)
33
+ ot = Octothorpe.new(one: 1, "two" => 2, "weird key" => 3)
34
34
  ot.>>.one # -> 1
35
35
  ot.>>.two # -> 2
36
36
  ot.get("weird key") # -> 3
@@ -39,7 +39,7 @@ ot.get("weird key") # -> 3
39
39
  With guard conditions:
40
40
 
41
41
  ```ruby
42
- ot = Octotghorpe.new(one: 1, "two" => 2)
42
+ ot = Octothorpe.new(one: 1, "two" => 2)
43
43
  ot.guard(Array, :three)
44
44
  ot.freeze # optional step - makes OT truly read-only
45
45
  ot.>>.three # -> []
@@ -62,6 +62,8 @@ Maybe not. Feel free to be your own judge.
62
62
 
63
63
  ### What possible use is it?
64
64
 
65
+ Well, I use it to pass data between models, controllers and views in Sinatra.
66
+
65
67
  If you are fed up with errors caused because Gem A gives you a hash with string keys and Gem B
66
68
  expects symbol keys; or you are tired of putting:
67
69
 
data/lib/octothorpe.rb CHANGED
@@ -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.3.0'
44
+ VERSION = '0.4.0'
45
45
 
46
46
 
47
47
  # Generic Octothorpe error class
@@ -58,7 +58,7 @@ class Octothorpe
58
58
  # Inner class for storage. This is to minimise namespace collision with key names. Not exposed to
59
59
  # Octothorpe's caller.
60
60
  #
61
- class Storage
61
+ class Storage < BasicObject
62
62
  attr_reader :octothorpe_store
63
63
 
64
64
  def initialize(hash)
@@ -66,7 +66,7 @@ class Octothorpe
66
66
  end
67
67
 
68
68
  def method_missing(method, *attrs)
69
- super if (block_given? || !attrs.empty?)
69
+ super if (::Kernel.block_given? || !attrs.empty?)
70
70
  @octothorpe_store[method.to_sym]
71
71
  end
72
72
 
@@ -186,6 +186,20 @@ class Octothorpe
186
186
  end
187
187
 
188
188
 
189
+ ##
190
+ # :call-seq:
191
+ # ot.whitelist(:one, :two, :three) -> new_ot
192
+ #
193
+ # Return an Octothorpe containing only these keys.
194
+ #
195
+ # If you name a key that is missing, that key will also be missing in the output; use _Guard_
196
+ # if that's not what you want.
197
+ #
198
+ def whitelist(*keys)
199
+ Octothorpe.new @inner_hash.select{|k,_| symbol_hash(keys).include? k}
200
+ end
201
+
202
+
189
203
  #
190
204
  # Resolve some of the standard comparisons (with an OT or a hash)
191
205
  #
@@ -192,6 +192,31 @@ describe Octothorpe do
192
192
  end
193
193
 
194
194
 
195
+ describe "#whitelist" do
196
+
197
+ it "returns only the keys you give it" do
198
+ expect( @ot.whitelist(:one, :dup).to_h ).to eq(one: "a", dup: 3)
199
+ end
200
+
201
+ it "copes with symbols or strings as keys" do
202
+ expect( @ot.whitelist(:one, "weird key").to_h ).to eq(one: "a", :"weird key" => 4)
203
+ end
204
+
205
+ it "returns only the keys it has" do
206
+ expect( @ot.whitelist(:one, :four, :two).to_h ).to eq(one: "a", two: 2)
207
+ end
208
+
209
+ it "returns an empty OT for an empty OT" do
210
+ expect( Octothorpe.new.whitelist(:foo) ).to eq Octothorpe.new
211
+ end
212
+
213
+ it "copes with a null whitelist" do
214
+ expect( @ot.whitelist ).to eq Octothorpe.new
215
+ end
216
+
217
+ end
218
+
219
+
195
220
  describe "#==" do
196
221
 
197
222
  context 'when passed a hash' do
metadata CHANGED
@@ -1,83 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octothorpe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Jones
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-29 00:00:00.000000000 Z
11
+ date: 2017-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.7'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.7'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: '10.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: pry
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: pry-doc
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - '>='
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  description: |
@@ -93,9 +93,9 @@ executables: []
93
93
  extensions: []
94
94
  extra_rdoc_files: []
95
95
  files:
96
- - ".hgignore"
97
- - ".hgtags"
98
- - ".rspec"
96
+ - .hgignore
97
+ - .hgtags
98
+ - .rspec
99
99
  - Gemfile
100
100
  - LICENSE.txt
101
101
  - README.md
@@ -115,17 +115,17 @@ require_paths:
115
115
  - lib
116
116
  required_ruby_version: !ruby/object:Gem::Requirement
117
117
  requirements:
118
- - - ">="
118
+ - - '>='
119
119
  - !ruby/object:Gem::Version
120
120
  version: '0'
121
121
  required_rubygems_version: !ruby/object:Gem::Requirement
122
122
  requirements:
123
- - - ">="
123
+ - - '>='
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
126
  requirements: []
127
127
  rubyforge_project:
128
- rubygems_version: 2.5.1
128
+ rubygems_version: 2.4.8
129
129
  signing_key:
130
130
  specification_version: 4
131
131
  summary: Like a Hash. Better for message passing between classes, I hope.