Module: Card::Set::Inheritance

Included in:
Card::Set
Defined in:
lib/card/set/inheritance.rb

Overview

API to inherit other sets and their formats

Instance Method Summary collapse

Instance Method Details

#include_set(set, opts = {}) ⇒ Object

include a set module and all its format modules

@example

include_set Type::Basic, except: :css

Parameters:

  • set (Module)
  • opts (Hash) (defaults to: {})

    choose the formats you want to include

Options Hash (opts):

  • :only (Symbol, Array<Symbol>)

    include only these formats

  • :except (Symbol, Array<Symbol>)

    don't include these formats



12
13
14
15
16
# File 'lib/card/set/inheritance.rb', line 12

def include_set set, opts={}
  set_type = set.abstract_set? ? :abstract : :nonbase
  add_set_modules Card::Set.modules[set_type][set.shortname]
  include_set_formats set, opts
end

#include_set_formats(set, opts = {}) ⇒ Object

include format modules of a set

@example

include_set Type::Basic, except: :css

Parameters:

  • set (Module)
  • opts (Hash) (defaults to: {})

    choose the formats you want to include

Options Hash (opts):

  • :only (Symbol, Array<Symbol>)

    include only these formats

  • :except (Symbol, Array<Symbol>)

    don't include these formats



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/card/set/inheritance.rb', line 25

def include_set_formats set, opts={}
  each_format set do |format, format_mods|
    format_sym = Card::Format.format_sym format
    next unless applicable_format?(format_sym, opts[:except], opts[:only])
    format_mods.each do |format_mod|
      define_on_format format_sym do
        include format_mod
      end
    end
  end
end