class Reviser::Reviser

@author Renan Strauss

This class is basically here to give the user a generic and comprehensive way to use and customize the behavior of our tool. The main idea is that the user should not instantiate components himself, nor worry about the data these components exchange. It is the API entry point.

Public Class Methods

load(data) click to toggle source

Adds an entry with the specified data.

# File lib/reviser.rb, line 83
def self.load(data)
        raise ArgumentError unless data.has_key?(:component)

        data[:input_from] ||= nil
        data[:local] ||= false

        @@loaded_components.store data[:component],
        {
                :input_from => data[:input_from],
                :local => data[:local],
                :data => nil
        }
end
register(data) click to toggle source

Registers the specified extension (its methods will be available for analysis)

# File lib/reviser.rb, line 101
def self.register(data)
        raise ArgumentError unless data.has_key?(:extension)

        @@registered_extensions << data[:extension]
end
registered_extensions() click to toggle source
# File lib/reviser.rb, line 76
def self.registered_extensions
        @@registered_extensions
end
run() click to toggle source

Basically runs each loaded component. The exection order is based on the loading order.

# File lib/reviser.rb, line 119
def self.run
        raise RuntimeError unless @@setup

        if Cfg.has_key?(:options) && Cfg[:options].has_key?(:log_dir)
                FileUtils.mkdir Cfg[:options][:log_dir] unless Dir.exist? Cfg[:options][:log_dir]
        end

        #
        # Need to change this ASAP in order to
        # let users load their own components
        #
        @@loaded_components.each do |comp, conf|
                puts "[ " + "Running ".yellow + "#{Reviser.titleize comp}".blue + " ]"

                require_relative "reviser/components/#{comp}" unless conf[:local]

                namespace = conf[:local] && '' || 'Components::'
                param = ((conf[:input_from] != nil) && @@loaded_components[conf[:input_from]][:data]) || nil
                
                c = eval("#{namespace}#{Reviser.titleize comp}").new param

                begin
                        @@loaded_components[comp][:data] = c.work
                rescue Interrupt => i
                        puts 'Bye bye'
                rescue Gem::LoadError => e
                        puts 'Missing gem'.light_red + "\t" + e.message
                        exit
                rescue Exception => ex
                        puts 'Error'.red + "\t" + ex.message
                        exit
                end
                
                puts "[ " + "Done".green + " ]"
        end

        # To handle multiple loads
        # and calls to run
        @@loaded_components = {}
end
setup(config_file) click to toggle source

Loads the configuration from given config_file

# File lib/reviser.rb, line 110
def self.setup(config_file)
        Cfg.load config_file
        @@setup = true
end
titleize(str) click to toggle source

Quite handy

# File lib/reviser.rb, line 163
def self.titleize(str)
        str.split(/ |\_/).map(&:capitalize).join('')
end