duct_tape 0.3.0 → 0.3.4

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/Rakefile CHANGED
@@ -3,6 +3,7 @@ require 'rake'
3
3
  require 'jeweler'
4
4
 
5
5
  VERSION_FILE = File.expand_path("../VERSION", __FILE__)
6
+ GEMSPEC_FILE = File.expand_path("../duct_tape.gemspec", __FILE__)
6
7
  VERSION_STRING = File.read(VERSION_FILE).strip
7
8
  Jeweler::Tasks.new do |gem|
8
9
  gem.name = "duct_tape"
@@ -111,7 +112,12 @@ namespace :version do
111
112
  f.write(VERSION_STRING.sub!(/^(\d+)\.(\d+)\.(\d+)$/) { |s| "#{$1}.#{$2}.#{$3.to_i + 1}" })
112
113
  end
113
114
  commit_msg = "New Version: #{VERSION_STRING}"
114
- sh "git commit -m #{commit_msg.inspect} #{(VERSION_FILE).to_s.inspect}"
115
+ files = [VERSION_FILE.inspect]
116
+ if Rake::Task[:gemspec]
117
+ Rake::Task[:gemspec].invoke
118
+ files << GEMSPEC_FILE.inspect
119
+ end
120
+ sh "git commit -m #{commit_msg.inspect} #{files.join(" ")}"
115
121
  sh "git checkout -- #{(VERSION_FILE).to_s.inspect}"
116
122
  end
117
123
 
@@ -122,7 +128,12 @@ namespace :version do
122
128
  f.write(VERSION_STRING.sub!(/^(\d+)\.(\d+)\.(\d+)$/) { |s| "#{$1}.#{$2.to_i + 1}.0" })
123
129
  end
124
130
  commit_msg = "New Version: #{VERSION_STRING}"
125
- sh "git commit -m #{commit_msg.inspect} #{(VERSION_FILE).to_s.inspect}"
131
+ files = [VERSION_FILE.inspect]
132
+ if Rake::Task[:gemspec]
133
+ Rake::Task[:gemspec].invoke
134
+ files << GEMSPEC_FILE.inspect
135
+ end
136
+ sh "git commit -m #{commit_msg.inspect} #{files.join(" ")}"
126
137
  sh "git checkout -- #{(VERSION_FILE).to_s.inspect}"
127
138
  end
128
139
 
@@ -133,7 +144,12 @@ namespace :version do
133
144
  f.write(VERSION_STRING.sub!(/^(\d+)\.(\d+)\.(\d+)$/) { |s| "#{$1.to_i + 1}.0.0" })
134
145
  end
135
146
  commit_msg = "New Version: #{VERSION_STRING}"
136
- sh "git commit -m #{commit_msg.inspect} #{(VERSION_FILE).to_s.inspect}"
147
+ files = [VERSION_FILE.inspect]
148
+ if Rake::Task[:gemspec]
149
+ Rake::Task[:gemspec].invoke
150
+ files << GEMSPEC_FILE.inspect
151
+ end
152
+ sh "git commit -m #{commit_msg.inspect} #{files.join(" ")}"
137
153
  sh "git checkout -- #{(VERSION_FILE).to_s.inspect}"
138
154
  end
139
155
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.4
data/duct_tape.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "duct_tape"
8
- s.version = "0.3.0"
8
+ s.version = "0.3.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Tim Rodriguez"]
12
- s.date = "2014-06-23"
12
+ s.date = "2014-06-25"
13
13
  s.description = "A general-purpose utility library for Ruby"
14
14
  s.email = ["tw.rodriguez@gmail.com"]
15
15
  s.extensions = ["ext/mkrf_conf.rb"]
@@ -111,3 +111,4 @@ Gem::Specification.new do |s|
111
111
  s.add_dependency(%q<simplecov>, [">= 0"])
112
112
  end
113
113
  end
114
+
@@ -43,6 +43,21 @@ module Containers
43
43
  @hash.inspect
44
44
  end
45
45
 
46
+ def keys
47
+ @hash.keys
48
+ end
49
+
50
+ def values
51
+ @hash.values
52
+ end
53
+
54
+ # TODO
55
+ #def method_missing(*args, &block)
56
+ # ret = @hash.__send__(*args, &block)
57
+ # rebuild_hash
58
+ # ret
59
+ #end
60
+
46
61
  def to_s
47
62
  @hash.to_s
48
63
  end
data/lib/ext/hash.rb CHANGED
@@ -45,10 +45,14 @@ class Hash
45
45
  alias_method :&, :select_keys
46
46
 
47
47
  def select_keys!(other, &block)
48
- type_assert(other, Array, Hash)
49
48
  unless block_given?
49
+ type_assert(other, Array, Hash, Regexp)
50
50
  other = other.keys if Hash === other
51
- block = proc { |k| other.include?(k) }
51
+ if Regexp === other
52
+ block = proc { |k| other === k }
53
+ else
54
+ block = proc { |k| other.include?(k) }
55
+ end
52
56
  end
53
57
  self.reject! { |key,val| !block[key] }
54
58
  end
@@ -61,10 +65,14 @@ class Hash
61
65
  alias_method :-, :reject_keys
62
66
 
63
67
  def reject_keys!(other, &block)
64
- type_assert(other, Array, Hash)
65
68
  unless block_given?
69
+ type_assert(other, Array, Hash, Regexp)
66
70
  other = other.keys if Hash === other
67
- block = proc { |k| other.include?(k) }
71
+ if Regexp === other
72
+ block = proc { |k| other === k }
73
+ else
74
+ block = proc { |k| other.include?(k) }
75
+ end
68
76
  end
69
77
  self.reject! { |key,val| block[key] }
70
78
  end
@@ -80,4 +88,52 @@ class Hash
80
88
  def not_empty?(arg)
81
89
  !empty?
82
90
  end
91
+
92
+ def flatten_nested!(key_joiner="__")
93
+ changed = false
94
+ keys.each do |base_key|
95
+ if self[base_key].is_a?(Hash)
96
+ self[base_key].flatten_nested!(key_joiner)
97
+ self[base_key].each_pair do |k,v|
98
+ self["#{base_key}#{key_joiner}#{k}"] = v
99
+ end
100
+ delete(base_key)
101
+ changed = true
102
+ end
103
+ end
104
+ changed ? self : nil
105
+ end
106
+
107
+ def expand_nested!(key_joiner="__")
108
+ changed = false
109
+ keys.each do |base_key|
110
+ if base_key[key_joiner]
111
+ nested_keys = base_key.split(key_joiner)
112
+ hsh_ref = self
113
+ nested_keys.each_with_index do |key,idx|
114
+ if idx == nested_keys.size - 1
115
+ hsh_ref[key] = self[base_key]
116
+ else
117
+ hsh_ref[key] ||= {}
118
+ hsh_ref = hsh_ref[key]
119
+ end
120
+ end
121
+ delete(base_key)
122
+ changed = true
123
+ end
124
+ end
125
+ changed ? self : nil
126
+ end
127
+
128
+ def flatten_nested(key_joiner="__")
129
+ target = deep_dup
130
+ target.flatten_nested!(key_joiner)
131
+ target
132
+ end
133
+
134
+ def expand_nested(key_joiner="__")
135
+ target = deep_dup
136
+ target.expand_nested!(key_joiner)
137
+ target
138
+ end
83
139
  end
@@ -103,3 +103,47 @@ describe Hash, "#to_h" do
103
103
  expect(a).to eq(b)
104
104
  end
105
105
  end
106
+
107
+ #
108
+ # Hash#flatten_nested
109
+ #
110
+ describe Hash, "#flatten_nested" do
111
+ it "should have the method defined" do
112
+ expect(Hash.method_defined?(:flatten_nested)).to be(true)
113
+ end
114
+
115
+ pending "More tests"
116
+ end
117
+
118
+ #
119
+ # Hash#flatten_nested!
120
+ #
121
+ describe Hash, "#flatten_nested!" do
122
+ it "should have the method defined" do
123
+ expect(Hash.method_defined?(:flatten_nested!)).to be(true)
124
+ end
125
+
126
+ pending "More tests"
127
+ end
128
+
129
+ #
130
+ # Hash#expand_nested
131
+ #
132
+ describe Hash, "#expand_nested" do
133
+ it "should have the method defined" do
134
+ expect(Hash.method_defined?(:expand_nested)).to be(true)
135
+ end
136
+
137
+ pending "More tests"
138
+ end
139
+
140
+ #
141
+ # Hash#expand_nested!
142
+ #
143
+ describe Hash, "#expand_nested!" do
144
+ it "should have the method defined" do
145
+ expect(Hash.method_defined?(:expand_nested!)).to be(true)
146
+ end
147
+
148
+ pending "More tests"
149
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: duct_tape
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-06-23 00:00:00.000000000 Z
12
+ date: 2014-07-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: facets