Class: Cranium::Application
- Inherits:
-
Object
- Object
- Cranium::Application
- Includes:
- Logging
- Defined in:
- lib/cranium/application.rb
Instance Attribute Summary collapse
-
#sources ⇒ Object
readonly
Returns the value of attribute sources.
Instance Method Summary collapse
- #after_import(&block) ⇒ Object
- #apply_hook(name) ⇒ Object
- #cranium_arguments ⇒ Object
-
#initialize(arguments) ⇒ Application
constructor
A new instance of Application.
- #load_arguments ⇒ Object
- #register_hook(name, &block) ⇒ Object
- #register_source(name, &block) ⇒ Object
- #run ⇒ Object
Methods included from Logging
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 = {} = Cranium::CommandLineOptions.new arguments end |
Instance Attribute Details
#sources ⇒ Object (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_arguments ⇒ Object
24 25 26 |
# File 'lib/cranium/application.rb', line 24 def cranium_arguments .cranium_arguments end |
#load_arguments ⇒ Object
18 19 20 |
# File 'lib/cranium/application.rb', line 18 def load_arguments .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 |
#run ⇒ Object
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 .cranium_arguments[:load] begin load process_file rescue Exception => ex log :error, ex raise ensure apply_hook :after end end |