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

#extract_view_cache_rules(view, cache_rule) ⇒ Object



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

def extract_view_cache_rules view, cache_rule
  return unless cache_rule
  methodname = Card::Format.view_cache_setting_method view
  define_method(methodname) { cache_rule }
end

#interpret_view_opts(view, opts) ⇒ Object



93
94
95
96
97
# File 'lib/card/set/format.rb', line 93

def interpret_view_opts view, opts
  return unless opts.present?
  Card::Format.interpret_view_opts view, opts
  extract_view_cache_rules view, opts.delete(:cache)
end

#lookup_alias_block(view, args) ⇒ Object



109
110
111
112
113
114
115
116
117
# File 'lib/card/set/format.rb', line 109

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



85
86
87
88
89
90
91
# File 'lib/card/set/format.rb', line 85

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

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



105
106
107
# File 'lib/card/set/format.rb', line 105

def view_block view, args, &block
  block_given? ? block : lookup_alias_block(view, args)
end