Module: Vagrant::Util::Presence
- Extended by:
- Presence
- Included in:
- Action::General::PackageSetupFolders, Presence
- Defined in:
- lib/vagrant/util/presence.rb
Instance Method Summary collapse
-
#presence(obj) ⇒ Object, false
Returns the presence of the object.
-
#present?(obj) ⇒ true, false
Determines if the given object is "present".
Instance Method Details
#presence(obj) ⇒ Object, false
Returns the presence of the object. If the object is #present?, it is
returned. Otherwise false
is returned.
39 40 41 42 43 44 45 |
# File 'lib/vagrant/util/presence.rb', line 39 def presence(obj) if present?(obj) obj else false end end |
#present?(obj) ⇒ true, false
Determines if the given object is "present". A String is considered
present if the stripped contents are not empty. An Array/Hash is
considered present if they have a length of more than 1. "true" is
always present and false
and nil
are always not present. Any other
object is considered to be present.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/vagrant/util/presence.rb', line 16 def present?(obj) case obj when String !obj.strip.empty? when Symbol !obj.to_s.strip.empty? when Array !obj.compact.empty? when Hash !obj.empty? when TrueClass, FalseClass obj when NilClass false when Object true end end |