Module: Lazier
- Defined in:
- lib/lazier.rb,
lib/lazier/hash.rb,
lib/lazier/i18n.rb,
lib/lazier/math.rb,
lib/lazier/object.rb,
lib/lazier/string.rb,
lib/lazier/boolean.rb,
lib/lazier/version.rb,
lib/lazier/datetime.rb,
lib/lazier/pathname.rb,
lib/lazier/settings.rb,
lib/lazier/localizer.rb,
lib/lazier/exceptions.rb,
lib/lazier/configuration.rb
Overview
This file is part of the lazier gem. Copyright (C) 2013 and above Shogun [email protected]. Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
Defined Under Namespace
Modules: Boolean, DateTime, Exceptions, Hash, I18n, Math, Object, Pathname, String, TimeZone, Version Classes: Configuration, Localizer, Settings
Class Method Summary collapse
-
.benchmark(message = nil, precision = 0, &block) ⇒ Float|String
Measure the time in milliseconds required to execute the given block.
-
.find_class(cls, scope = "::%CLASS%", only_in_scope = false) ⇒ Class
Finds a class to instantiate.
-
.load!(*what) ⇒ Settings
Loads the extensions.
-
.load_boolean ⇒ Object
Loads Boolean extensions.
-
.load_datetime ⇒ Object
Loads DateTime extensions.
-
.load_hash ⇒ Object
Loads Hash extensions.
-
.load_hash_method_access ⇒ Object
Loads Hash method access extensions.
-
.load_math ⇒ Object
Loads Math extensions.
-
.load_object ⇒ Object
Loads Object extensions.
-
.load_pathname ⇒ Object
Loads Pathname extensions.
-
.load_string ⇒ Object
Loads String extensions.
-
.settings ⇒ Settings
Returns the settings for the extensions.
Class Method Details
.benchmark(message = nil, precision = 0, &block) ⇒ Float|String
Measure the time in milliseconds required to execute the given block.
139 140 141 142 |
# File 'lib/lazier.rb', line 139 def self.benchmark( = nil, precision = 0, &block) rv = Benchmark.ms(&block) ? format("%s (%0.#{precision}f ms)", , rv) : rv end |
.find_class(cls, scope = "::%CLASS%", only_in_scope = false) ⇒ Class
Finds a class to instantiate.
122 123 124 125 126 127 128 129 130 |
# File 'lib/lazier.rb', line 122 def self.find_class(cls, scope = "::%CLASS%", only_in_scope = false) if cls.is_a?(::String) || cls.is_a?(::Symbol) rv, cls = perform_initial_class_search(cls, only_in_scope) rv = search_class_inside_scope(rv, cls, scope) # Search inside scope rv || raise(NameError.new("", cls)) else cls.is_a?(::Class) ? cls : cls.class end end |
.load!(*what) ⇒ Settings
Loads the extensions.
50 51 52 53 54 55 56 |
# File 'lib/lazier.rb', line 50 def self.load!(*what) modules = what.present? ? what.flatten.uniq.compact.map(&:to_s) : %w(object boolean string hash datetime math pathname) modules.each { |w| ::Lazier.send("load_#{w}") } yield if block_given? ::Lazier::Settings.instance end |
.load_boolean ⇒ Object
Loads Boolean extensions.
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/lazier.rb', line 64 def self.load_boolean ::TrueClass.class_eval do include ::Lazier::Object include ::Lazier::Boolean end ::FalseClass.class_eval do include ::Lazier::Object include ::Lazier::Boolean end end |
.load_datetime ⇒ Object
Loads DateTime extensions.
93 94 95 96 97 98 99 100 101 |
# File 'lib/lazier.rb', line 93 def self.load_datetime Lazier.load_object [::Time, ::Date, ::DateTime].each do |c| c.class_eval { include ::Lazier::DateTime } end ::ActiveSupport::TimeZone.class_eval { include ::Lazier::TimeZone } end |
.load_hash ⇒ Object
Loads Hash extensions.
82 83 84 85 |
# File 'lib/lazier.rb', line 82 def self.load_hash clean_hash_compact ::Hash.class_eval { include ::Lazier::Hash } end |
.load_hash_method_access ⇒ Object
Loads Hash method access extensions.
88 89 90 |
# File 'lib/lazier.rb', line 88 def self.load_hash_method_access ::Hash.class_eval { include Hashie::Extensions::MethodAccess } end |
.load_math ⇒ Object
Loads Math extensions.
104 105 106 107 |
# File 'lib/lazier.rb', line 104 def self.load_math Lazier.load_object ::Math.class_eval { include ::Lazier::Math } end |
.load_object ⇒ Object
Loads Object extensions.
59 60 61 |
# File 'lib/lazier.rb', line 59 def self.load_object ::Object.class_eval { include ::Lazier::Object } end |
.load_pathname ⇒ Object
Loads Pathname extensions.
110 111 112 113 |
# File 'lib/lazier.rb', line 110 def self.load_pathname require "pathname" ::Pathname.class_eval { include ::Lazier::Pathname } end |
.load_string ⇒ Object
Loads String extensions.
77 78 79 |
# File 'lib/lazier.rb', line 77 def self.load_string ::String.class_eval { include ::Lazier::String } end |
.settings ⇒ Settings
Returns the settings for the extensions.
33 34 35 |
# File 'lib/lazier.rb', line 33 def self.settings ::Lazier::Settings.instance end |