Sha256: 1700d6c6eb110454b91d99f8e2e6452bd13cecbed4087a0673161383adcc39a0
Contents?: true
Size: 1.7 KB
Versions: 2
Compression:
Stored size: 1.7 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 = if args[:with_drafts] 'card_actions.card_id IN (:card_ids) AND ( (draft = 0 OR draft IS null) OR actor_id = :current_user_id)' else 'card_actions.card_id IN (:card_ids) AND ( (draft = 0 OR draft IS null) )' end Card::Act.joins(:actions).where(sql, {:card_ids => card_ids, :current_user_id=>Card::Auth.current_id }).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, :draft=>[nil, 0] ).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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
wagn-1.14.1 | lib/card/act.rb |
wagn-1.14.0 | lib/card/act.rb |