Sha256: 3b4d2a3314860c8a0faf857f0be78d594061b742a7dfa8d04a3973362f3fc69f

Contents?: true

Size: 1000 Bytes

Versions: 4

Compression:

Stored size: 1000 Bytes

Contents

def act options={}, &block
  if act_card
    add_to_act options, &block
  else
    start_new_act &block
  end
end

def act_card
  Card::Director.act_card
end

def act_card?
  self == act_card
end

module ClassMethods
  def create! opts
    card = Card.new opts
    card.save!
    card
  end

  def create opts
    card = Card.new opts
    card.save
    card
  end
end

def save! *args
  as_subcard = args.first&.delete :as_subcard
  act(as_subcard: as_subcard) { super }
end

def save(*)
  act { super }
end

def valid?(*)
  act(validating: true) { super }
end

def update *args
  act { super }
end

def update! *args
  act { super }
end

alias_method :update_attributes, :update
alias_method :update_attributes!, :update!

private

def start_new_act
  self.director = nil
  Director.run_act(self) do
    run_callbacks(:act) { yield }
  end
end

def add_to_act options={}
  director.appoint self unless @director
  director.head = true unless options[:validating] || options[:as_subcard]
  yield
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
card-1.101.3 mod/core/set/all/actify.rb
card-1.101.2 mod/core/set/all/actify.rb
card-1.101.1 mod/core/set/all/actify.rb
card-1.101.0 mod/core/set/all/actify.rb