module AttributeExtras

Extra macros for auto attribute manipulation.

Constants

VERSION

Public Class Methods

define_extra(name, &perform) click to toggle source
# File lib/attribute_extras.rb, line 32
def self.define_extra(name, &perform)
  extra = Class.new(AttributeExtra)
  extra_name = name.to_s.gsub(/(?:\A|_)([a-z])/i) { $1.upcase }.to_sym

  AttributeExtras.const_set(extra_name, extra)
  ActiveRecord::Base.define_singleton_method(name) do |*attributes|
    include extra.new(name, attributes, perform)
  end
end