lib/ruby-rails-extensions.rb in ruby-rails-extensions-2.1.0.pre.rc.8 vs lib/ruby-rails-extensions.rb in ruby-rails-extensions-2.1.0.pre.rc.9
- old
+ new
@@ -109,17 +109,19 @@
def flag_name(gem_base)
self.class.flag_name(gem_base)
end
end
+ module_function
+
# @return [Configuration]
- def self.configuration
+ def configuration
@configuration ||= Configuration.new
end
# @yield [Configuration]
- def self.configure
+ def configure
yield(configuration)
Configuration::BOOLEAN_GEMS.each do |extension|
next unless configuration.public_send(:"#{extension}?")
@@ -130,7 +132,32 @@
# @return [Array<Symbol>]
def configuration_flags
configuration.flags
end
- module_function :configuration_flags
+ # @see Object#presence from active_support/core_ext/object/blank.rb
+ def presence(*items)
+ items.each do |item|
+ return item if present?(item)
+ end
+
+ nil
+ end
+
+ # @see Object#blank? from active_support/core_ext/object/blank.rb
+ def blank?(item)
+ if item.respond_to?(:blank?)
+ return item.blank?
+ end
+
+ item.respond_to?(:empty?) ? !!item.empty? : !item
+ end
+
+ # @see Object#present? from active_support/core_ext/object/blank.rb
+ def present?(item)
+ if item.respond_to?(:present?)
+ return item.present?
+ end
+
+ !blank?(item)
+ end
end