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 discrete piece of Decko 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:

decko generate card: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 following subdirectories:

  • assets - for JavaScript, CSS, and variants (CoffeeScript, SCSS, etc)

  • data - for seed and test data. see SEEDME.

  • lib - for standard code libraries

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

  • set - the mod’s focal point where card sets are configured (see below)

  • spec - for rspec tests

## Set Modules

Set modules define methods for a given set of cards and their format objects. They are defined in a mod’s set directory. For example, suppose you’ve created a mod that called biz, your deck has Company cards, and you want to extend the behavior of those cards.

You can add a set module like so:

decko generate set biz type company

This will create the following two files:

mod/biz/set/type/company.rb
mod/biz/spec/set/type/company.rb

If you would like to break this code into smaller files, you can extend this pattern into another directory, eg:

mod/biz/set/type/company/foo.rb
mod/biz/set/type/company/bar.rb

The general pattern can be expressed as follows:

DECKNAME/mod/MODNAME/set/SET_PATTERN/ANCHOR[/FREENAME].rb

Learn more:

- {Card} introduces card objects
- {Card::Set} provides an overview of how set modules work
- {Card::Set::Format} explains the basics of the format API
- {Card::Set::Format::AbstractFormat} explains the basics of the view definition API
- {Card::Set::Event::Api} explains the basics of the event API

## Other Directories

Other ways your mod can extend Decko functionality include:

- **set_pattern** for additional {Card::Set::Pattern set patterns},
  or types of sets.
- **file** for fixed initial card content

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, load, missing, normalize_name

Constructor Details

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

Returns a new instance of Mod.



68
69
70
71
72
73
# File 'lib/cardio/mod.rb', line 68

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.



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

def group
  @group
end

#indexObject (readonly)

Returns the value of attribute index.



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

def index
  @index
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Instance Method Details

#codenameObject



79
80
81
# File 'lib/cardio/mod.rb', line 79

def codename
  "mod_#{name}"
end

#ensure_cardObject



93
94
95
96
97
98
99
100
101
# File 'lib/cardio/mod.rb', line 93

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



75
76
77
# File 'lib/cardio/mod.rb', line 75

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

#subpath(*parts) ⇒ Object



83
84
85
86
# File 'lib/cardio/mod.rb', line 83

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

#tmp_dir(type) ⇒ Object



88
89
90
91
# File 'lib/cardio/mod.rb', line 88

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