Module: Card::Model::SaveHelper

Includes:
SaveArguments, SaveHelperHelper
Included in:
Cardio::Migration::Transform
Defined in:
lib/card/model/save_helper.rb,
lib/card/model/save_helper/save_arguments.rb,
lib/card/model/save_helper/save_helper_helper.rb

Overview

API to create and update cards. It is intended as a helper for “external” scripts (seeding, testing, migrating, etc) and not for internal application code. The general pattern is: All methods use the ActiveRecord !-methods that throw exceptions if somethings fails. All !-methods in this module rename existing cards to resolve name conflicts)

Defined Under Namespace

Modules: SaveArguments, SaveHelperHelper

Constant Summary

Constants included from SaveHelperHelper

SaveHelperHelper::CARDTYPE_METHOD_REGEXP

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Card::Model::SaveHelper::SaveHelperHelper

Instance Method Details

#create_card(name_or_args, content_or_args = nil) ⇒ Object Also known as: create



19
20
21
# File 'lib/card/model/save_helper.rb', line 19

def create_card name_or_args, content_or_args=nil
  Card.create! create_args(name_or_args, content_or_args)
end

#create_card!(name_or_args, content_or_args = nil) ⇒ Object Also known as: create!

if card with same name exists move it out of the way



24
25
26
27
# File 'lib/card/model/save_helper.rb', line 24

def create_card! name_or_args, content_or_args=nil
  args = standardize_args name_or_args, content_or_args
  create_card args.reverse_merge(rename_if_conflict: :old)
end

#delete_card(name) ⇒ Object Also known as: delete



40
41
42
43
44
# File 'lib/card/model/save_helper.rb', line 40

def delete_card name
  return unless Card.exist?(name)

  Card[name].delete!
end

#delete_code_card(name) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/card/model/save_helper.rb', line 46

def delete_code_card name
  return unless delete_code_card? name

  card = Card[name]
  card.update! codename: ""
  card.delete!
end

#update_card(name, content_or_args) ⇒ Object Also known as: update



29
30
31
32
33
# File 'lib/card/model/save_helper.rb', line 29

def update_card name, content_or_args
  args = standardize_update_args name, content_or_args
  resolve_name_conflict args
  Card[name]&.update! args
end

#update_card!(name, content_or_args) ⇒ Object Also known as: update!



35
36
37
38
# File 'lib/card/model/save_helper.rb', line 35

def update_card! name, content_or_args
  args = standardize_update_args name, content_or_args
  update_card name, args.reverse_merge(rename_if_conflict: :new)
end

#with_user(user_name, &block) ⇒ Object



15
16
17
# File 'lib/card/model/save_helper.rb', line 15

def with_user user_name, &block
  Card::Auth.with(current_id: user_name.card_id, &block)
end