Module: Card::Director::CardClass

Included in:
Card
Defined in:
lib/card/director/card_class.rb

Overview

director-related Card class methods

Instance Method Summary collapse

Instance Method Details

#create(opts) ⇒ Object



11
12
13
14
15
# File 'lib/card/director/card_class.rb', line 11

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

#create!(opts) ⇒ Object



5
6
7
8
9
# File 'lib/card/director/card_class.rb', line 5

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

#ensure(opts) ⇒ Object

The ensure methods are use to make sure a card exists and can be used when you’re unsure as to whether it already does. It’s arguments are largely the same as those used by Card#create and @card.update with the important exception of ‘conflict`.

The conflict argument takes one of three values:

- **defer**: let existing card stay as it is
- **default**: update existing card if it is "pristine" (meaning it has not
  been edited by anyone other than Decko Bot)
- **override**: update existing card

If the options specify a codename and the name is already in use, things get a little more involved. (Note: we MUST ensure that a card with the codename exists!)

If the conflict setting is “defer”:

- if the _codename_ is NOT already in use, we create a new card with an
  altered name
- otherwise we do nothing.

If the conflict setting is “default”:

- if the _codename_ is NOT already in use:
  - if the card using the name we want is pristine, we update that card
  - otherwise we create a new card with an altered name
- if the _codename_ IS already in use
  - if the card with the codename is pristine, we update everything but the
    name (which is used by another card)
  - otherwise we do nothing

If the conflict setting is “override”:

- if the _codename_ is NOT already in use, we update the existing card with the
  name.
- otherwise we alter the card withe the conflicting name and update the card
  with the codename.


54
55
56
# File 'lib/card/director/card_class.rb', line 54

def ensure opts
  ensuring opts, &:save_if_needed
end

#ensure!(opts) ⇒ Object



58
59
60
# File 'lib/card/director/card_class.rb', line 58

def ensure! opts
  ensuring opts, &:save_if_needed!
end