Module: AttributeExtras

Defined in:
lib/attribute_extras.rb,
lib/attribute_extras/version.rb

Overview

Extra macros for auto attribute manipulation.

Defined Under Namespace

Classes: AttributeExtra

Constant Summary collapse

VERSION =
'1.0.0'

Class Method Summary collapse

Class Method Details

.define_extra(name, &perform) ⇒ Object



32
33
34
35
36
37
38
39
40
# 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