doc_raptor 0.2.1 → 0.2.2
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/Changelog.md +3 -0
- data/lib/core_ext/object/blank.rb +113 -0
- metadata +4 -3
data/Changelog.md
CHANGED
@@ -0,0 +1,113 @@
|
|
1
|
+
unless Object.new.respond_to? :blank?
|
2
|
+
# this is taken directly from activesupport 3.1.1
|
3
|
+
# we won't redo all this unless we need to
|
4
|
+
class Object
|
5
|
+
# An object is blank if it's false, empty, or a whitespace string.
|
6
|
+
# For example, "", " ", +nil+, [], and {} are all blank.
|
7
|
+
#
|
8
|
+
# This simplifies:
|
9
|
+
#
|
10
|
+
# if address.nil? || address.empty?
|
11
|
+
#
|
12
|
+
# ...to:
|
13
|
+
#
|
14
|
+
# if address.blank?
|
15
|
+
def blank?
|
16
|
+
respond_to?(:empty?) ? empty? : !self
|
17
|
+
end
|
18
|
+
|
19
|
+
# An object is present if it's not <tt>blank?</tt>.
|
20
|
+
def present?
|
21
|
+
!blank?
|
22
|
+
end
|
23
|
+
|
24
|
+
# Returns object if it's <tt>present?</tt> otherwise returns +nil+.
|
25
|
+
# <tt>object.presence</tt> is equivalent to <tt>object.present? ? object : nil</tt>.
|
26
|
+
#
|
27
|
+
# This is handy for any representation of objects where blank is the same
|
28
|
+
# as not present at all. For example, this simplifies a common check for
|
29
|
+
# HTTP POST/query parameters:
|
30
|
+
#
|
31
|
+
# state = params[:state] if params[:state].present?
|
32
|
+
# country = params[:country] if params[:country].present?
|
33
|
+
# region = state || country || 'US'
|
34
|
+
#
|
35
|
+
# ...becomes:
|
36
|
+
#
|
37
|
+
# region = params[:state].presence || params[:country].presence || 'US'
|
38
|
+
def presence
|
39
|
+
self if present?
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class NilClass
|
44
|
+
# +nil+ is blank:
|
45
|
+
#
|
46
|
+
# nil.blank? # => true
|
47
|
+
#
|
48
|
+
def blank?
|
49
|
+
true
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class FalseClass
|
54
|
+
# +false+ is blank:
|
55
|
+
#
|
56
|
+
# false.blank? # => true
|
57
|
+
#
|
58
|
+
def blank?
|
59
|
+
true
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
class TrueClass
|
64
|
+
# +true+ is not blank:
|
65
|
+
#
|
66
|
+
# true.blank? # => false
|
67
|
+
#
|
68
|
+
def blank?
|
69
|
+
false
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
class Array
|
74
|
+
# An array is blank if it's empty:
|
75
|
+
#
|
76
|
+
# [].blank? # => true
|
77
|
+
# [1,2,3].blank? # => false
|
78
|
+
#
|
79
|
+
alias_method :blank?, :empty?
|
80
|
+
end
|
81
|
+
|
82
|
+
class Hash
|
83
|
+
# A hash is blank if it's empty:
|
84
|
+
#
|
85
|
+
# {}.blank? # => true
|
86
|
+
# {:key => 'value'}.blank? # => false
|
87
|
+
#
|
88
|
+
alias_method :blank?, :empty?
|
89
|
+
end
|
90
|
+
|
91
|
+
class String
|
92
|
+
# A string is blank if it's empty or contains whitespaces only:
|
93
|
+
#
|
94
|
+
# "".blank? # => true
|
95
|
+
# " ".blank? # => true
|
96
|
+
# " something here ".blank? # => false
|
97
|
+
#
|
98
|
+
def blank?
|
99
|
+
self !~ /\S/
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
class Numeric #:nodoc:
|
104
|
+
# No number is blank:
|
105
|
+
#
|
106
|
+
# 1.blank? # => false
|
107
|
+
# 0.blank? # => false
|
108
|
+
#
|
109
|
+
def blank?
|
110
|
+
false
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: doc_raptor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 2
|
10
|
+
version: 0.2.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Michael Kuehl
|
@@ -49,6 +49,7 @@ files:
|
|
49
49
|
- README.md
|
50
50
|
- MIT-LICENSE
|
51
51
|
- lib/doc_raptor.rb
|
52
|
+
- lib/core_ext/object/blank.rb
|
52
53
|
has_rdoc: true
|
53
54
|
homepage: http://docraptor.com
|
54
55
|
licenses: []
|