Module: Card::Director::All

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

Overview

director-related Card instance methods

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#directorObject



10
11
12
# File 'lib/card/director/all.rb', line 10

def director
  @director ||= Director.fetch self
end

Instance Method Details

#act(options = {}, &block) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/card/director/all.rb', line 30

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

#act_cardObject



38
39
40
# File 'lib/card/director/all.rb', line 38

def act_card
  Card::Director.act_card
end

#act_card?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/card/director/all.rb', line 42

def act_card?
  self == act_card
end

#clear_action_specific_attributesObject



98
99
100
101
102
# File 'lib/card/director/all.rb', line 98

def clear_action_specific_attributes
  self.class.action_specific_attributes.each do |attr|
    instance_variable_set "@#{attr}", nil
  end
end

#identify_actionObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/card/director/all.rb', line 19

def identify_action
  @action =
    if trash && trash_changed?
      :delete
    elsif new_card?
      :create
    else
      :update
    end
end

#prepare_for_phasesObject



14
15
16
17
# File 'lib/card/director/all.rb', line 14

def prepare_for_phases
  reset_patterns
  include_set_modules
end

#restore_changes_informationObject



89
90
91
92
93
94
95
96
# File 'lib/card/director/all.rb', line 89

def restore_changes_information
  # restores changes for integration phase
  # (rails cleared them in an after_create/after_update hook which is
  #  executed before the integration phase)
  return unless saved_changes.present?

  @mutations_from_database = mutations_before_last_save
end

#save(*_args) ⇒ Object



51
52
53
# File 'lib/card/director/all.rb', line 51

def save *_args
  act { super }
end

#save!(**args) ⇒ Object



46
47
48
49
# File 'lib/card/director/all.rb', line 46

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

#save_if_neededObject



67
68
69
70
# File 'lib/card/director/all.rb', line 67

def save_if_needed
  validate
  save if save_needed?
end

#save_if_needed!Object



72
73
74
75
# File 'lib/card/director/all.rb', line 72

def save_if_needed!
  validate
  save! if save_needed?
end

#save_needed?Boolean

Returns:

  • (Boolean)


77
78
79
80
81
82
83
84
# File 'lib/card/director/all.rb', line 77

def save_needed?
  # (
  new? || test_field_changing? || subcards.cards.any?(&:save_needed?)
  # ).tap do |r|
  #   # binding.pry if r
  #   puts "save needed for #{name}".yellow if r && !new?
  # end
end

#update(*_args) ⇒ Object Also known as: update_attributes



59
60
61
# File 'lib/card/director/all.rb', line 59

def update *_args
  act { super }
end

#update!(*_args) ⇒ Object Also known as: update_attributes!



63
64
65
# File 'lib/card/director/all.rb', line 63

def update! *_args
  act { super }
end

#valid?(*_args) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/card/director/all.rb', line 55

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