Class: Cardio::Mod

Inherits:
Object
  • Object
show all
Extended by:
ClassMethods
Defined in:
lib/cardio/mod.rb,
lib/cardio/mod/eat.rb,
lib/cardio/mod/sow.rb,
lib/cardio/mod/dirs.rb,
lib/cardio/mod/loader.rb,
lib/cardio/mod/eat/edibles.rb,
lib/cardio/mod/modfile_api.rb,
lib/cardio/mod/class_methods.rb,
lib/cardio/mod/load_strategy.rb,
lib/cardio/mod/modfile_loader.rb,
lib/cardio/mod/module_template.rb,
lib/cardio/mod/loader/set_loader.rb,
lib/cardio/mod/load_strategy/eval.rb,
lib/cardio/mod/loader/set_template.rb,
lib/cardio/mod/load_strategy/tmp_files.rb,
lib/cardio/mod/loader/set_pattern_loader.rb,
lib/cardio/mod/load_strategy/set_tmp_files.rb,
lib/cardio/mod/load_strategy/pattern_tmp_files.rb,
lib/cardio/mod/load_strategy/set_binding_magic.rb

Overview

A Card Mod (short for “module” or “modification”) is a library containing discrete chunk of card functionality. Mods are how the Decko community develops and shares code. If you want to customize a deck in a way that can’t be done on the site itself, try a mod.

The simplest way to add a mod is to run this command in your deck:

card generate mod MOD_NAME

# or, for short:
card g mod MOD_NAME

This will create a directory following the pattern ‘DECK_NAME/mod/MOD_NAME`. This directory contains all the specifications of your mod. By default that includes a README.md file and the subdirectories in bold below:

  • assets

    • script - JavaScript, CoffeeScript, etc

    • style - CSS, SCSS, etc

  • config

    - **early** ruby init files loaded before Card
    - **late** ruby init files loaded after Card
    - **locales** i18n yml files
    
  • data - seed and test data.

  • lib - standard ruby libraries

    • task - rake tasks

  • public - accessible via the web at DECK_URL_ROOT/mod/MOD_NAME/

  • **set** - the mod’s focal point where card sets are configured

  • set_pattern - (advanced) for adding types of sets.

  • spec - for rspec tests

  • vendor - for external code, especially git submodules

Mods also often contain a .gemspec file to specify the mod as a ruby gem.

Learn more:

- {Card} introduces card objects
- {Card::Set} explains of how set modules work

Defined Under Namespace

Modules: ClassMethods, ModfileApi Classes: BindingMagic, Dirs, Eat, LoadStrategy, Loader, ModfileLoader, ModuleTemplate, Sow

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ClassMethods

dependencies, dirs, ensure_installed, ensure_uninstalled, fetch, gem_specs, leftover, load, normalize_name

Constructor Details

#initialize(name, path, group, index) ⇒ Mod

Returns a new instance of Mod.



47
48
49
50
51
52
# File 'lib/cardio/mod.rb', line 47

def initialize name, path, group, index
  @name = Mod.normalize_name name
  @path = required_path path
  @group = group || :custom
  @index = index
end

Instance Attribute Details

#groupObject (readonly)

Returns the value of attribute group.



45
46
47
# File 'lib/cardio/mod.rb', line 45

def group
  @group
end

#indexObject (readonly)

Returns the value of attribute index.



45
46
47
# File 'lib/cardio/mod.rb', line 45

def index
  @index
end

#nameObject (readonly)

Returns the value of attribute name.



45
46
47
# File 'lib/cardio/mod.rb', line 45

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



45
46
47
# File 'lib/cardio/mod.rb', line 45

def path
  @path
end

Instance Method Details

#codenameObject



58
59
60
# File 'lib/cardio/mod.rb', line 58

def codename
  "mod_#{name}"
end

#ensure_cardObject



72
73
74
75
76
77
78
79
80
# File 'lib/cardio/mod.rb', line 72

def ensure_card
  if Card::Codename.exists? codename
    card = Card.fetch codename.to_sym
    card.update type: :mod unless card.type_code == :mod
    card
  else
    Card.create name: mod_card_name, type: :mod, codename: codename
  end
end

#mod_card_nameObject



54
55
56
# File 'lib/cardio/mod.rb', line 54

def mod_card_name
  "mod: #{name.tr '_', ' '}"
end

#subpath(*parts) ⇒ Object



62
63
64
65
# File 'lib/cardio/mod.rb', line 62

def subpath *parts
  path = File.join [@path] + parts
  path if File.exist? path
end

#tmp_dir(type) ⇒ Object



67
68
69
70
# File 'lib/cardio/mod.rb', line 67

def tmp_dir type
  File.join Cardio.paths["tmp/#{type}"].first, @group.to_s,
            "mod#{'%03d' % (@index + 1)}-#{@name}"
end