Module: Pipeline::TransactionalAttribute::ClassMethods

Defined in:
lib/pipeline/core_ext/transactional_attribute.rb

Instance Method Summary collapse

Instance Method Details

#transactional_attrs(*attributes) ⇒ Object Also known as: transactional_attr



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/pipeline/core_ext/transactional_attribute.rb', line 8

def transactional_attrs(*attributes)
  attributes.each do |attribute|
    class_eval <<-EOD
      def #{attribute.to_s}=(value)
        ActiveRecord::Base.transaction(:requires_new => true) do
          write_attribute('#{attribute.to_s}', value)
          save!
        end
      end
    EOD
  end
end