Class: Cardio::Mod::Data

Inherits:
Object show all
Includes:
Card::Model::SaveHelper
Defined in:
card/lib/cardio/mod/data.rb

Overview

handle data in data directory of mods (list of card attributes) https://docs.google.com/document/d/13K_ynFwfpHwc3t5gnLeAkZJZHco1wK063nJNYwU8qfc/edit#

Constant Summary

Constants included from Card::Model::SaveHelper::SaveHelperHelper

Card::Model::SaveHelper::SaveHelperHelper::CARDTYPE_METHOD_REGEXP

Instance Method Summary collapse

Methods included from Card::Model::SaveHelper

#add_script, #create_card, #create_card!, #create_or_update_card, #create_or_update_card!, #delete_card, #delete_code_card, #ensure_card, #ensure_card!, #ensure_code_card, #ensure_trait, #ensure_trait_rule, #update_card, #update_card!, #with_user

Constructor Details

#initialize(mod: nil) ⇒ Data

Returns a new instance of Data.



13
14
15
# File 'card/lib/cardio/mod/data.rb', line 13

def initialize mod: nil
  @mod = mod
end

Dynamic Method Handling

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

Instance Method Details

#itemsArray <Hash>

list of card attribute hashes

Returns:

  • (Array <Hash>)


27
28
29
# File 'card/lib/cardio/mod/data.rb', line 27

def items
  paths.map { |mod_path| mod_items mod_path }.flatten
end

#mergeObject



17
18
19
20
21
22
23
# File 'card/lib/cardio/mod/data.rb', line 17

def merge
  Card::Mailer.perform_deliveries = false
  Card::Auth.as_bot do
    # puts Rails.env
    items.each { |item| ensure_card item }
  end
end

#pathsArray <String>

Returns:

  • (Array <String>)


32
33
34
35
# File 'card/lib/cardio/mod/data.rb', line 32

def paths
  hash = Mod.dirs.subpaths "data"
  @mod ? [hash[@mod]] : hash.values
end