module Card::Name::All::Parts

Card methods for handling name parts, eg A and B are both parts of A+B

Public Instance Methods

left(*args) click to toggle source
# File lib/card/name/all/parts.rb, line 6
def left *args
  case
  when simple?    then nil
  when superleft then superleft
  when name_is_changing? && name.to_name.trunk_name == name_before_act.to_name
    nil # prevent recursion when, eg, renaming A+B to A+B+C
  else
    Card.fetch name.left, *args
  end
end
left_id=(cardish) click to toggle source
# File lib/card/name/all/parts.rb, line 37
def left_id= cardish
  write_card_or_id :left_id, cardish
end
left_or_new(args={}) click to toggle source
# File lib/card/name/all/parts.rb, line 17
def left_or_new args={}
  left(args) || Card.new(args.merge(name: name.left))
end
right(*args) click to toggle source
# File lib/card/name/all/parts.rb, line 21
def right *args
  Card.fetch(name.right, *args) unless simple?
end
right_id=(cardish) click to toggle source
# File lib/card/name/all/parts.rb, line 33
def right_id= cardish
  write_card_or_id :right_id, cardish
end
tag(*args) click to toggle source
# File lib/card/name/all/parts.rb, line 29
def tag *args
  simple? ? self : Card.fetch(name.right, *args)
end
trunk(*args) click to toggle source
# File lib/card/name/all/parts.rb, line 25
def trunk *args
  simple? ? self : left(*args)
end

Private Instance Methods

when_id_exists(cardish) { |card_id| ... } click to toggle source
# File lib/card/name/all/parts.rb, line 47
def when_id_exists cardish, &block
  if (card_id = Card.id cardish)
    yield card_id
  elsif cardish.is_a? Card
    with_id_after_store cardish, &block
  else
    yield cardish # eg nil
  end
end
with_id_after_store(subcard) { |id| ... } click to toggle source

subcards are usually saved after super cards; after_store forces it to save the subcard first and callback afterwards

# File lib/card/name/all/parts.rb, line 60
def with_id_after_store subcard
  subcard subcard
  subcard.director.after_store { |card| yield card.id }
end
write_card_or_id(attribute, cardish) click to toggle source
# File lib/card/name/all/parts.rb, line 43
def write_card_or_id attribute, cardish
  when_id_exists(cardish) { |id| write_attribute attribute, id }
end