Class: Yaframework::Base

Inherits:
Object
  • Object
show all
Includes:
Render
Defined in:
lib/yaframework/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Render

#partial, #render, #setup, #template_path, #view

Constructor Details

#initializeBase

Returns a new instance of Base.



14
15
16
17
18
19
20
# File 'lib/yaframework/base.rb', line 14

def initialize
  @routes = Hash.new([])
  @before_hooks = []
  @after_hooks  = []
  @settings = {}
  @inbox = {}
end

Instance Attribute Details

#envObject (readonly)

Returns the value of attribute env.



10
11
12
# File 'lib/yaframework/base.rb', line 10

def env
  @env
end

#requestObject (readonly) Also known as: req

Returns the value of attribute request.



10
11
12
# File 'lib/yaframework/base.rb', line 10

def request
  @request
end

#responseObject (readonly) Also known as: res

Returns the value of attribute response.



10
11
12
# File 'lib/yaframework/base.rb', line 10

def response
  @response
end

#routesObject (readonly)

Returns the value of attribute routes.



10
11
12
# File 'lib/yaframework/base.rb', line 10

def routes
  @routes
end

#settingsObject (readonly)

Returns the value of attribute settings.



10
11
12
# File 'lib/yaframework/base.rb', line 10

def settings
  @settings
end

Instance Method Details

#after(&block) ⇒ Object



51
52
53
# File 'lib/yaframework/base.rb', line 51

def after(&block)
  @after_hooks << block
end

#before(&block) ⇒ Object



47
48
49
# File 'lib/yaframework/base.rb', line 47

def before(&block)
  @before_hooks << block
end

#call(env) ⇒ Object



36
37
38
39
40
41
# File 'lib/yaframework/base.rb', line 36

def call(env)
  @env = env
  @request  = Yaframework::Request.new @env
  @response = Yaframework::Response.new
  catch(:halt) { route_eval }
end

#configure(&block) ⇒ Object



32
33
34
# File 'lib/yaframework/base.rb', line 32

def configure(&block)
  exec(block) if block_given?
end

#halt(response) ⇒ Object



43
44
45
# File 'lib/yaframework/base.rb', line 43

def halt(response)
  throw :halt, response
end

#handle(status, &block) ⇒ Object



59
60
61
# File 'lib/yaframework/base.rb', line 59

def handle(status, &block)
  @inbox[status] = block
end

#helpers(&block) ⇒ Object



28
29
30
# File 'lib/yaframework/base.rb', line 28

def helpers(&block)
  exec(block) if block_given?
end

#listen(port = 5000) ⇒ Object



63
64
65
# File 'lib/yaframework/base.rb', line 63

def listen(port = 5000)
  Rack::Handler::WEBrick.run self, Port: port
end

#paramsObject



55
56
57
# File 'lib/yaframework/base.rb', line 55

def params
  request.params
end