Module: Mongory::Utils
- Included in:
- Matchers::AbstractMatcher, QueryBuilder
- Defined in:
- lib/mongory/utils.rb,
lib/mongory/utils/context.rb,
lib/mongory/utils/debugger.rb,
lib/mongory/utils/rails_patch.rb,
lib/mongory/utils/singleton_builder.rb
Overview
Utility helpers shared across Mongory internals.
Includes blank checking, present checking, and class-level instance method caching.
Defined Under Namespace
Modules: ClassMethods, RailsPatch Classes: Context, Debugger, SingletonBuilder
Class Method Summary collapse
-
.included(base) ⇒ Object
When included, also extends the including class with ClassMethods.
-
.included_classes ⇒ Array
Where to record classes that include Utils.
Instance Method Summary collapse
-
#is_blank?(obj) ⇒ Boolean
Determines whether an object is considered "blank".
-
#is_present?(obj) ⇒ Boolean
Checks if an object is "present".
Class Method Details
.included(base) ⇒ Object
When included, also extends the including class with ClassMethods. And record which class include this module.
18 19 20 21 22 |
# File 'lib/mongory/utils.rb', line 18 def self.included(base) base.extend(ClassMethods) super included_classes << base end |
.included_classes ⇒ Array
Where to record classes that include Utils.
27 28 29 |
# File 'lib/mongory/utils.rb', line 27 def self.included_classes @included_classes ||= [] end |
Instance Method Details
#is_blank?(obj) ⇒ Boolean
Determines whether an object is considered "blank". Nil, false, empty string/array/hash are blank.
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/mongory/utils.rb', line 45 def is_blank?(obj) case obj when false, nil true when Hash, Array, String obj.empty? else false end end |
#is_present?(obj) ⇒ Boolean
Checks if an object is "present". Inverse of #is_blank?.
36 37 38 |
# File 'lib/mongory/utils.rb', line 36 def is_present?(obj) !is_blank?(obj) end |