A “Set” is a group of cards to which “Rules” may be applied. Sets can be as specific as
a single card, as general as all cards, or anywhere in between.
Rules take two main forms: card rules and code rules.
"Card rules" are defined in card content. These are generally configured via the web
interface and are thus documented at http://wagn.org/rules.
"Code rules" can be defined in a "set file" within any "Mod" (short for both "module" and
"modification"). In accordance with Wagn's "MoVE" architecture, there are two main kinds of
code rules you can create in a set file: Views, and Events. Events are associated with the
Card class, and Views are associated with a Format class. You can also use set files to
add or override Card and/or Format methods directly. The majority of Card code is contained
in these files.
(FIXME - define mod, add generator)
Whenever you fetch or instantiate a card, it will automatically include all the
set modules defined in set files associated with sets of which it is a member. This
entails both simple model methods and "events", which are special methods explored
in greater detail below.
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 this:
mycard = Card.fetch 'Philipp+address'
...then mycard will include the set modules associated with each of those sets in the above
order. (The order is determined by the set pattern; see lib/card/set_pattern.rb for more
information about set_ptterns and mod/core/set/all/fetch.rb for more about fetching.)
Similarly, whenever a Format object is instantiated for a card, it includes all views
associated with BOTH (a) sets of which the card is a member and (b) the current format or
its ancestors. More on defining views below.
In order to have a set file associated with "all cards ending in +address", you could create
a file in mywagn/mod/mymod/set/right/address.rb. The recommended mechanism for doing so
is running `wagn generate set modname set_pattern set_anchor`. In the current example, this
would translate to `wagn generate set mymod right address`. Note that both the set_pattern
and the set_anchor must correspond to the codename of a card in the database to function
correctly but you can add arbitrary subdirectories to organize your code rules. The rule above
for example could be saved in mywagn/mod/mymod/set/right/address/america/north/canada.rb.
When a Card application loads, it uses these files to autogenerate a tmp_file that uses this set file to
createa Card::Set::Right::Address module which itself is extended with Card::Set. A set file
is "just ruby" but is generally quite concise because Card uses its file location to
autogenerate ruby module names and then uses Card::Set module to provide additional API.
View definitions
When you declare:
view :view_name do |args|
#...your code here
end
Methods are defined on the format
The external api with checks:
render(:viewname, args)