Module: Card::Set
- Includes:
- AdvancedApi, Event::Api, Format, Helpers, Inheritance, Trait
- Defined in:
- lib/card/set.rb,
lib/card/set/type.rb,
lib/card/set/event.rb,
lib/card/set/trait.rb,
lib/card/set/format.rb,
lib/card/set/helpers.rb,
lib/card/set/pattern.rb,
lib/card/set/abstract.rb,
lib/card/set/event/all.rb,
lib/card/set/registrar.rb,
lib/card/set/i18n_scope.rb,
lib/card/set/inheritance.rb,
lib/card/set/pattern/all.rb,
lib/card/set/advanced_api.rb,
lib/card/set/card_methods.rb,
lib/card/set/i18n_scanner.rb,
lib/card/set/pattern/base.rb,
lib/card/set/event/options.rb,
lib/card/set/required_field.rb,
lib/card/set/event/callbacks.rb,
lib/card/set/format/haml_paths.rb,
lib/card/set/event/delayed_event.rb,
lib/card/set/pattern/class_methods.rb,
lib/card/set/event/skip_and_trigger.rb,
lib/card/set/format/abstract_format.rb,
lib/card/set/format/abstract_format/wrapper.rb,
lib/card/set/format/abstract_format/view_opts.rb,
lib/card/set/format/abstract_format/haml_views.rb,
lib/card/set/format/abstract_format/view_definition.rb
Overview
A Set is a group of Cards to which Rules may apply. Sets can be as specific as a single card, as general as all cards, or anywhere in between.
Rules can defined onto Sets in two ways:
- **Card rules** are defined in card content. These are generally configured via the
web interface and are thus documented at decko.org/rules.
- **Code rules** can be defined in a 'set module'.
## Set Modules
### File structure
Set modules specify views, events, and other methods for a given set of cards. They are defined in a mod’s set directory. For example, suppose you’ve created a mod 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:
card 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
Note: _the set module’s filename connects it to the set, so both the set_pattern and the set_anchor must correspond to the codename of a card in the database to function correctly. For example, the type/company directory corresponds to the Set card named ‘:company+:type`. Both the :company and :type codenames must exist for this to work properly._
### Writing/Editing set modules
A set module is mostly standard ruby, but the files are quite concise because
1. the set module's file location is used to autogenerate ruby module definitions
2. A DSL (Domain-Specific Language) makes common tasks easy.
You can, for example, edit ‘mod/biz/set/type/company.rb`, and add only the following code:
def hello
"world"
end
No further code is needed for this method to be available to cards with the type Company (as specified by the file’s location). This code will automatically be added to a ruby module named ‘Card::Set::Type::Company`. That module is extended with the Set module, giving it access to the set module DSL.
These important Card::Set subclasses explain more about the DSL
- {Format} introduces format blocks
- {Format::AbstractFormat} covers {Format::AbstractFormat#view view} definitions
- {Event::Api} explains {Event::Api#event event} definitions
### Loading set modules
Whenever you fetch or instantiate a card, the card will automatically include code from all the set modules associated with sets of which it is a member.
For example, say you have a Plaintext card named 'Philipp+address', and you have set
files for the following sets:
* all cards
* all Plaintext cards
* all cards ending in +address
When you run any of these:
mycard = Card.fetch "Philipp+address"
mycard = "Philipp+address".card
mycard = ["Philipp", "address"].card
...then mycard will include the set modules associated with each of those sets in the
above order.
Defined Under Namespace
Modules: AdvancedApi, CardMethods, Format, Helpers, I18nScope, Inheritance, Pattern, Registrar, Trait Classes: Abstract, Event, I18nScanner, RequiredField, Type
Constant Summary
Constants included from Helpers
Helpers::SET_PATTERN_TEST_REGEXP
Constants included from Event::Api
Class Attribute Summary collapse
-
.basket ⇒ Object
Returns the value of attribute basket.
-
.modules ⇒ Object
Returns the value of attribute modules.
-
.traits ⇒ Object
Returns the value of attribute traits.
Class Method Summary collapse
Methods included from I18nScope
Methods included from Registrar
extended, finalize_load, process_base_modules, register_set
Methods included from Helpers
#format_module, #format_modules, #method_missing, #modules, #pattern_code, #respond_to_missing?, #set_name_parts, #shortname, #underscored_name
Methods included from AdvancedApi
#assign_type, #attachment, #define_set_from_error, #ensure_set, #setting_opts, #stage_method
Methods included from Format
#before, #format, layout_method_name, #view, view_method_name, view_setting_method_name, wrapper_method_name
Methods included from Inheritance
#include_set, #include_set_formats
Methods included from Trait
#card_accessor, #card_reader, #card_writer, #require_field
Methods included from Event::Api
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Card::Set::Helpers
Class Attribute Details
.basket ⇒ Object
Returns the value of attribute basket.
107 108 109 |
# File 'lib/card/set.rb', line 107 def basket @basket end |
.modules ⇒ Object
Returns the value of attribute modules.
107 108 109 |
# File 'lib/card/set.rb', line 107 def modules @modules end |
.traits ⇒ Object
Returns the value of attribute traits.
107 108 109 |
# File 'lib/card/set.rb', line 107 def traits @traits end |
Class Method Details
.reset ⇒ Object
109 110 111 112 113 114 115 116 117 |
# File 'lib/card/set.rb', line 109 def reset self.modules = { base: [], base_format: {}, nonbase: {}, nonbase_format: {}, abstract: {}, abstract_format: {} } self.basket = {} end |