Class: Cardio::Mod
- Inherits:
-
Object
- Object
- Cardio::Mod
- Extended by:
- ClassMethods
- Defined in:
- lib/cardio/mod.rb,
lib/cardio/mod/eat.rb,
lib/cardio/mod/dirs.rb,
lib/cardio/mod/poop.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 the following directories:
DECK_NAME/mod/MOD_NAME
DECK_NAME/mod/MOD_NAME/lib
DECK_NAME/mod/MOD_NAME/public
DECK_NAME/mod/MOD_NAME/set
The lib directory contains libraries, of course. And files in the public directory are public and served directly.
But in most mods, the focal point is the set directory.
## 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/.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, Poop
Instance Attribute Summary collapse
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #codename ⇒ Object
- #ensure ⇒ Object
-
#initialize(name, path, index) ⇒ Mod
constructor
A new instance of Mod.
- #mod_card_name ⇒ Object
- #subpath(*parts) ⇒ Object
- #tmp_dir(type) ⇒ Object
Methods included from ClassMethods
dependencies, dirs, each_path, ensure_installed, ensure_uninstalled, fetch, gem_specs, load, missing, normalize_name
Constructor Details
#initialize(name, path, index) ⇒ Mod
Returns a new instance of Mod.
69 70 71 72 73 |
# File 'lib/cardio/mod.rb', line 69 def initialize name, path, index @name = Mod.normalize_name name @path = required_path path @index = index end |
Instance Attribute Details
#index ⇒ Object (readonly)
Returns the value of attribute index.
67 68 69 |
# File 'lib/cardio/mod.rb', line 67 def index @index end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
67 68 69 |
# File 'lib/cardio/mod.rb', line 67 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
67 68 69 |
# File 'lib/cardio/mod.rb', line 67 def path @path end |
Instance Method Details
#codename ⇒ Object
79 80 81 |
# File 'lib/cardio/mod.rb', line 79 def codename "mod_#{name}" end |
#ensure ⇒ Object
93 94 95 96 97 98 99 100 |
# File 'lib/cardio/mod.rb', line 93 def ensure Card::Auth.as_bot do card = ensure_card card.ensure_mod_script_card card.ensure_mod_style_card Card::Cache.reset_all end end |
#mod_card_name ⇒ Object
75 76 77 |
# File 'lib/cardio/mod.rb', line 75 def mod_card_name "mod: #{name}" 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, "mod#{'%03d' % (@index + 1)}-#{@name}" end |