module CMSScanner::Formatter::ClassMethods

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

Public Instance Methods

availables() click to toggle source

@return [ Array<String> ] The list of the available formatters (except the Base one) @note: the load method above should then be used to create the associated formatter

# 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) click to toggle source

@param [ String ] format @param [ Array<String> ] custom_views

@return [ Formatter::Base ]

# 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