gem_bootstrap 0.1.3 → 0.2.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: 04f42f68b80452ca0ecc2aa6cf1dc636db517507
4
- data.tar.gz: fc05f29113bafebffca0479557b9ee8aef9b5850
3
+ metadata.gz: af9902ec8aa202d31d354737201107316976423c
4
+ data.tar.gz: db14948b41bb9dc7c05cd7ebcc4f9de399b0d635
5
5
  SHA512:
6
- metadata.gz: 9908fde60b4546363e192b521ee1ecc653ca728564aad1aa0ea814b919e5a771ab53e91c3867119d65d512754315615db24387058df0a52001fbb1e5b9fa38b0
7
- data.tar.gz: daae9c6bae2cbc7140a691e6f86d91546236d47156e42407aca6ab31eba416e1eddc722a40ee71483e1e5f8e56e9e007c92901d64f54de1c7932b7bbb0d8c053
6
+ metadata.gz: ddeafa22174dd04b1e069bd6b5bb78f09a0e56031a1760a989cdd29f7227c283e1fd38efc465be8fe79d7c7d4833a28d0f625b0ce15658522e12d5859f4c8c20
7
+ data.tar.gz: dd5a30bdab6a1d9d476db6012986cc05883c4cf2030a77b3b917fe962e88826c23e3df2b3af37483afea80a8ba3e536b9c49899e3ea659a4ec94af18e90cdf8f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ #### 0.2.0
2
+
3
+ - Use refinement instead of monkeypatching core classes
4
+ - Minor code cleanup
5
+
1
6
  #### 0.1.3
2
7
 
3
8
  - Update rubocop to 0.23.x
data/Rakefile CHANGED
@@ -1,13 +1,11 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rake/testtask"
3
3
  project_name = "gem_bootstrap"
4
-
5
4
  Rake::TestTask.new do |t|
6
5
  t.libs << "lib/#{project_name}"
7
6
  t.test_files = FileList["test/lib/#{project_name}/test_*.rb"]
8
7
  t.verbose = true
9
8
  end
10
-
11
9
  task default: [:test, :rubocop]
12
10
 
13
11
  task :pry do
@@ -23,8 +21,6 @@ require "rubocop/rake_task"
23
21
  desc "Run RuboCop on the lib directory"
24
22
  RuboCop::RakeTask.new(:rubocop) do |task|
25
23
  task.patterns = ["lib/**/*.rb"]
26
- # only show the files with failures
27
24
  task.formatters = ["files"]
28
- # don't abort rake on failure
29
25
  task.fail_on_error = false
30
26
  end
@@ -25,17 +25,20 @@ Gem::Specification.new do |spec|
25
25
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
26
26
  spec.test_files = Dir.glob("test/**/*")
27
27
  spec.require_paths = ["lib"]
28
- spec.add_runtime_dependency "thor", "~> 0.19"
29
- spec.add_runtime_dependency "grit", "~> 2.5"
30
- spec.add_development_dependency "awesome_print", "~> 1.2"
31
- spec.add_development_dependency "bundler", "~> 1.6"
32
- spec.add_development_dependency "gem-ctags", "~> 1.0"
33
- spec.add_development_dependency "minitest", "~> 5.3"
28
+
29
+ spec.add_runtime_dependency "thor", "~> 0.19.1"
30
+ spec.add_runtime_dependency "grit", "~> 2.5.0"
31
+ spec.add_runtime_dependency "agile_utils", "~> 0.2.0"
32
+
33
+ spec.add_development_dependency "awesome_print", "~> 1.2.0"
34
+ spec.add_development_dependency "bundler", "~> 1.6.2"
35
+ spec.add_development_dependency "gem-ctags", "~> 1.0.6"
36
+ spec.add_development_dependency "minitest", "~> 5.4.0"
34
37
  spec.add_development_dependency "minitest-spec-context", "~> 0.0.3"
35
- spec.add_development_dependency "guard", "~> 2.6"
36
- spec.add_development_dependency "guard-minitest", "~> 2.2"
37
- spec.add_development_dependency "pry", "~> 0.9"
38
- spec.add_development_dependency "rake", "~> 10.3"
39
- spec.add_development_dependency "rubocop", "~> 0.23"
38
+ spec.add_development_dependency "guard", "~> 2.6.1"
39
+ spec.add_development_dependency "guard-minitest", "~> 2.3.1"
40
+ spec.add_development_dependency "pry", "~> 0.10.0"
41
+ spec.add_development_dependency "rake", "~> 10.3.2"
42
+ spec.add_development_dependency "rubocop", "~> 0.24.1"
40
43
  spec.add_development_dependency "yard", "~> 0.8.7"
41
44
  end
@@ -1,9 +1,13 @@
1
1
  require "thor"
2
+ require "agile_utils"
2
3
  require_relative "./misc_utils"
3
4
  require_relative "./git_utils"
4
5
  module GemBootstrap
5
6
  class CLI < Thor::Group
7
+ using AgileUtils::HashExt
8
+ using AgileUtils::BlankExt
6
9
  include Thor::Actions
10
+
7
11
  argument :name
8
12
  class_option :github_id,
9
13
  aliases: "-g",
@@ -38,7 +42,6 @@ module GemBootstrap
38
42
  template "../../templates/lib/newgem/logger.rb", "#{name}/lib/#{name}/logger.rb"
39
43
  template "../../templates/lib/newgem/cli.rb", "#{name}/lib/#{name}/cli.rb"
40
44
  template "../../templates/lib/newgem/newgem.rb", "#{name}/lib/#{name}/#{name}.rb"
41
- template "../../templates/lib/newgem/core_ext/hash/keys.rb", "#{name}/lib/#{name}/core_ext/hash/keys.rb"
42
45
  template "../../templates/test/test_helper.rb", "#{name}/test/test_helper.rb"
43
46
  template "../../templates/test/lib/newgem/test_newgem.rb", "#{name}/test/lib/#{name}/test_#{name}.rb"
44
47
  end
@@ -1,3 +1,3 @@
1
1
  module GemBootstrap
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/gem_bootstrap.rb CHANGED
@@ -3,5 +3,5 @@ require_relative "./gem_bootstrap/cli"
3
3
  require_relative "./gem_bootstrap/git_utils"
4
4
  require_relative "./gem_bootstrap/misc_utils"
5
5
  require_relative "./gem_bootstrap/gem_bootstrap"
6
- require_relative "./gem_bootstrap/core_ext/object/blank"
6
+
7
7
  include GemBootstrap
@@ -1,5 +1,5 @@
1
1
  ### Changelogs
2
2
 
3
- #### 0.0.1
3
+ #### 0.1.0
4
4
 
5
5
  - Initial release
data/templates/Guardfile CHANGED
@@ -3,11 +3,6 @@
3
3
  guard 'minitest' do
4
4
  # with Minitest::Unit
5
5
  watch(%r|^test/(.*)\/?test_(.*)\.rb|)
6
- watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
7
- watch(%r|^test/test_helper\.rb|) { "test" }
8
-
9
- # with Minitest::Spec
10
- # watch(%r|^spec/(.*)_spec\.rb|)
11
- # watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
- # watch(%r|^spec/spec_helper\.rb|) { "spec" }
6
+ watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
7
+ watch(%r|^test/test_helper\.rb|) { "test" }
13
8
  end
@@ -28,12 +28,6 @@ CollectionMethods:
28
28
  find: 'detect'
29
29
  find_all: 'select'
30
30
 
31
- # Do not force public/protected/private keyword to be indented at the same
32
- # level as the def keyword. My personal preference is to outdent these keywords
33
- # because I think when scanning code it makes it easier to identify the
34
- # sections of code and visually separate them. When the keyword is at the same
35
- # level I think it sort of blends in with the def keywords and makes it harder
36
- # to scan the code and see where the sections are.
37
31
  AccessModifierIndentation:
38
32
  Enabled: false
39
33
 
@@ -61,10 +55,6 @@ DotPosition:
61
55
  Encoding:
62
56
  Enabled: false
63
57
 
64
- # Enforce outdenting of access modifiers (i.e. public, private, protected)
65
- AccessModifierIndentation:
66
- EnforcedStyle: outdent
67
-
68
58
  EmptyLinesAroundAccessModifier:
69
59
  Enabled: true
70
60
 
@@ -1,6 +1,9 @@
1
+ require 'agile_utils'
1
2
  require 'thor'
2
3
  module <%= MiscUtils.camel_case(name) %>
3
4
  class CLI < Thor
5
+ using AgileUtils::HashExt
6
+
4
7
  desc 'execute', 'Execute the main program'
5
8
  method_option 'version',
6
9
  aliases: '-v',
@@ -18,7 +21,7 @@ module <%= MiscUtils.camel_case(name) %>
18
21
  desc 'usage', 'Display help screen'
19
22
  def usage
20
23
  puts <<-EOS
21
- Add your sample usage here!
24
+ TODO: Add your sample usage here
22
25
  EOS
23
26
  end
24
27
 
@@ -1,3 +1,3 @@
1
1
  module <%= MiscUtils.camel_case(name) %>
2
- VERSION = '0.0.1'
2
+ VERSION = '0.1.0'
3
3
  end
@@ -2,5 +2,4 @@ require_relative '<%= name %>/version'
2
2
  require_relative '<%= name %>/logger'
3
3
  require_relative '<%= name %>/<%= name %>'
4
4
  require_relative '<%= name %>/cli'
5
- require_relative '<%= name %>/core_ext/hash/keys'
6
5
  include <%= MiscUtils.camel_case(name) %>
@@ -15,16 +15,17 @@ Gem::Specification.new do |spec|
15
15
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
16
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
17
  spec.require_paths = ['lib']
18
- spec.add_runtime_dependency 'thor', '~> 0.19'
19
- spec.add_development_dependency 'awesome_print', '~> 1.2'
20
- spec.add_development_dependency 'bundler', '~> 1.5'
21
- spec.add_development_dependency 'gem-ctags', '~> 1.0'
22
- spec.add_development_dependency 'guard', '~> 2.6'
23
- spec.add_development_dependency 'guard-minitest', '~> 2.2'
24
- spec.add_development_dependency 'minitest', '~> 5.3'
18
+ spec.add_runtime_dependency 'thor', '~> 0.19.1'
19
+ spec.add_runtime_dependency 'agile_utils', '~> 0.2.0'
20
+ spec.add_development_dependency 'awesome_print', '~> 1.2.0'
21
+ spec.add_development_dependency 'bundler', '~> 1.6.2'
22
+ spec.add_development_dependency 'gem-ctags', '~> 1.0.6'
23
+ spec.add_development_dependency 'guard', '~> 2.6.1'
24
+ spec.add_development_dependency 'guard-minitest', '~> 2.3.1'
25
+ spec.add_development_dependency 'minitest', '~> 5.4.0'
25
26
  spec.add_development_dependency 'minitest-spec-context', '~> 0.0.3'
26
- spec.add_development_dependency 'pry', '~> 0.9'
27
- spec.add_development_dependency 'rake', '~> 10.1'
28
- spec.add_development_dependency 'rubocop', '~> 0.23'
29
- spec.add_development_dependency 'yard', '~> 0.8'
27
+ spec.add_development_dependency 'pry', '~> 0.10.0'
28
+ spec.add_development_dependency 'rake', '~> 10.3.2'
29
+ spec.add_development_dependency 'rubocop', '~> 0.24.0'
30
+ spec.add_development_dependency 'yard', '~> 0.8.7'
30
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gem_bootstrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Burin Choomnuan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-04 00:00:00.000000000 Z
11
+ date: 2014-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -16,84 +16,98 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.19'
19
+ version: 0.19.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.19'
26
+ version: 0.19.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: grit
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.5'
33
+ version: 2.5.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '2.5'
40
+ version: 2.5.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: agile_utils
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.2.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.2.0
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: awesome_print
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: '1.2'
61
+ version: 1.2.0
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: '1.2'
68
+ version: 1.2.0
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: bundler
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: '1.6'
75
+ version: 1.6.2
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: '1.6'
82
+ version: 1.6.2
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: gem-ctags
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: '1.0'
89
+ version: 1.0.6
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: '1.0'
96
+ version: 1.0.6
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: minitest
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
101
  - - "~>"
88
102
  - !ruby/object:Gem::Version
89
- version: '5.3'
103
+ version: 5.4.0
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
108
  - - "~>"
95
109
  - !ruby/object:Gem::Version
96
- version: '5.3'
110
+ version: 5.4.0
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: minitest-spec-context
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -114,70 +128,70 @@ dependencies:
114
128
  requirements:
115
129
  - - "~>"
116
130
  - !ruby/object:Gem::Version
117
- version: '2.6'
131
+ version: 2.6.1
118
132
  type: :development
119
133
  prerelease: false
120
134
  version_requirements: !ruby/object:Gem::Requirement
121
135
  requirements:
122
136
  - - "~>"
123
137
  - !ruby/object:Gem::Version
124
- version: '2.6'
138
+ version: 2.6.1
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: guard-minitest
127
141
  requirement: !ruby/object:Gem::Requirement
128
142
  requirements:
129
143
  - - "~>"
130
144
  - !ruby/object:Gem::Version
131
- version: '2.2'
145
+ version: 2.3.1
132
146
  type: :development
133
147
  prerelease: false
134
148
  version_requirements: !ruby/object:Gem::Requirement
135
149
  requirements:
136
150
  - - "~>"
137
151
  - !ruby/object:Gem::Version
138
- version: '2.2'
152
+ version: 2.3.1
139
153
  - !ruby/object:Gem::Dependency
140
154
  name: pry
141
155
  requirement: !ruby/object:Gem::Requirement
142
156
  requirements:
143
157
  - - "~>"
144
158
  - !ruby/object:Gem::Version
145
- version: '0.9'
159
+ version: 0.10.0
146
160
  type: :development
147
161
  prerelease: false
148
162
  version_requirements: !ruby/object:Gem::Requirement
149
163
  requirements:
150
164
  - - "~>"
151
165
  - !ruby/object:Gem::Version
152
- version: '0.9'
166
+ version: 0.10.0
153
167
  - !ruby/object:Gem::Dependency
154
168
  name: rake
155
169
  requirement: !ruby/object:Gem::Requirement
156
170
  requirements:
157
171
  - - "~>"
158
172
  - !ruby/object:Gem::Version
159
- version: '10.3'
173
+ version: 10.3.2
160
174
  type: :development
161
175
  prerelease: false
162
176
  version_requirements: !ruby/object:Gem::Requirement
163
177
  requirements:
164
178
  - - "~>"
165
179
  - !ruby/object:Gem::Version
166
- version: '10.3'
180
+ version: 10.3.2
167
181
  - !ruby/object:Gem::Dependency
168
182
  name: rubocop
169
183
  requirement: !ruby/object:Gem::Requirement
170
184
  requirements:
171
185
  - - "~>"
172
186
  - !ruby/object:Gem::Version
173
- version: '0.23'
187
+ version: 0.24.1
174
188
  type: :development
175
189
  prerelease: false
176
190
  version_requirements: !ruby/object:Gem::Requirement
177
191
  requirements:
178
192
  - - "~>"
179
193
  - !ruby/object:Gem::Version
180
- version: '0.23'
194
+ version: 0.24.1
181
195
  - !ruby/object:Gem::Dependency
182
196
  name: yard
183
197
  requirement: !ruby/object:Gem::Requirement
@@ -214,8 +228,6 @@ files:
214
228
  - gem_bootstrap.gemspec
215
229
  - lib/gem_bootstrap.rb
216
230
  - lib/gem_bootstrap/cli.rb
217
- - lib/gem_bootstrap/core_ext/hash/keys.rb
218
- - lib/gem_bootstrap/core_ext/object/blank.rb
219
231
  - lib/gem_bootstrap/gem_bootstrap.rb
220
232
  - lib/gem_bootstrap/git_utils.rb
221
233
  - lib/gem_bootstrap/misc_utils.rb
@@ -233,7 +245,6 @@ files:
233
245
  - templates/dot_yardopts
234
246
  - templates/lib/newgem.rb
235
247
  - templates/lib/newgem/cli.rb
236
- - templates/lib/newgem/core_ext/hash/keys.rb
237
248
  - templates/lib/newgem/logger.rb
238
249
  - templates/lib/newgem/newgem.rb
239
250
  - templates/lib/newgem/version.rb
@@ -1,54 +0,0 @@
1
- class Hash
2
- # from: activesupport/lib/active_support/core_ext/hash/keys.rb
3
- #
4
- # hash = { name: 'Rob', age: '28' }
5
- # hash.transform_keys{ |key| key.to_s.upcase }
6
- # => { "NAME" => "Rob", "AGE" => "28" }
7
- def transform_keys
8
- result = {}
9
- each_key do |key|
10
- result[yield(key)] = self[key]
11
- end
12
- result
13
- end
14
-
15
- def transform_keys!(&block)
16
- keys.each do |key|
17
- value = delete(key)
18
- self[yield(key)] = value.is_a?(Hash) ? value.transform_keys!(&block) : value
19
- end
20
- self
21
- end
22
-
23
- # hash = { 'name' => 'Rob', 'age' => '28' }
24
- # hash.symbolize_keys
25
- # => { name: "Rob", age: "28" }
26
- def symbolize_keys
27
- transform_keys { |key| key.to_sym rescue key }
28
- end
29
-
30
- # from: activesupport/lib/active_support/core_ext/hash/keys.rb, line 135
31
- def symbolize_keys!
32
- transform_keys! { |key| key.to_sym rescue key }
33
- end
34
-
35
- # Merges the caller into +other_hash+. For example,
36
- #
37
- # options = options.reverse_merge(size: 25, velocity: 10)
38
- #
39
- # is equivalent to
40
- #
41
- # options = { size: 25, velocity: 10 }.merge(options)
42
- #
43
- # This is particularly useful for initializing an options hash
44
- # with default values.
45
- def reverse_merge(other_hash)
46
- other_hash.merge(self)
47
- end
48
-
49
- # Destructive +reverse_merge+.
50
- def reverse_merge!(other_hash)
51
- # right wins if there is no left
52
- merge!(other_hash) { |_key, left, _right| left }
53
- end
54
- end
@@ -1,105 +0,0 @@
1
- # encoding: utf-8
2
- # from: active_support/core_ext/object/blank.rb
3
- class Object
4
- # An object is blank if it's false, empty, or a whitespace string.
5
- # For example, '', ' ', +nil+, [], and {} are all blank.
6
- #
7
- # This simplifies:
8
- #
9
- # if address.nil? || address.empty?
10
- #
11
- # ...to:
12
- #
13
- # if address.blank?
14
- def blank?
15
- respond_to?(:empty?) ? empty? : !self
16
- end
17
-
18
- # An object is present if it's not <tt>blank?</tt>.
19
- def present?
20
- !blank?
21
- end
22
-
23
- # Returns object if it's <tt>present?</tt> otherwise returns +nil+.
24
- # <tt>object.presence</tt> is equivalent to <tt>object.present? ? object : nil</tt>.
25
- #
26
- # This is handy for any representation of objects where blank is the same
27
- # as not present at all. For example, this simplifies a common check for
28
- # HTTP POST/query parameters:
29
- #
30
- # state = params[:state] if params[:state].present?
31
- # country = params[:country] if params[:country].present?
32
- # region = state || country || 'US'
33
- #
34
- # ...becomes:
35
- #
36
- # region = params[:state].presence || params[:country].presence || 'US'
37
- def presence
38
- self if present?
39
- end
40
- end
41
-
42
- class NilClass
43
- # +nil+ is blank:
44
- #
45
- # nil.blank? # => true
46
- def blank?
47
- true
48
- end
49
- end
50
-
51
- class FalseClass
52
- # +false+ is blank:
53
- #
54
- # false.blank? # => true
55
- def blank?
56
- true
57
- end
58
- end
59
-
60
- class TrueClass
61
- # +true+ is not blank:
62
- #
63
- # true.blank? # => false
64
- def blank?
65
- false
66
- end
67
- end
68
-
69
- class Array
70
- # An array is blank if it's empty:
71
- #
72
- # [].blank? # => true
73
- # [1,2,3].blank? # => false
74
- alias_method :blank?, :empty?
75
- end
76
-
77
- class Hash
78
- # A hash is blank if it's empty:
79
- #
80
- # {}.blank? # => true
81
- # { key: 'value' }.blank? # => false
82
- alias_method :blank?, :empty?
83
- end
84
-
85
- class String
86
- # A string is blank if it's empty or contains whitespaces only:
87
- #
88
- # ''.blank? # => true
89
- # ' '.blank? # => true
90
- # ' '.blank? # => true
91
- # ' something here '.blank? # => false
92
- def blank?
93
- self !~ /[^[:space:]]/
94
- end
95
- end
96
-
97
- class Numeric #:nodoc:
98
- # No number is blank:
99
- #
100
- # 1.blank? # => false
101
- # 0.blank? # => false
102
- def blank?
103
- false
104
- end
105
- end
@@ -1,54 +0,0 @@
1
- class Hash
2
- # File activesupport/lib/active_support/core_ext/hash/keys.rb
3
- #
4
- # hash = { name: 'Rob', age: '28' }
5
- # hash.transform_keys{ |key| key.to_s.upcase }
6
- # => { "NAME" => "Rob", "AGE" => "28" }
7
- def transform_keys
8
- result = {}
9
- each_key do |key|
10
- result[yield(key)] = self[key]
11
- end
12
- result
13
- end
14
-
15
- def transform_keys!(&block)
16
- keys.each do |key|
17
- value = delete(key)
18
- self[yield(key)] = value.is_a?(Hash) ? value.transform_keys!(&block) : value
19
- end
20
- self
21
- end
22
-
23
- # hash = { 'name' => 'Rob', 'age' => '28' }
24
- # hash.symbolize_keys
25
- # => { name: "Rob", age: "28" }
26
- def symbolize_keys
27
- transform_keys { |key| key.to_sym rescue key }
28
- end
29
-
30
- # File activesupport/lib/active_support/core_ext/hash/keys.rb, line 135
31
- def symbolize_keys!
32
- transform_keys! { |key| key.to_sym rescue key }
33
- end
34
-
35
- # Merges the caller into +other_hash+. For example,
36
- #
37
- # options = options.reverse_merge(size: 25, velocity: 10)
38
- #
39
- # is equivalent to
40
- #
41
- # options = { size: 25, velocity: 10 }.merge(options)
42
- #
43
- # This is particularly useful for initializing an options hash
44
- # with default values.
45
- def reverse_merge(other_hash)
46
- other_hash.merge(self)
47
- end
48
-
49
- # Destructive +reverse_merge+.
50
- def reverse_merge!(other_hash)
51
- # right wins if there is no left
52
- merge!(other_hash) { |_key, left, _right| left }
53
- end
54
- end