Module: CMSScanner::Formatter::ClassMethods

Included in:
CMSScanner::Formatter
Defined in:
lib/cms_scanner/formatter.rb

Overview

Module to be able to do Formatter.load() & Formatter.availables and do that as well when the Formatter is included in another module

Instance Method Summary collapse

Instance Method Details

#availablesArray<String>

@note: the #load method above should then be used to create the associated formatter

Returns:

  • (Array<String>)

    The list of the available formatters (except the Base one)



26
27
28
29
30
31
32
33
# File 'lib/cms_scanner/formatter.rb', line 26

def availables
  formatters = NS::Formatter.constants.select do |const|
    name = NS::Formatter.const_get(const)
    name.is_a?(Class) && name != NS::Formatter::Base
  end

  formatters.map { |sym| sym.to_s.underscore.dasherize }
end

#load(format = nil, custom_views = nil) ⇒ Formatter::Base

Parameters:

  • format (String) (defaults to: nil)
  • custom_views (Array<String>) (defaults to: nil)

Returns:



15
16
17
18
19
20
21
22
# File 'lib/cms_scanner/formatter.rb', line 15

def load(format = nil, custom_views = nil)
  format ||= 'cli'
  custom_views ||= []

  f = const_get(format.tr('-', '_').camelize).new
  custom_views.each { |v| f.views_directories << v }
  f
end