Sha256: c4e0975c1cff586e7f72c5a4084bf9a08d8bf0d6b46031015f95093bd7906be9

Contents?: true

Size: 1.35 KB

Versions: 14

Compression:

Stored size: 1.35 KB

Contents

module CMSScanner
  # Controllers Container
  class Controllers < Array
    attr_reader :option_parser

    # @param [ OptParsevalidator::OptParser ] options_parser
    def initialize(option_parser = OptParseValidator::OptParser.new(nil, 40))
      @option_parser = option_parser

      register_options_files
    end

    # Adds the potential option file paths to the option_parser
    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

    # @param [ Controller::Base ] controller
    #
    # @retun [ Controllers ] self
    def <<(controller)
      options = controller.cli_options

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

    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
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
cms_scanner-0.0.39.0 lib/cms_scanner/controllers.rb
cms_scanner-0.0.38.4 lib/cms_scanner/controllers.rb
cms_scanner-0.0.38.3 lib/cms_scanner/controllers.rb
cms_scanner-0.0.38.2 lib/cms_scanner/controllers.rb
cms_scanner-0.0.38.1 lib/cms_scanner/controllers.rb
cms_scanner-0.0.38.0 lib/cms_scanner/controllers.rb
cms_scanner-0.0.37.12 lib/cms_scanner/controllers.rb
cms_scanner-0.0.37.11 lib/cms_scanner/controllers.rb
cms_scanner-0.0.37.10 lib/cms_scanner/controllers.rb
cms_scanner-0.0.37.9 lib/cms_scanner/controllers.rb
cms_scanner-0.0.37.8 lib/cms_scanner/controllers.rb
cms_scanner-0.0.37.7 lib/cms_scanner/controllers.rb
cms_scanner-0.0.37.6 lib/cms_scanner/controllers.rb
cms_scanner-0.0.37.5 lib/cms_scanner/controllers.rb