agile_utils 0.1.5 → 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: f50e652ce299a2e408bd3a6f52854701dfa9a2b6
4
- data.tar.gz: e1caa27c97160b4832741ef51df9c56a999ff2a0
3
+ metadata.gz: cbfe4f818d75485cb60f065b5f6bcd6e5af37a59
4
+ data.tar.gz: 68d753a3f94a3089e7de614718f769e7265d8867
5
5
  SHA512:
6
- metadata.gz: 9a8aff4fc72070fbab97a0037f06ec37fe1200eb1cf28ec8ad87efcd21835c1b48b3b104bf425e368b5f64c6709e3d7d63e4b39b6ae73e88ad249cee39804059
7
- data.tar.gz: a3e2e44119e65efaa3eb13904c4558771fe21b41fa0f8edd6cc836579a2864f4cb4d7cc5bfe5e064d57b8a94b5053ec798a2845f392a11c6595972969794f837
6
+ metadata.gz: 76c7b1f736db7abe171669e5b0dec378a683a47c1c9c2965e8ed5c4c8263c50da36b4a58664070c32a2b06264bd8b757d4e2350ceb5a451c78f53a9be41140b3
7
+ data.tar.gz: 845e1a57084eb392c6c370c0fefa9272040b867bf839135df3a1e32a108eb711af7182249a5bdc7989f0762475a9ab808645e42d7a27b281b05e631a1f586528
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ #### 0.2.0
2
+
3
+ - Remove the monkeypatch and use 'refinement' feature of ruby 2.1.x
4
+
1
5
  #### 0.1.5
2
6
 
3
7
  - Organize the core_ext class
data/Rakefile CHANGED
@@ -1,6 +1,5 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rake/testtask"
3
-
4
3
  project_name = "agile_utils"
5
4
 
6
5
  Rake::TestTask.new do |t|
@@ -8,7 +7,9 @@ Rake::TestTask.new do |t|
8
7
  t.test_files = FileList["test/lib/#{project_name}/test_*.rb"]
9
8
  t.verbose = true
10
9
  end
10
+
11
11
  task default: :test
12
+
12
13
  task :pry do
13
14
  require "pry"
14
15
  require "awesome_print"
data/bin/agile_utils CHANGED
@@ -1,9 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- # Add the code for binary if we need one
3
2
  require_relative "../lib/agile_utils"
4
3
  include AgileUtils
5
- if ARGV.empty?
6
- AgileUtils::CLI.start(%w[usage])
7
- else
8
- AgileUtils::CLI.start(%w[main].concat(ARGV))
9
- end
4
+ AgileUtils::CLI.start(%w[usage])
data/lib/agile_utils.rb CHANGED
@@ -1,6 +1,6 @@
1
- require_relative "./agile_utils/core_ext/all"
2
1
  require_relative "./agile_utils/version"
3
- require_relative "./agile_utils/logger"
2
+ require_relative "./agile_utils/core_ext/blank_ext"
3
+ require_relative "./agile_utils/core_ext/hash_ext"
4
4
  require_relative "./agile_utils/cli"
5
5
  require_relative "./agile_utils/helper"
6
6
  require_relative "./agile_utils/file_util"
@@ -6,7 +6,7 @@ module AgileUtils
6
6
  aliases: "-b",
7
7
  desc: "Base directory",
8
8
  default: Dir.pwd
9
- }
9
+ }
10
10
  ]
11
11
 
12
12
  EXTS = [
@@ -31,7 +31,8 @@ module AgileUtils
31
31
  { type: :array,
32
32
  aliases: "-n",
33
33
  desc: "List of words in the filename to be included with the result if any",
34
- default: [] }
34
+ default: []
35
+ }
35
36
  ]
36
37
 
37
38
  EXC_WORDS = [
@@ -39,7 +40,8 @@ module AgileUtils
39
40
  { type: :array,
40
41
  aliases: "-x",
41
42
  desc: "List of words in the filename to be excluded from the result if any",
42
- default: [] }
43
+ default: []
44
+ }
43
45
  ]
44
46
 
45
47
  IGNORE_CASE = [
@@ -47,7 +49,8 @@ module AgileUtils
47
49
  { type: :boolean,
48
50
  aliases: "-i",
49
51
  desc: "Ignore the case in the input filename",
50
- default: true }
52
+ default: true
53
+ }
51
54
  ]
52
55
 
53
56
  RECURSIVE = [
@@ -55,7 +58,8 @@ module AgileUtils
55
58
  { type: :boolean,
56
59
  aliases: "-r",
57
60
  desc: "Search for files recursively",
58
- default: true }
61
+ default: true
62
+ }
59
63
  ]
60
64
 
61
65
  VERSION = [
@@ -63,7 +67,8 @@ module AgileUtils
63
67
  { type: :boolean,
64
68
  aliases: "-v",
65
69
  desc: "Display version information",
66
- default: false }
70
+ default: false
71
+ }
67
72
  ]
68
73
  end
69
74
  end
@@ -1,23 +1,9 @@
1
1
  require "thor"
2
- require_relative "../agile_utils"
3
2
  module AgileUtils
4
3
  class CLI < Thor
5
- desc "main", "Main entry point"
6
- def main
7
- opts = options.symbolize_keys
8
- if opts[:version]
9
- puts "You are using AgileUtils version #{AgileUtils::VERSION}"
10
- exit
11
- end
12
- end
13
4
  desc "usage", "Display help screen"
14
5
  def usage
15
6
  puts <<-EOS
16
- # List of available APIs
17
- require 'agile_utils'
18
- include AgileUtils
19
-
20
- # General methods
21
7
  AgileUtils::Helper.capture
22
8
  AgileUtils::Helper.make_list
23
9
  AgileUtils::Helper.shell
@@ -31,7 +17,6 @@ AgileUtils::FileUtils.gunzip()
31
17
  AgileUtils::FileUtils.tar_gzip_files()
32
18
  EOS
33
19
  end
34
-
35
20
  default_task :usage
36
21
  end
37
22
  end
@@ -0,0 +1,109 @@
1
+ module AgileUtils
2
+ module BlankExt
3
+ # encoding: utf-8
4
+ # from: active_support/core_ext/object/blank.rb
5
+ refine Object do
6
+ # An object is blank if it's false, empty, or a whitespace string.
7
+ # For example, '', ' ', +nil+, [], and {} are all blank.
8
+ #
9
+ # This simplifies:
10
+ #
11
+ # if address.nil? || address.empty?
12
+ #
13
+ # ...to:
14
+ #
15
+ # if address.blank?
16
+ def blank?
17
+ respond_to?(:empty?) ? empty? : !self
18
+ end
19
+
20
+ # An object is present if it's not <tt>blank?</tt>.
21
+ def present?
22
+ !blank?
23
+ end
24
+
25
+ # Returns object if it's <tt>present?</tt> otherwise returns +nil+.
26
+ # <tt>object.presence</tt> is equivalent to <tt>object.present? ? object : nil</tt>.
27
+ #
28
+ # This is handy for any representation of objects where blank is the same
29
+ # as not present at all. For example, this simplifies a common check for
30
+ # HTTP POST/query parameters:
31
+ #
32
+ # state = params[:state] if params[:state].present?
33
+ # country = params[:country] if params[:country].present?
34
+ # region = state || country || 'US'
35
+ #
36
+ # ...becomes:
37
+ #
38
+ # region = params[:state].presence || params[:country].presence || 'US'
39
+ def presence
40
+ self if present?
41
+ end
42
+ end
43
+
44
+ refine NilClass do
45
+ # +nil+ is blank:
46
+ #
47
+ # nil.blank? # => true
48
+ def blank?
49
+ true
50
+ end
51
+ end
52
+
53
+ refine FalseClass do
54
+ # +false+ is blank:
55
+ #
56
+ # false.blank? # => true
57
+ def blank?
58
+ true
59
+ end
60
+ end
61
+
62
+ refine TrueClass do
63
+ # +true+ is not blank:
64
+ #
65
+ # true.blank? # => false
66
+ def blank?
67
+ false
68
+ end
69
+ end
70
+
71
+ refine Array do
72
+ # An array is blank if it's empty:
73
+ #
74
+ # [].blank? # => true
75
+ # [1,2,3].blank? # => false
76
+ alias_method :blank?, :empty?
77
+ end
78
+
79
+ refine Hash do
80
+ # A hash is blank if it's empty:
81
+ #
82
+ # {}.blank? # => true
83
+ # { key: 'value' }.blank? # => false
84
+ alias_method :blank?, :empty?
85
+ end
86
+
87
+ refine String do
88
+ # A string is blank if it's empty or contains whitespaces only:
89
+ #
90
+ # ''.blank? # => true
91
+ # ' '.blank? # => true
92
+ # ' '.blank? # => true
93
+ # ' something here '.blank? # => false
94
+ def blank?
95
+ self !~ /[^[:space:]]/
96
+ end
97
+ end
98
+
99
+ refine Numeric do #:nodoc:
100
+ # No number is blank:
101
+ #
102
+ # 1.blank? # => false
103
+ # 0.blank? # => false
104
+ def blank?
105
+ false
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,58 @@
1
+ module AgileUtils
2
+ module HashExt
3
+ refine Hash do
4
+ # File activesupport/lib/active_support/core_ext/hash/keys.rb
5
+ #
6
+ # hash = { name: 'Rob', age: '28' }
7
+ # hash.transform_keys{ |key| key.to_s.upcase }
8
+ # => { "NAME" => "Rob", "AGE" => "28" }
9
+ def transform_keys
10
+ result = {}
11
+ each_key do |key|
12
+ result[yield(key)] = self[key]
13
+ end
14
+ result
15
+ end
16
+
17
+ def transform_keys!(&block)
18
+ keys.each do |key|
19
+ value = delete(key)
20
+ self[yield(key)] = value.is_a?(Hash) ? value.transform_keys!(&block) : value
21
+ end
22
+ self
23
+ end
24
+
25
+ # hash = { 'name' => 'Rob', 'age' => '28' }
26
+ # hash.symbolize_keys
27
+ # => { name: "Rob", age: "28" }
28
+ def symbolize_keys
29
+ transform_keys { |key| key.to_sym rescue key }
30
+ end
31
+
32
+ # File activesupport/lib/active_support/core_ext/hash/keys.rb, line 135
33
+ def symbolize_keys!
34
+ transform_keys! { |key| key.to_sym rescue key }
35
+ end
36
+
37
+ # Merges the caller into +other_hash+. For example,
38
+ #
39
+ # options = options.reverse_merge(size: 25, velocity: 10)
40
+ #
41
+ # is equivalent to
42
+ #
43
+ # options = { size: 25, velocity: 10 }.merge(options)
44
+ #
45
+ # This is particularly useful for initializing an options hash
46
+ # with default values.
47
+ def reverse_merge(other_hash)
48
+ other_hash.merge(self)
49
+ end
50
+
51
+ # Destructive +reverse_merge+.
52
+ def reverse_merge!(other_hash)
53
+ # right wins if there is no left
54
+ merge!(other_hash) { |key, left, right| left }
55
+ end
56
+ end
57
+ end
58
+ end
@@ -1,3 +1,3 @@
1
1
  module AgileUtils
2
- VERSION = "0.1.5"
2
+ VERSION = "0.2.0"
3
3
  end
data/test/test_helper.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require "minitest"
1
2
  require "minitest/autorun"
2
3
  require "minitest/pride"
3
4
  require "minitest-spec-context"
metadata CHANGED
@@ -1,195 +1,195 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: agile_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
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-23 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
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0.19'
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
26
  version: '0.19'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: minitar
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: 0.5.4
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
40
  version: 0.5.4
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
47
  version: '1.5'
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: '1.5'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
61
  version: '10.1'
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: '10.1'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: awesome_print
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ~>
74
74
  - !ruby/object:Gem::Version
75
75
  version: '1.2'
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: '1.2'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: minitest-spec-context
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - ~>
88
88
  - !ruby/object:Gem::Version
89
89
  version: 0.0.3
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "~>"
94
+ - - ~>
95
95
  - !ruby/object:Gem::Version
96
96
  version: 0.0.3
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: guard-minitest
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - "~>"
101
+ - - ~>
102
102
  - !ruby/object:Gem::Version
103
103
  version: '2.2'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - "~>"
108
+ - - ~>
109
109
  - !ruby/object:Gem::Version
110
110
  version: '2.2'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: minitest
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - "~>"
115
+ - - ~>
116
116
  - !ruby/object:Gem::Version
117
117
  version: '5.3'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - "~>"
122
+ - - ~>
123
123
  - !ruby/object:Gem::Version
124
124
  version: '5.3'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: guard
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - "~>"
129
+ - - ~>
130
130
  - !ruby/object:Gem::Version
131
131
  version: '2.6'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - "~>"
136
+ - - ~>
137
137
  - !ruby/object:Gem::Version
138
138
  version: '2.6'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: pry
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - "~>"
143
+ - - ~>
144
144
  - !ruby/object:Gem::Version
145
145
  version: 0.9.10
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - "~>"
150
+ - - ~>
151
151
  - !ruby/object:Gem::Version
152
152
  version: 0.9.10
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: gem-ctags
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
- - - "~>"
157
+ - - ~>
158
158
  - !ruby/object:Gem::Version
159
159
  version: '1.0'
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
- - - "~>"
164
+ - - ~>
165
165
  - !ruby/object:Gem::Version
166
166
  version: '1.0'
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: yard
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
- - - "~>"
171
+ - - ~>
172
172
  - !ruby/object:Gem::Version
173
173
  version: '0.8'
174
174
  type: :development
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
- - - "~>"
178
+ - - ~>
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0.8'
181
181
  - !ruby/object:Gem::Dependency
182
182
  name: rubocop
183
183
  requirement: !ruby/object:Gem::Requirement
184
184
  requirements:
185
- - - "~>"
185
+ - - ~>
186
186
  - !ruby/object:Gem::Version
187
187
  version: '0.23'
188
188
  type: :development
189
189
  prerelease: false
190
190
  version_requirements: !ruby/object:Gem::Requirement
191
191
  requirements:
192
- - - "~>"
192
+ - - ~>
193
193
  - !ruby/object:Gem::Version
194
194
  version: '0.23'
195
195
  description: My collection of library that I have used that can be shared across multiple
@@ -201,34 +201,31 @@ executables:
201
201
  extensions: []
202
202
  extra_rdoc_files: []
203
203
  files:
204
- - ".gitignore"
205
- - ".rubocop.yml"
206
- - CHANGELOG.md
207
- - Gemfile
208
- - LICENSE
209
- - README.md
210
- - Rakefile
211
- - agile_utils.gemspec
212
204
  - bin/agile_utils
213
205
  - lib/agile_utils.rb
214
- - lib/agile_utils/base_option.rb
215
- - lib/agile_utils/cli.rb
216
206
  - lib/agile_utils/constant.rb
217
- - lib/agile_utils/core_ext/all.rb
218
- - lib/agile_utils/core_ext/hash/hash.rb
219
- - lib/agile_utils/core_ext/kernel/reporting.rb
220
- - lib/agile_utils/core_ext/object/blank.rb
221
207
  - lib/agile_utils/file_util.rb
222
208
  - lib/agile_utils/helper.rb
223
- - lib/agile_utils/logger.rb
209
+ - lib/agile_utils/core_ext/hash_ext.rb
210
+ - lib/agile_utils/core_ext/blank_ext.rb
211
+ - lib/agile_utils/cli.rb
224
212
  - lib/agile_utils/version.rb
225
- - test/fixtures/inputs/demo1.xxx.rb
226
- - test/fixtures/inputs/demo2.xxx.rb
227
- - test/fixtures/outputs/demo1.xhtml
228
- - test/fixtures/outputs/demo2.xhtml
229
- - test/lib/agile_utils/test_file_util.rb
213
+ - lib/agile_utils/base_option.rb
214
+ - Gemfile
215
+ - Rakefile
216
+ - agile_utils.gemspec
217
+ - README.md
218
+ - CHANGELOG.md
219
+ - LICENSE
220
+ - .rubocop.yml
221
+ - .gitignore
230
222
  - test/lib/agile_utils/test_helper.rb
223
+ - test/lib/agile_utils/test_file_util.rb
231
224
  - test/test_helper.rb
225
+ - test/fixtures/outputs/demo1.xhtml
226
+ - test/fixtures/outputs/demo2.xhtml
227
+ - test/fixtures/inputs/demo2.xxx.rb
228
+ - test/fixtures/inputs/demo1.xxx.rb
232
229
  homepage: https://github.com/agilecreativity/agile_utils
233
230
  licenses:
234
231
  - MIT
@@ -239,17 +236,17 @@ require_paths:
239
236
  - lib
240
237
  required_ruby_version: !ruby/object:Gem::Requirement
241
238
  requirements:
242
- - - ">="
239
+ - - '>='
243
240
  - !ruby/object:Gem::Version
244
241
  version: '0'
245
242
  required_rubygems_version: !ruby/object:Gem::Requirement
246
243
  requirements:
247
- - - ">="
244
+ - - '>='
248
245
  - !ruby/object:Gem::Version
249
246
  version: '0'
250
247
  requirements: []
251
248
  rubyforge_project:
252
- rubygems_version: 2.2.2
249
+ rubygems_version: 2.0.14
253
250
  signing_key:
254
251
  specification_version: 4
255
252
  summary: Collection of my ruby library that can be re-used across projects
@@ -1,3 +0,0 @@
1
- require_relative "./hash/hash"
2
- require_relative "./kernel/reporting"
3
- require_relative "./object/blank"
@@ -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
@@ -1,36 +0,0 @@
1
- require "tempfile"
2
- module Kernel
3
- # From: 'activesupport-4.1.0/lib/active_support/core_ext/kernel/reporting.rb
4
- #
5
- # Captures the given stream and returns it:
6
- #
7
- # stream = capture(:stdout) { puts 'notice' }
8
- # stream # => "notice\n"
9
- #
10
- # stream = capture(:stderr) { warn 'error' }
11
- # stream # => "error\n"
12
- #
13
- # even for subprocesses:
14
- #
15
- # stream = capture(:stdout) { system('echo notice') }
16
- # stream # => "notice\n"
17
- #
18
- # stream = capture(:stderr) { system('echo error 1>&2') }
19
- # stream # => "error\n"
20
- def capture(stream)
21
- stream = stream.to_s
22
- captured_stream = Tempfile.new(stream)
23
- stream_io = eval("$#{stream}")
24
- origin_stream = stream_io.dup
25
- stream_io.reopen(captured_stream)
26
-
27
- yield
28
-
29
- stream_io.rewind
30
- return captured_stream.read
31
- ensure
32
- captured_stream.close
33
- captured_stream.unlink
34
- stream_io.reopen(origin_stream)
35
- end
36
- 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,10 +0,0 @@
1
- require "logger"
2
- module AgileUtils
3
- class << self
4
- attr_writer :logger
5
- # @return [Logger] the Logger for the project
6
- def logger
7
- @logger ||= Logger.new STDOUT
8
- end
9
- end
10
- end