agile_utils 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/agile_utils.rb +1 -2
- data/lib/agile_utils/core_ext/all.rb +3 -0
- data/lib/agile_utils/core_ext/object/blank.rb +105 -0
- data/lib/agile_utils/version.rb +1 -1
- metadata +9 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f50e652ce299a2e408bd3a6f52854701dfa9a2b6
|
4
|
+
data.tar.gz: e1caa27c97160b4832741ef51df9c56a999ff2a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a8aff4fc72070fbab97a0037f06ec37fe1200eb1cf28ec8ad87efcd21835c1b48b3b104bf425e368b5f64c6709e3d7d63e4b39b6ae73e88ad249cee39804059
|
7
|
+
data.tar.gz: a3e2e44119e65efaa3eb13904c4558771fe21b41fa0f8edd6cc836579a2864f4cb4d7cc5bfe5e064d57b8a94b5053ec798a2845f392a11c6595972969794f837
|
data/CHANGELOG.md
CHANGED
data/lib/agile_utils.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
require_relative "./agile_utils/core_ext/
|
2
|
-
require_relative "./agile_utils/core_ext/kernel/reporting"
|
1
|
+
require_relative "./agile_utils/core_ext/all"
|
3
2
|
require_relative "./agile_utils/version"
|
4
3
|
require_relative "./agile_utils/logger"
|
5
4
|
require_relative "./agile_utils/cli"
|
@@ -0,0 +1,105 @@
|
|
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
|
data/lib/agile_utils/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: agile_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
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-
|
11
|
+
date: 2014-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -214,8 +214,10 @@ files:
|
|
214
214
|
- lib/agile_utils/base_option.rb
|
215
215
|
- lib/agile_utils/cli.rb
|
216
216
|
- lib/agile_utils/constant.rb
|
217
|
+
- lib/agile_utils/core_ext/all.rb
|
217
218
|
- lib/agile_utils/core_ext/hash/hash.rb
|
218
219
|
- lib/agile_utils/core_ext/kernel/reporting.rb
|
220
|
+
- lib/agile_utils/core_ext/object/blank.rb
|
219
221
|
- lib/agile_utils/file_util.rb
|
220
222
|
- lib/agile_utils/helper.rb
|
221
223
|
- lib/agile_utils/logger.rb
|
@@ -252,11 +254,11 @@ signing_key:
|
|
252
254
|
specification_version: 4
|
253
255
|
summary: Collection of my ruby library that can be re-used across projects
|
254
256
|
test_files:
|
255
|
-
- test/fixtures/inputs/demo1.xxx.rb
|
256
|
-
- test/fixtures/inputs/demo2.xxx.rb
|
257
|
-
- test/fixtures/outputs/demo1.xhtml
|
258
|
-
- test/fixtures/outputs/demo2.xhtml
|
259
|
-
- test/lib/agile_utils/test_file_util.rb
|
260
257
|
- test/lib/agile_utils/test_helper.rb
|
258
|
+
- test/lib/agile_utils/test_file_util.rb
|
261
259
|
- test/test_helper.rb
|
260
|
+
- test/fixtures/outputs/demo1.xhtml
|
261
|
+
- test/fixtures/outputs/demo2.xhtml
|
262
|
+
- test/fixtures/inputs/demo2.xxx.rb
|
263
|
+
- test/fixtures/inputs/demo1.xxx.rb
|
262
264
|
has_rdoc:
|