Module: Footing

Defined in:
lib/footing/extensions/schema_statements.rb,
lib/footing.rb,
lib/footing/version.rb,
lib/footing/extensions/hash.rb,
lib/footing/extensions/array.rb,
lib/footing/extensions/kernel.rb,
lib/footing/extensions/object.rb,
lib/footing/extensions/string.rb,
lib/footing/extensions/numeric.rb,
lib/footing/extensions/nil_class.rb,
lib/footing/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

Constant Summary collapse

VERSION =
"0.2.3"

Class Method Summary collapse

Class Method Details

.patch!(obj, extension) ⇒ Object

Patches a Module or instance with the given extension.

Parameters:

  • obj (Module, Object)

    The Module or instance to patch.

  • extension (Module)

    The Module that contains the patches.



10
11
12
13
14
# File 'lib/footing.rb', line 10

def patch!(obj, extension)
  context = patch_context(obj)
  raise "#{obj.class.name} doesn't support patching!" unless context
  context.send :include, extension
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.

Parameters:

  • mod (Module)

    The Module to setup util methods for.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/footing.rb', line 19

def util!(mod)
  proxy = Class.new(SimpleDelegator)
  Footing.patch! proxy, mod

  mod.instance_methods(false).each do |method_name|
    mod.define_singleton_method(method_name) do |target, *args|
      method = proxy.instance_method(method_name)
      target = proxy.new(target)
      if method.parameters.empty?
        method.bind(target).call
      else
        method.bind(target).call(*args)
      end
    end
  end
end