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, opts) ⇒ Object
- #format_ancestry ⇒ Object
- #format_class_name(format) ⇒ Object
- #format_sym(format) ⇒ Object
- #new(card, opts = {}) ⇒ Object
- #register(format) ⇒ Object
- #tagged(view, tag) ⇒ Object
Instance Method Details
#class_from_name(formatname) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/card/format/registration.rb', line 49 def class_from_name formatname if formatname == "Format" Card::Format else Card::Format.const_get formatname end end |
#extract_class_vars(view, opts) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/card/format/registration.rb', line 21 def extract_class_vars view, opts return unless opts.present? [:perms, :error_code, :denial, :closed].each do |varname| class_var = send varname class_var[view] = opts.delete(varname) if opts[varname] end view, opts end |
#extract_view_tags(view, opts) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/card/format/registration.rb', line 30 def view, opts = opts.delete :tags return unless Array.wrap().each do |tag| [view] ||= {} [view][tag] = true end end |
#format_ancestry ⇒ Object
62 63 64 65 66 |
# File 'lib/card/format/registration.rb', line 62 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 |
#new(card, opts = {}) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/card/format/registration.rb', line 39 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
57 58 59 60 |
# File 'lib/card/format/registration.rb', line 57 def tagged view, tag return unless view && tag && (viewhash = [view.to_sym]) viewhash[tag.to_sym] end |