Class: HotCocoaApplication

Inherits:
Object show all
Includes:
HotCocoa
Defined in:
lib/hotcocoa/mvc.rb

Constant Summary

Constants included from HotCocoa

HotCocoa::Behaviours, HotCocoa::VERSION

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HotCocoa

on_notification

Constructor Details

#initialize(application_file) ⇒ HotCocoaApplication

Returns a new instance of HotCocoaApplication.



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/hotcocoa/mvc.rb', line 23

def initialize application_file
  HotCocoaApplication.instance = self

  @controllers = {}
  load_controllers_and_views(directory_of(application_file))

  @shared_application = application(ApplicationView.options[:application])
  @shared_application.load_application_menu
  @application_controller = controller(:application_controller)

  shared_application.delegate_to(application_controller)
end

Class Attribute Details

.instanceHotCocoaApplication

The singleton instance of the application.

Returns:



20
21
22
# File 'lib/hotcocoa/mvc.rb', line 20

def instance
  @instance
end

Instance Attribute Details

#application_controllerObject

Returns [].

Returns:

  • []



10
11
12
# File 'lib/hotcocoa/mvc.rb', line 10

def application_controller
  @application_controller
end

#controllersObject

Returns [].

Returns:

  • []



13
14
15
# File 'lib/hotcocoa/mvc.rb', line 13

def controllers
  @controllers
end

#shared_applicationNSApplication

Returns:

  • (NSApplication)


7
8
9
# File 'lib/hotcocoa/mvc.rb', line 7

def shared_application
  @shared_application
end

Instance Method Details

#controller(controller_name) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/hotcocoa/mvc.rb', line 40

def controller controller_name
  controller_name_string = controller_name.to_s

  controller_class = if Object.const_get(controller_name_string !~ /_/ && controller_name_string =~ /[A-Z]+.*/)
    controller_name_string
  else
    controller_name_string.split('_').map { |e| e.capitalize }.join
  end

  @controllers[controller_name] || create_controller_instance(controller_name, controller_class)
end

#startObject



36
37
38
# File 'lib/hotcocoa/mvc.rb', line 36

def start
  @shared_application.run
end