Class: Atelier::Application

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/atelier/application.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeApplication

Returns a new instance of Application.



14
15
16
17
18
19
20
21
22
# File 'lib/atelier/application.rb', line 14

def initialize
  @root_library = nil
  @logger = Logger.new(STDERR)
  @logger.level = Logger::WARN

  Kernel.send(:define_method, :library) do |name, &block|
    Application.instance.load_root_library(name, &block)
  end
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



12
13
14
# File 'lib/atelier/application.rb', line 12

def logger
  @logger
end

#root_libraryObject (readonly)

Returns the value of attribute root_library.



12
13
14
# File 'lib/atelier/application.rb', line 12

def root_library
  @root_library
end

Instance Method Details

#load_root_library(name, &block) ⇒ Object



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

def load_root_library(name, &block)
  @root_library = Library.new(name, &block)
end

#run(library_file, action, *parameters) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/atelier/application.rb', line 34

def run(library_file, action, *parameters)
  load(library_file)

  send_action(action, *parameters)
rescue Exception => e
  logger.error e
end

#send_action(action, *parameters) ⇒ Object



28
29
30
31
32
# File 'lib/atelier/application.rb', line 28

def send_action(action, *parameters)
  root_library.send(action, *parameters)
rescue Exception => e
  logger.error e
end