Module: Card::Set::All::Trash

Extended by:
Card::Set
Defined in:
card/tmpsets/set/mod002-core/all/trash.rb

Overview

Set: All cards (Trash)

Defined Under Namespace

Modules: ClassMethods

Constant Summary

Constants included from Helpers

Helpers::SET_PATTERN_TEST_REGEXP

Constants included from Event::Api

Event::Api::OPTIONS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Card::Set

reset_modules

Methods included from I18nScope

#mod_name, #scope

Methods included from Loader

#clean_empty_module_from_hash, #clean_empty_modules, #extended, #process_base_modules, #register_set

Methods included from Helpers

#method_missing, #num_set_parts, #pattern_code, #respond_to_missing?, #set_name_parts, #shortname, #underscore

Methods included from Card::Set::AdvancedApi

#attachment, #define_set_from_error, #ensure_set, #setting_opts, #stage_method

Methods included from Format

#before, #format, layout_method_name, #view, view_method_name, view_setting_method_name, wrapper_method_name

Methods included from Inheritance

#include_set, #include_set_formats

Methods included from Basket

#abstract_basket, #add_to_basket, #basket, #unshift_basket

Methods included from Trait

#card_accessor, #card_reader, #card_writer, #require_field

Methods included from Event::Api

#event

Class Method Details

.source_locationObject



7
# File 'card/tmpsets/set/mod002-core/all/trash.rb', line 7

def self.source_location; "/Users/ethan/dev/decko/gem/card/mod/core/set/all/trash.rb"; end

Instance Method Details

#add_to_trash(args) {|args.merge trash: true| ... } ⇒ Object

Yields:

  • (args.merge trash: true)


72
73
74
75
# File 'card/tmpsets/set/mod002-core/all/trash.rb', line 72

def add_to_trash args
  return if new_card?
  yield args.merge trash: true
end

#db_attributesObject



95
96
97
# File 'card/tmpsets/set/mod002-core/all/trash.rb', line 95

def db_attributes
  send(:mutations_from_database).send :attributes
end

#delete(args = {}) ⇒ Object

def trash? trash end



66
67
68
69
70
# File 'card/tmpsets/set/mod002-core/all/trash.rb', line 66

def delete args={}
  add_to_trash args do |delete_args|
    update delete_args
  end
end

#delete!(args = {}) ⇒ Object



66
67
68
69
70
# File 'card/tmpsets/set/mod002-core/all/trash.rb', line 66

def delete! args={}
  add_to_trash args do |delete_args|
    update! delete_args
  end
end

#delete_as_subcard(subcard) ⇒ Object



131
132
133
134
# File 'card/tmpsets/set/mod002-core/all/trash.rb', line 131

def delete_as_subcard subcard
  subcard.trash = true
  add_subcard subcard
end

#event: manage_trashObject



77
78
79
80
81
# File 'card/tmpsets/set/mod002-core/all/trash.rb', line 77

event :manage_trash, :prepare_to_store, on: :create do
  pull_from_trash!
  self.trash = false
  true
end

#event: validate_deleteObject



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'card/tmpsets/set/mod002-core/all/trash.rb', line 99

event :validate_delete, :validate, on: :delete do
  unless codename.blank?
    errors.add :delete, tr(:error_system_card, name: name, codename: codename)
  end

  undeletable_all_rules_tags =
    %w[default style layout create read update delete]
  # FIXME: HACK! should be configured in the rule

  if junction? && left&.codename == :all &&
     undeletable_all_rules_tags.member?(right.codename.to_s)
    errors.add :delete, tr(:error_indestructible, name: name)
  end

  errors.add :delete, tr(:error_user_edits, name: name) if  && has_edits?
end

#event: validate_delete_childrenObject



116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'card/tmpsets/set/mod002-core/all/trash.rb', line 116

event :validate_delete_children, after: :validate_delete, on: :delete do
  return if errors.any?
  each_child do |child|
    next unless child
    # prevents errors in cases where a child is deleted prior to this point
    # and thus is not returned by the fetch in #children

    delete_as_subcard child
    # next if child.valid?
    # child.errors.each do |field, message|
    #   errors.add field, "can't delete #{child.name}: #{message}"
    # end
  end
end

#pull_from_trash!Object



83
84
85
86
87
88
89
90
91
92
93
# File 'card/tmpsets/set/mod002-core/all/trash.rb', line 83

def pull_from_trash!
  return unless (id = Card::Lexicon.id key) # name is already known
  return unless (trashed_card = Card.where(id: id).take)&.trash
  # confirm name is actually in trash

  db_attributes["id"] = trashed_card.db_attributes["id"]
  # id_in_database returns existing card id

  @from_trash = true
  @new_record = false
end