Sha256: 2999c326579dbdcddacbeb1eded0a3a1c3cc580b91677100adfa26d040eef29b

Contents?: true

Size: 919 Bytes

Versions: 1

Compression:

Stored size: 919 Bytes

Contents

module ActsAsAFO

  def self.included(base)
    base.extend ClassMethods
  end

  module ClassMethods

    def acts_as_arter_flow_object
      has_one :arter_flow_object, :as => :afoable, :dependent => :destroy
      include InstanceMethods

    end

  end

  module InstanceMethods
    
    def after_create
      super
      create_arter_flow_objecjt
    end

    ArterFlowObject::STEPS.each do |s|
      module_eval <<-EOF
        def #{s}ed?
          arter_flow_object.send(:#{s}) rescue false
        end

        def toggle_#{s}!(usr)
          raise ActiveRecord::RecordNotFound.new("no corresponding arter flow object record found")  unless arter_flow_object
          arter_flow_object.toggle(:#{s})
          arter_flow_object.#{s}_updater = usr
          arter_flow_object.save
        end
      EOF
    end

    private

    def create_arter_flow_object
      arter_flow_object.create
    end
 
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
acts_as_arter_flow_object-0.1.0 lib/afo/acts_as_afo.rb