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
Overview
This file is part of the lazier gem. Copyright (C) 2013 and above Shogun
Defined Under Namespace
Modules: Boolean, DateTime, Exceptions, Hash, I18n, Math, Object, Pathname, String, TimeZone, Version Classes: Localizer, Settings
Class Method Summary collapse
-
.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_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
.find_class(cls, scope = "::%CLASS%", only_in_scope = false) ⇒ Class
Finds a class to instantiate.
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/lazier.rb', line 114 def self.find_class(cls, scope = "::%CLASS%", only_in_scope = false) if cls.is_a?(::String) || cls.is_a?(::Symbol) then rv = nil cls = cls.to_s.camelize if only_in_scope then cls.gsub!(/^::/, "") # Mark only search only inside scope else rv = search_class(cls) # Search outside scope end rv = search_class(scope.to_s.gsub("%CLASS%", cls)) if !rv && cls !~ /^::/ && scope.present? # Search inside scope rv || raise(NameError.new("", cls)) else cls.is_a?(::Class) ? cls : cls.class end end |
.load!(*what) ⇒ Settings
Loads the extensions.
48 49 50 51 52 |
# File 'lib/lazier.rb', line 48 def self.load!(*what) (what.present? ? what : ["object", "boolean", "string", "hash", "datetime", "math", "pathname"]).each { |w| ::Lazier.send("load_#{w}") } yield if block_given? ::Lazier::Settings.instance end |
.load_boolean ⇒ Object
Loads Boolean extensions.
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/lazier.rb', line 60 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.
86 87 88 89 90 91 92 93 94 |
# File 'lib/lazier.rb', line 86 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.
78 79 80 81 82 83 |
# File 'lib/lazier.rb', line 78 def self.load_hash ::Hash.class_eval do include Hashie::Extensions::MethodAccess include ::Lazier::Hash end end |
.load_math ⇒ Object
Loads Math extensions.
97 98 99 100 |
# File 'lib/lazier.rb', line 97 def self.load_math Lazier.load_object ::Math.class_eval { include ::Lazier::Math } end |
.load_object ⇒ Object
Loads Object extensions.
55 56 57 |
# File 'lib/lazier.rb', line 55 def self.load_object ::Object.class_eval { include ::Lazier::Object } end |
.load_pathname ⇒ Object
Loads Pathname extensions.
103 104 105 106 |
# File 'lib/lazier.rb', line 103 def self.load_pathname require "pathname" ::Pathname.class_eval { include ::Lazier::Pathname } end |