deployable-patch 0.3.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Makefile +4 -0
- data/lib/deployable/patch/hash/accept.rb +33 -0
- data/lib/deployable/patch/hash/except.rb +26 -0
- data/lib/deployable/patch/{hash_keys.rb → hash/keys.rb} +0 -0
- data/lib/deployable/patch/hash.rb +4 -0
- data/lib/deployable/patch/version.rb +1 -1
- data/lib/deployable/patch.rb +2 -2
- data/spec/hash_accept_spec.rb +18 -0
- data/spec/hash_except_spec.rb +22 -0
- data/spec/hash_keys_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- metadata +12 -5
- data/Rakefile +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34622ab5537292f84612831eb2aa395f8009f296
|
4
|
+
data.tar.gz: 8c546b06c7e35163de4323635d2e361acefb9501
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b191ac3a98a97ae150c0743c93a22e238a8e3565f4770f17cf0a7a048f8bd6aea686bff1ca501e172b38fc9f85a2789bd30962f108c2561e8e9ad39d4bf5d0ef
|
7
|
+
data.tar.gz: 32af4676dca4832a32641cc8ab92225a6d13442c11b3dda568d649891ba2c476da105f3307e14085876261d0fcb29142f244b33529e37a8277f3e398bd8f0f03
|
data/Makefile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
class Hash
|
2
|
+
# Return a hash that includes only the given keys. This is useful for
|
3
|
+
# discarding everything but a few known toggles:
|
4
|
+
#
|
5
|
+
# {:a => 1, :b => 2}.accept(:a) # => {:a => 1}
|
6
|
+
#
|
7
|
+
|
8
|
+
#
|
9
|
+
def accept(*key_list)
|
10
|
+
r = self.class.new
|
11
|
+
key_list.each{ |key|
|
12
|
+
begin
|
13
|
+
r[key] = fetch(key)
|
14
|
+
rescue KeyError
|
15
|
+
|
16
|
+
end
|
17
|
+
}
|
18
|
+
r
|
19
|
+
|
20
|
+
# Slower
|
21
|
+
#dup.accept!(*key_list)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Removes any keys not given from the hash.
|
25
|
+
#
|
26
|
+
# @hash.accept! :one, :two
|
27
|
+
|
28
|
+
def accept!(*key_list)
|
29
|
+
intersection = keys - key_list
|
30
|
+
intersection.each{ |key| delete(key) }
|
31
|
+
self
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class Hash
|
2
|
+
# Return a hash that includes everything but the given keys. This is useful for
|
3
|
+
# limiting a set of parameters to everything but a few known toggles:
|
4
|
+
#
|
5
|
+
# @person.update_attributes(params[:person].except(:admin))
|
6
|
+
#
|
7
|
+
# If the receiver responds to +convert_key+, the method is called on each of the
|
8
|
+
# arguments. This allows +except+ to play nice with hashes with indifferent access
|
9
|
+
# for instance:
|
10
|
+
#
|
11
|
+
# {:a => 1}.with_indifferent_access.except(:a) # => {}
|
12
|
+
# {:a => 1}.with_indifferent_access.except("a") # => {}
|
13
|
+
#
|
14
|
+
def except(*keys)
|
15
|
+
dup.except!(*keys)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Replaces the hash without the given keys.
|
19
|
+
|
20
|
+
# @hash.except! :one, :two
|
21
|
+
|
22
|
+
def except!(*keys)
|
23
|
+
keys.each { |key| delete(key) }
|
24
|
+
self
|
25
|
+
end
|
26
|
+
end
|
File without changes
|
data/lib/deployable/patch.rb
CHANGED
@@ -5,5 +5,5 @@ require 'deployable/patch/ensure_array'
|
|
5
5
|
require 'deployable/patch/instance_class_variables'
|
6
6
|
require 'deployable/patch/meta'
|
7
7
|
require 'deployable/patch/class_ancestor'
|
8
|
-
require 'deployable/patch/
|
9
|
-
require 'deployable/patch/not_nil'
|
8
|
+
require 'deployable/patch/hash'
|
9
|
+
require 'deployable/patch/not_nil'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'deployable/patch/hash/accept'
|
3
|
+
|
4
|
+
describe 'Hash accept' do
|
5
|
+
before :each do
|
6
|
+
@hash = { :one => 1, :two => 2 }
|
7
|
+
end
|
8
|
+
|
9
|
+
it "hash accept" do
|
10
|
+
expect( @hash.accept :one ).to eq({:one => 1})
|
11
|
+
end
|
12
|
+
|
13
|
+
it "hash accept!" do
|
14
|
+
expect( @hash.accept! :one ).to eq({:one => 1})
|
15
|
+
expect( @hash.accept! :one ).to be @hash
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'deployable/patch/hash/except'
|
3
|
+
|
4
|
+
describe 'Hash except' do
|
5
|
+
before :each do
|
6
|
+
@hash = { :one => 1, :two => 2 }
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should return a new hash with :one" do
|
10
|
+
expect( @hash.except :one ).to eq({:two => 2})
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should return a new hash with nothing" do
|
14
|
+
expect( @hash.except :one, :two ).to eq({})
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should return same hash without :two" do
|
18
|
+
expect( @hash.except! :one ).to eq @hash
|
19
|
+
expect( @hash.except! :one ).to eq({:two => 2})
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
data/spec/hash_keys_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deployable-patch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Deployable - Matt Hoyle
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,8 +52,8 @@ files:
|
|
52
52
|
- ChangeLog.md
|
53
53
|
- Gemfile
|
54
54
|
- LICENSE.txt
|
55
|
+
- Makefile
|
55
56
|
- README.md
|
56
|
-
- Rakefile
|
57
57
|
- deployable-patch.gemspec
|
58
58
|
- lib/deployable/patch.rb
|
59
59
|
- lib/deployable/patch/array.rb
|
@@ -62,13 +62,18 @@ files:
|
|
62
62
|
- lib/deployable/patch/dir.rb
|
63
63
|
- lib/deployable/patch/dir/entries_no_dots.rb
|
64
64
|
- lib/deployable/patch/ensure_array.rb
|
65
|
-
- lib/deployable/patch/
|
65
|
+
- lib/deployable/patch/hash.rb
|
66
|
+
- lib/deployable/patch/hash/accept.rb
|
67
|
+
- lib/deployable/patch/hash/except.rb
|
68
|
+
- lib/deployable/patch/hash/keys.rb
|
66
69
|
- lib/deployable/patch/instance_class_variables.rb
|
67
70
|
- lib/deployable/patch/meta.rb
|
68
71
|
- lib/deployable/patch/not_nil.rb
|
69
72
|
- lib/deployable/patch/null.rb
|
70
73
|
- lib/deployable/patch/string/quoting.rb
|
71
74
|
- lib/deployable/patch/version.rb
|
75
|
+
- spec/hash_accept_spec.rb
|
76
|
+
- spec/hash_except_spec.rb
|
72
77
|
- spec/hash_keys_spec.rb
|
73
78
|
- spec/not_nil_spec.rb
|
74
79
|
- spec/patch_spec.rb
|
@@ -93,11 +98,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
98
|
version: '0'
|
94
99
|
requirements: []
|
95
100
|
rubyforge_project:
|
96
|
-
rubygems_version: 2.
|
101
|
+
rubygems_version: 2.5.1
|
97
102
|
signing_key:
|
98
103
|
specification_version: 4
|
99
104
|
summary: Central repo for monkey patches to other ruby stuff
|
100
105
|
test_files:
|
106
|
+
- spec/hash_accept_spec.rb
|
107
|
+
- spec/hash_except_spec.rb
|
101
108
|
- spec/hash_keys_spec.rb
|
102
109
|
- spec/not_nil_spec.rb
|
103
110
|
- spec/patch_spec.rb
|
data/Rakefile
DELETED