Class: CMSScanner::Controllers

Inherits:
Array
  • Object
show all
Defined in:
lib/cms_scanner/controllers.rb

Overview

Controllers Container

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(option_parser = OptParseValidator::OptParser.new(nil, 40)) ⇒ Controllers

Returns a new instance of Controllers.

Parameters:

  • options_parser (OptParsevalidator::OptParser)


7
8
9
10
11
# File 'lib/cms_scanner/controllers.rb', line 7

def initialize(option_parser = OptParseValidator::OptParser.new(nil, 40))
  @option_parser = option_parser

  register_options_files
end

Instance Attribute Details

#option_parserObject (readonly)

Returns the value of attribute option_parser.



4
5
6
# File 'lib/cms_scanner/controllers.rb', line 4

def option_parser
  @option_parser
end

Instance Method Details

#<<(controller) ⇒ Object

Parameters:



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

def <<(controller)
  options = controller.cli_options

  unless include?(controller)
    option_parser.add(*options) if options
    super(controller)
  end
  self
end

#register_options_filesObject

Adds the potential option file paths to the option_parser



14
15
16
17
18
19
20
# File 'lib/cms_scanner/controllers.rb', line 14

def register_options_files
  [Dir.home, Dir.pwd].each do |dir|
    option_parser.options_files.supported_extensions.each do |ext|
      @option_parser.options_files << Pathname.new(dir).join(".#{NS.app_name}", "cli_options.#{ext}").to_s
    end
  end
end

#runObject



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/cms_scanner/controllers.rb', line 35

def run
  parsed_options             = option_parser.results
  first.class.parsed_options = parsed_options

  redirect_output_to_file(parsed_options[:output]) if parsed_options[:output]

  each(&:before_scan)
  each(&:run)
  # Reverse is used here as the app/controllers/core#after_scan finishes the output
  # and must be the last one to be executed
  reverse_each(&:after_scan)
end