Sha256: dbf757634eb6c925d389760b9424744e3e9759417a708d1116c26dc2d688e556

Contents?: true

Size: 2 KB

Versions: 49

Compression:

Stored size: 2 KB

Contents

# -*- encoding : utf-8 -*-
class Card; module Set; class All; module Actions; extend Card::Set
# ~~ above autogenerated; below pulled from /Users/ethan/dev/wagn/gem/card/mod/history/set/all/actions.rb ~~
# -*- encoding : utf-8 -*-

def select_action_by_params params
  return unless (action = find_action_by_params(params))
  run_callbacks :select_action do
    self.selected_action_id = action.id
  end
end

def find_action_by_params args
  if args[:rev]
    nth_action args[:rev]
  elsif args[:rev_id].is_a?(Integer) || args[:rev_id] =~ /^\d+$/
    if (action = Action.fetch(args[:rev_id])) && action.card_id == id
      action
    end
  # revision id is probalby a mod (e.g. if you request
  # files/:logo/standard.png)
  elsif args[:rev_id]
    last_action
  end
end

def nth_action index
  index = index.to_i
  return unless id && index > 0
  Action.where("draft is not true AND card_id = #{id}")
        .order(:id).limit(1).offset(index - 1).first
end

def revision action
  # a "revision" refers to the state of all tracked fields
  # at the time of a given action
  action = Card::Action.fetch(action) if action.is_a? Integer
  return unless action
  Card::Change::TRACKED_FIELDS.each_with_object({}) do |field, attr_changes|
    last_change = action.change(field) ||
                  last_change_on(field, not_after: action)
    attr_changes[field.to_sym] = (last_change ? last_change.value : self[field])
  end
end

def delete_old_actions
  Card::Change::TRACKED_FIELDS.each do |field|
    # assign previous changes on each tracked field to the last action
    next unless (la = last_action) && !la.change(field).present? &&
                (last_change = last_change_on field)
    # last_change comes as readonly record
    last_change = Card::Change.find(last_change.id)
    last_change.update_attributes!(card_action_id: last_action_id)
  end
  actions.where("id != ?", last_action_id).delete_all
end


# ~~ below autogenerated; above pulled from /Users/ethan/dev/wagn/gem/card/mod/history/set/all/actions.rb ~~
end;end;end;end;

Version data entries

49 entries across 49 versions & 1 rubygems

Version Path
card-1.99.6 tmpsets/set/mod003-history/all/actions.rb
card-1.99.5 tmpsets/set/mod003-history/all/actions.rb
card-1.97.0.1 tmpsets/set/mod003-history/all/actions.rb
card-1.97.0 tmpsets/set/mod003-history/all/actions.rb
card-1.96.8 tmpsets/set/mod003-history/all/actions.rb
card-1.96.7 tmpsets/set/mod003-history/all/actions.rb
card-1.96.6 tmpsets/set/mod003-history/all/actions.rb
card-1.96.5 tmpsets/set/mod003-history/all/actions.rb
card-1.96.4 tmpsets/set/mod003-history/all/actions.rb
card-1.96.3 tmpsets/set/mod003-history/all/actions.rb
card-1.96.2 tmpsets/set/mod003-history/all/actions.rb
card-1.96.1 tmpsets/set/mod003-history/all/actions.rb
card-1.96.0 tmpsets/set/mod003-history/all/actions.rb
card-1.95.3 tmpsets/set/mod003-history/all/actions.rb
card-1.95.2 tmpsets/set/mod003-history/all/actions.rb
card-1.95.1 tmpsets/set/mod003-history/all/actions.rb
card-1.95.0 tmpsets/set/mod003-history/all/actions.rb
card-1.94.1 tmpsets/set/mod003-history/all/actions.rb
card-1.94.0 tmpsets/set/mod003-history/all/actions.rb
card-1.93.13 tmpsets/set/mod003-history/all/actions.rb