Module: Card::Format::Registration
- Included in:
- Card::Format
- Defined in:
- lib/card/format/registration.rb
Instance Method Summary collapse
- #class_from_name(formatname) ⇒ Object
- #extract_class_vars(view, opts) ⇒ Object
- #extract_view_tags(view, tags) ⇒ Object
- #format_ancestry ⇒ Object
- #format_class_name(format) ⇒ Object
- #format_sym(format) ⇒ Object
- #interpret_view_opts(view, opts) ⇒ Object
- #new(card, opts = {}) ⇒ Object
- #register(format) ⇒ Object
- #tagged(view, tag) ⇒ Object
- #view_cache_setting_method(view) ⇒ Object
Instance Method Details
#class_from_name(formatname) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/card/format/registration.rb', line 55 def class_from_name formatname if formatname == "Format" Card::Format else Card::Format.const_get formatname end end |
#extract_class_vars(view, opts) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/card/format/registration.rb', line 26 def extract_class_vars view, opts [:perms, :error_code, :denial, :closed].each do |varname| next unless (value = opts.delete varname) send(varname)[view] = value end end |
#extract_view_tags(view, tags) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/card/format/registration.rb', line 33 def view, return unless Array.wrap().each do |tag| [view] ||= {} [view][tag] = true end end |
#format_ancestry ⇒ Object
68 69 70 71 72 |
# File 'lib/card/format/registration.rb', line 68 def format_ancestry ancestry = [self] ancestry += superclass.format_ancestry unless self == Card::Format ancestry end |
#format_class_name(format) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/card/format/registration.rb', line 8 def format_class_name format format = format.to_s format = "" if format == "base" format = aliases[format] if aliases[format] "#{format.camelize}Format" end |
#format_sym(format) ⇒ Object
15 16 17 18 19 |
# File 'lib/card/format/registration.rb', line 15 def format_sym format return format if format.is_a? Symbol match = format.to_s.match(/::(?<format>[^:]+)Format/) match ? match[:format] : :base end |
#interpret_view_opts(view, opts) ⇒ Object
21 22 23 24 |
# File 'lib/card/format/registration.rb', line 21 def interpret_view_opts view, opts extract_class_vars view, opts view, opts.delete(:tags) end |
#new(card, opts = {}) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/card/format/registration.rb', line 45 def new card, opts={} if self != Format super else format = opts[:format] || :html klass = class_from_name format_class_name(format) self == klass ? super : klass.new(card, opts) end end |
#register(format) ⇒ Object
4 5 6 |
# File 'lib/card/format/registration.rb', line 4 def register format registered << format.to_s end |
#tagged(view, tag) ⇒ Object
63 64 65 66 |
# File 'lib/card/format/registration.rb', line 63 def tagged view, tag return unless view && tag && (viewhash = [view.to_sym]) viewhash[tag.to_sym] end |
#view_cache_setting_method(view) ⇒ Object
41 42 43 |
# File 'lib/card/format/registration.rb', line 41 def view_cache_setting_method view "view_#{view}_cache_setting" end |