Module: Footing
- Defined in:
- lib/extensions/schema_statements.rb,
lib/footing.rb,
lib/extensions/hash.rb,
lib/extensions/array.rb,
lib/extensions/kernel.rb,
lib/extensions/object.rb,
lib/extensions/string.rb,
lib/extensions/numeric.rb,
lib/extensions/nil_class.rb,
lib/extensions/postgresql_adapter.rb
Overview
Extend Rails with this module to add a uuid method in your migrations.
Example:
# rails_root/config/application.rb
config.after_initialize do
Footing.patch! ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::TableDefinition, Footing::PGTableDefinition
end
Defined Under Namespace
Modules: Array, Hash, Kernel, NilClass, Numeric, Object, PGSchemaStatements, PGTableDefinition, String
Class Method Summary collapse
- .modules ⇒ Object
-
.patch!(obj, extension) ⇒ Object
Patches a Module or instance with the given extension.
-
.patch_all! ⇒ Object
Applies all Footing patches.
-
.util!(mod) ⇒ Object
Creates class methods for all instance methods in the module.
-
.util_all! ⇒ Object
Creates util methods for all Footing patches.
Class Method Details
.modules ⇒ Object
3 4 5 6 7 8 9 10 11 |
# File 'lib/footing.rb', line 3 def self.modules [ "Kernel", "Object", "String", "Numeric", "Hash" ] end |
.patch!(obj, extension) ⇒ Object
Patches a Module or instance with the given extension.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/footing.rb', line 25 def self.patch!(obj, extension) context = obj if obj.is_a? Module if context.nil? begin context = class << obj self end rescue Exception => ex end end raise "#{obj.class.name} doesn't support patching!" unless context context.send :include, extension end |
.patch_all! ⇒ Object
Applies all Footing patches.
14 15 16 17 18 19 20 |
# File 'lib/footing.rb', line 14 def self.patch_all! modules.each do |name| context = Object.const_get(name) footing = Footing.const_get(name) patch! context, footing end end |
.util!(mod) ⇒ Object
Creates class methods for all instance methods in the module. This allows users to invoke utility methods rather than monkey patching if they so desire.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/footing.rb', line 48 def self.util!(mod) proxy = ::Object.new proxy_eigen = class << proxy self end Footing.patch! proxy, mod eigen = class << mod self end mod.instance_methods(false).each do |method| eigen.send :define_method, method do |*args| o = args.first || proxy m = proxy_eigen.instance_method(method) if m.parameters.empty? m.bind(o).call else m.bind(o).call(*args) end end end end |