Class: Rubko::App

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/rubko/app.rb

Instance Attribute Summary collapse

Attributes included from Base

#parent

Instance Method Summary collapse

Methods included from Base

#camelize, #finalize, #httpGet, #jsonParse, #loadController, #loadFile, #loadModel, #loadPlugin, #loadView, #method_missing, #uncamelize

Constructor Details

#initialize(env, shared = nil) ⇒ App

Returns a new instance of App.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rubko/app.rb', line 7

def initialize(env, shared = nil)
	@status = 200
	@headers = {'Connection' => 'Keep-Alive', 'Date' => Time.now.httpdate}
	@mime = 'text/html'
	@body = ''

	@shared = shared
	@finalizers = []

	@env = env
	params = Rack::Utils.parse_nested_query env['rack.input'].read
	@params = Hash[ params.map { |k, v|
		[ k.to_sym, v ]
	} ]

	super()
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Rubko::Base

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



25
26
27
# File 'lib/rubko/app.rb', line 25

def body
  @body
end

#envObject (readonly)

Returns the value of attribute env.



26
27
28
# File 'lib/rubko/app.rb', line 26

def env
  @env
end

#finalizersObject (readonly)

Returns the value of attribute finalizers.



26
27
28
# File 'lib/rubko/app.rb', line 26

def finalizers
  @finalizers
end

#headersObject

Returns the value of attribute headers.



25
26
27
# File 'lib/rubko/app.rb', line 25

def headers
  @headers
end

#mimeObject

Returns the value of attribute mime.



25
26
27
# File 'lib/rubko/app.rb', line 25

def mime
  @mime
end

#paramsObject (readonly)

Returns the value of attribute params.



26
27
28
# File 'lib/rubko/app.rb', line 26

def params
  @params
end

#sharedObject (readonly)

Returns the value of attribute shared.



26
27
28
# File 'lib/rubko/app.rb', line 26

def shared
  @shared
end

#statusObject

Returns the value of attribute status.



25
26
27
# File 'lib/rubko/app.rb', line 25

def status
  @status
end

Instance Method Details

#init(path) ⇒ Object



28
29
30
31
# File 'lib/rubko/app.rb', line 28

def init(path)
	url.path = path
	request( *url.newPath )
end

#production?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/rubko/app.rb', line 57

def production?
	ENV['RACK_ENV'] == 'production'
end

#request(name = :welcome, action = nil, *path) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/rubko/app.rb', line 33

def request(name = :welcome, action = nil, *path)
	@controller = loadController(name) || loadController(:error404)

	calls = [ action ? "_#{action}" : 'index' ]
	calls << calls.first + '_' + url.method

	calls.map! { |call|
		if @controller.respond_to? call
			@body = @controller.__send__ call, *path
			true
		end
	}
	if calls.compact.empty?
		@body = @controller.other action, *path
	end

	# finalize request
	finalizers.reverse_each(&:finalize)
	prepareBody!
	prepareHeaders!

	[status, headers, body]
end