class Cranium::Application

Attributes

options[R]
sources[R]

Public Class Methods

new(arguments) click to toggle source
# File lib/cranium/application.rb, line 9
def initialize(arguments)
  @sources = Cranium::SourceRegistry.new
  @hooks = {}

  @options = Cranium::CommandLineOptions.new arguments
end

Public Instance Methods

after_import(&block) click to toggle source
# File lib/cranium/application.rb, line 51
def after_import(&block)
  register_hook :after_import, &block
end
apply_hook(name) click to toggle source
# File lib/cranium/application.rb, line 64
def apply_hook(name)
  unless @hooks[name].nil?
    @hooks[name].each do |block|
      block.call
    end
  end
end
cranium_arguments() click to toggle source
# File lib/cranium/application.rb, line 24
def cranium_arguments
  options.cranium_arguments
end
load_arguments() click to toggle source
# File lib/cranium/application.rb, line 18
def load_arguments
  options.load_arguments
end
register_hook(name, &block) click to toggle source
# File lib/cranium/application.rb, line 57
def register_hook(name, &block)
  @hooks[name] ||= []
  @hooks[name] << block
end
register_source(name, &block) click to toggle source
# File lib/cranium/application.rb, line 30
def register_source(name, &block)
  @sources.register_source(name, &block).resolve_files
end
run() click to toggle source
# File lib/cranium/application.rb, line 36
def run
  process_file = validate_file options.cranium_arguments[:load]

  begin
    load process_file
  rescue Exception => ex
    log :error, ex
    raise
  ensure
    apply_hook :after
  end
end

Private Instance Methods

exit_if_no_file_specified(file) click to toggle source
# File lib/cranium/application.rb, line 88
def exit_if_no_file_specified(file)
  if file.nil? || file.empty?
    $stderr.puts "ERROR: No file specified"
    exit 1
  end
end
exit_if_no_such_file_exists(file) click to toggle source
# File lib/cranium/application.rb, line 97
def exit_if_no_such_file_exists(file)
  unless File.exists? file
    $stderr.puts "ERROR: File '#{file}' does not exist"
    exit 1
  end
end
validate_file(load_file) click to toggle source
# File lib/cranium/application.rb, line 80
def validate_file(load_file)
  exit_if_no_file_specified load_file
  exit_if_no_such_file_exists load_file
  load_file
end