Class: ApplicationInstance

Inherits:
EventdClient
  • Object
show all
Defined in:
lib/shot/application_instance.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(socket = nil) ⇒ ApplicationInstance

Initialize the superclass.

Note

Please use the ApplicationInstance#from_eventd_client method instead, since it is not usually a good idea to instantiate an EventdClient without a socket.



43
44
45
46
47
# File 'lib/shot/application_instance.rb', line 43

def initialize(socket = nil)
	super(socket)
	@config = {}
	@loaders = {}
end

Instance Attribute Details

#appObject

Main Application instance



16
17
18
# File 'lib/shot/application_instance.rb', line 16

def app
  @app
end

#configObject

App Configuration



19
20
21
# File 'lib/shot/application_instance.rb', line 19

def config
  @config
end

#loadersObject

Array of loaders



13
14
15
# File 'lib/shot/application_instance.rb', line 13

def loaders
  @loaders
end

Class Method Details

.from_eventd_client(client, app) ⇒ Object

Initialize a new ApplicationInstance from an existing EventdClient.

Note

This is the preferred way to initialize an ApplicationInstance.

Attributes

  • client - EventdClient to copy properties from.



29
30
31
32
33
34
35
# File 'lib/shot/application_instance.rb', line 29

def self.from_eventd_client(client, app)
	instance = ApplicationInstance.new
	instance.app = app
	instance.socket = client.socket
	instance.setup_socket
	instance
end

Instance Method Details

#add_loader(loader) ⇒ Object

Add a loader to the list of custom loaders the application supports.

Attributes

  • loader - A class which inherits from Loader



55
56
57
58
# File 'lib/shot/application_instance.rb', line 55

def add_loader(loader)
	loader_instance = loader.new self
	@loaders[loader_instance.type] = loader_instance
end

#get(type, file) ⇒ Object

Calls out to any available loader and loads the specified file



62
63
64
65
66
67
68
# File 'lib/shot/application_instance.rb', line 62

def get(type, file)
	if @loaders[type]
		@loaders[type].get file
	else
		raise LoaderNotFoundException.new "Could not load type #{type}"
	end
end