Sha256: b29486a230434715e5090582d7cc41f04c2ae0ab07f0c7d3676a6e42ca1f611d

Contents?: true

Size: 1.63 KB

Versions: 12

Compression:

Stored size: 1.63 KB

Contents

# -*- encoding : utf-8 -*-
class Card
  class Act < ActiveRecord::Base
    before_save :set_actor
    has_many :actions, :foreign_key=>:card_act_id, :inverse_of=> :act, :order => :id, :class_name=> "Card::Action"
    belongs_to :actor, class_name: "Card"
    belongs_to :card    
    def set_actor
      self.actor_id ||= Auth.current_id
    end
    
    def self.delete_actionless
      Card::Act.where(
        "id NOT IN (?)",
        Card::Action.pluck("card_act_id"),
      ).delete_all
    end
    
    def self.find_all_with_actions_on card_ids, args={}
      sql = 'card_actions.card_id IN (:card_ids) AND ( (draft is not true) '
      sql << ( args[:with_drafts] ? 'OR actor_id = :current_user_id)' : ')' )
      vars = {:card_ids => card_ids, :current_user_id=>Card::Auth.current_id }
      Card::Act.joins(:actions).where( sql, vars ).uniq.order(:id).reverse_order
    end
    
    # def actor
    #   Card[ actor_id ]
    # end

    # def card
 #      Card[ card_id ]
 #    end
    
    def action_on card_id
      actions.where( "card_id = #{card.id} and draft is not true" ).first
    end
        
    def elapsed_time
      DateTime.new(acted_at).distance_of_time_in_words_to_now
    end
    
    def relevant_drafts_for card
      drafts.select do |action|
        card.included_card_ids.include?(action.card_id) || (card == action.card)
      end
    end
    
    def relevant_actions_for card, with_drafts=false
      actions.select do |action|
        card.included_card_ids.include?(action.card_id) || (card == action.card)
      end
    end
    
  private
    def timestamp_attributes_for_create
      super << :acted_at
    end
    
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
card-1.15.2 mod/01_history/lib/card/act.rb
card-1.15.1 mod/01_history/lib/card/act.rb
card-1.15.0 mod/01_history/lib/card/act.rb
card-1.15.pre2 mod/01_history/lib/card/act.rb
card-1.15.pre mod/01_history/lib/card/act.rb
wagn-1.14.9 lib/card/act.rb
wagn-1.14.8 lib/card/act.rb
wagn-1.14.7 lib/card/act.rb
wagn-1.14.6 lib/card/act.rb
wagn-1.14.5 lib/card/act.rb
wagn-1.14.4 lib/card/act.rb
wagn-1.14.3 lib/card/act.rb