Module: Card::Set::Format::AbstractFormat

Includes:
Basket
Defined in:
lib/card/set/format.rb

Overview

All Format modules are extended with this module in order to support the basic format API (ok, view definitions. It's just view definitions.) No longer just view definitions. Also basket definitions now.

Instance Method Summary collapse

Methods included from Basket

#abstract_basket, #add_to_basket, #basket

Instance Method Details

#lookup_alias_block(view, args) ⇒ Object



97
98
99
100
101
102
103
104
105
# File 'lib/card/set/format.rb', line 97

def lookup_alias_block view, args
  opts = args[0].is_a?(Hash) ? args.shift : { view: args.shift }
  opts[:mod] ||= self
  opts[:view] ||= view
  views[opts[:mod]][opts[:view]] || begin
    raise "cannot find #{opts[:view]} view in #{opts[:mod]}; " \
          "failed to alias #{view} in #{self}"
  end
end

#view(view, *args, &block) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/card/set/format.rb', line 84

def view view, *args, &block
  view = view.to_viewname.key.to_sym
  views[self] ||= {}
  view_block = views[self][view] =
                 if block_given?
                   Card::Format.extract_class_vars view, args[0]
                   block
                 else
                   lookup_alias_block view, args
                 end
  define_method "_view_#{view}", view_block
end