Sha256: 4be3f8174a9a5d15dd3d2801df44c5c302ac616d022951be2357631e6a6bedae
Contents?: true
Size: 1.28 KB
Versions: 1
Compression:
Stored size: 1.28 KB
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_object end # lazy generating # 'cause before user run " script/generate acts_as_arter_flow_object", # acts_as_arter_flow_object.rb has not been copied to app/models, # and this will caused a "uninitialized constant ActsAsAFO::InstanceMethods::ArterFlowObject" error. klazz = Kernel.const_get("ArterFlowObject") rescue nil unless klazz.nil? 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 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.2.5 | lib/afo/acts_as_afo.rb |