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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 88bd324ee45730f3e43cf66023b8b6d15bc63b30
4
- data.tar.gz: 4706ab7c9faf64e7927ee448ebd4e394a11d1a29
3
+ metadata.gz: 34622ab5537292f84612831eb2aa395f8009f296
4
+ data.tar.gz: 8c546b06c7e35163de4323635d2e361acefb9501
5
5
  SHA512:
6
- metadata.gz: 582140540edc7fd63a99ce01407ddb17eea81f97cac2067a8c90be9e0a2092b7b61a2c2e6e90912fac8685404bfac04a16130c356069c023345373c2535fced3
7
- data.tar.gz: ab98ea15820ccfca7f4ea81be654cc07b65449dea107135dba3e46bf0b76034a9bf9865d310130692c62e905fd13551e2c13b64d9743b0a53c88eb209eae5560
6
+ metadata.gz: b191ac3a98a97ae150c0743c93a22e238a8e3565f4770f17cf0a7a048f8bd6aea686bff1ca501e172b38fc9f85a2789bd30962f108c2561e8e9ad39d4bf5d0ef
7
+ data.tar.gz: 32af4676dca4832a32641cc8ab92225a6d13442c11b3dda568d649891ba2c476da105f3307e14085876261d0fcb29142f244b33529e37a8277f3e398bd8f0f03
data/Makefile ADDED
@@ -0,0 +1,4 @@
1
+
2
+ build: pkg
3
+ bundle exec gem build deployable-patch.gemspec
4
+ mv deployable-patch-[0-9]*.gem pkg/
@@ -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
@@ -0,0 +1,4 @@
1
+ require "deployable/patch/hash/keys"
2
+ require "deployable/patch/hash/accept"
3
+ require "deployable/patch/hash/except"
4
+
@@ -1,6 +1,6 @@
1
1
  module Deployable
2
2
  module Patch
3
3
  # deployable-patch version
4
- VERSION = "0.3.0"
4
+ VERSION = "1.0.0"
5
5
  end
6
6
  end
@@ -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/hash_keys'
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
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- require 'deployable/patch/hash_keys'
2
+ require 'deployable/patch/hash/keys'
3
3
 
4
4
  describe 'Hash keys any/all' do
5
5
  before :each do
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  gem 'rspec', '~> 3.1'
2
2
  require 'rspec'
3
3
  require 'deployable/patch/version'
4
-
4
+ require 'pry-byebug'
5
5
 
6
6
  include Deployable::Patch
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.3.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-04-23 00:00:00.000000000 Z
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/hash_keys.rb
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.2.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
@@ -1,2 +0,0 @@
1
- require "bundler/gem_tasks"
2
-