Sha256: 17faaf170243805f1aad8621d8e9e2cb65e675f8a01ac17dca524dc50e31d3f2

Contents?: true

Size: 904 Bytes

Versions: 3

Compression:

Stored size: 904 Bytes

Contents

class ArterFlowObject < ActiveRecord::Base

  default_scope :order => "created_at desc"

  belongs_to :afoable, :polymorphic => true

  STEPS = [:design, :model, :map, :rig]

  STEPS.each do |s|
    self.class_eval <<-EOF
      belongs_to :#{s}_updater, :class_name => "User", :foreign_key => :#{s}_updater_id 
    EOF

    self.module_eval <<-MDE
      def toggle_#{s}! usr
        self.toggle "#{s}".to_sym
        self.#{s}_updater = usr
        save!
      end

      def #{s}_updater_name
        self.#{s}_updater.login rescue ''
      end
    MDE
  end

  def origin_human_type
    Kernel.const_get(self.afoable_type).human_name
  end

  def origin_name
    afoable.send(:title) rescue (afoable.send(:name) rescue 'Unknown')
  end

  def self.afo_types_for_select
    find(:all, :select => "DISTINCT afoable_type").inject([]){|ary,rcd| ary << [rcd.origin_human_type, rcd.afoable_type]}
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
acts_as_arter_flow_object-0.3.0 generators/acts_as_arter_flow_object/templates/models/arter_flow_object.rb
acts_as_arter_flow_object-0.2.5 generators/acts_as_arter_flow_object/templates/models/arter_flow_object.rb
acts_as_arter_flow_object-0.2.4 generators/acts_as_arter_flow_object/templates/models/arter_flow_object.rb