Class: Cranium::Application

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/cranium/application.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#log, #record_metric

Constructor Details

#initialize(arguments) ⇒ Application

Returns a new instance of Application.



9
10
11
12
13
14
# File 'lib/cranium/application.rb', line 9

def initialize(arguments)
  @sources = Cranium::SourceRegistry.new
  @hooks = {}

  @options = Cranium::CommandLineOptions.new arguments
end

Instance Attribute Details

#sourcesObject (readonly)

Returns the value of attribute sources.



5
6
7
# File 'lib/cranium/application.rb', line 5

def sources
  @sources
end

Instance Method Details

#after_import(&block) ⇒ Object



51
52
53
# File 'lib/cranium/application.rb', line 51

def after_import(&block)
  register_hook :after_import, &block
end

#apply_hook(name) ⇒ Object



64
65
66
67
68
69
70
# 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_argumentsObject



24
25
26
# File 'lib/cranium/application.rb', line 24

def cranium_arguments
  options.cranium_arguments
end

#load_argumentsObject



18
19
20
# File 'lib/cranium/application.rb', line 18

def load_arguments
  options.load_arguments
end

#register_hook(name, &block) ⇒ Object



57
58
59
60
# File 'lib/cranium/application.rb', line 57

def register_hook(name, &block)
  @hooks[name] ||= []
  @hooks[name] << block
end

#register_source(name, &block) ⇒ Object



30
31
32
# File 'lib/cranium/application.rb', line 30

def register_source(name, &block)
  @sources.register_source(name, &block).resolve_files
end

#runObject



36
37
38
39
40
41
42
43
44
45
46
47
# 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