Class: Freddie::Handlers::Base
- Inherits:
-
Object
- Object
- Freddie::Handlers::Base
show all
- Defined in:
- lib/freddie/handlers.rb
Overview
Base class for all handlers.
Direct Known Subclasses
Application, Javascript, OmniAuth, Path, RedirectTo, Render, Resource, Run, SendFile, Stylesheet, Template
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(*args, &block) ⇒ Base
Returns a new instance of Base.
15
16
17
18
|
# File 'lib/freddie/handlers.rb', line 15
def initialize(*args, &block)
@args = args
@block = block
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/freddie/handlers.rb', line 75
def method_missing(name, *args, &block)
klass_name = "Freddie::Handlers::#{name.to_s.classify}"
unless finished?
klass = klass_name.constantize or raise MissingHandlerError, "Could not locate #{klass_name}"
klass.new(*args, &block).tap do |handler|
handler.call(env)
end
end
end
|
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
7
8
9
|
# File 'lib/freddie/handlers.rb', line 7
def args
@args
end
|
#block ⇒ Object
Returns the value of attribute block.
7
8
9
|
# File 'lib/freddie/handlers.rb', line 7
def block
@block
end
|
#env ⇒ Object
Returns the value of attribute env.
7
8
9
|
# File 'lib/freddie/handlers.rb', line 7
def env
@env
end
|
Class Method Details
.call(env) ⇒ Object
10
11
12
|
# File 'lib/freddie/handlers.rb', line 10
def call(env)
new.call(env)
end
|
Instance Method Details
30
|
# File 'lib/freddie/handlers.rb', line 30
def after_perform ; end
|
28
|
# File 'lib/freddie/handlers.rb', line 28
def before_perform ; end
|
#call(env) ⇒ Object
20
21
22
23
24
25
26
|
# File 'lib/freddie/handlers.rb', line 20
def call(env)
@env = env
before_perform
perform
after_perform
response
end
|
#context ⇒ Object
32
33
34
|
# File 'lib/freddie/handlers.rb', line 32
def context
env['freddie.context'] ||= Context.new(env)
end
|
#finish! ⇒ Object
56
57
58
|
# File 'lib/freddie/handlers.rb', line 56
def finish!
env['freddie.finished'] = true
end
|
#finished? ⇒ Boolean
60
61
62
|
# File 'lib/freddie/handlers.rb', line 60
def finished?
env['freddie.finished']
end
|
#layout(name) ⇒ Object
52
53
54
|
# File 'lib/freddie/handlers.rb', line 52
def layout(name)
env['freddie.layout'] = name
end
|
#params ⇒ Object
44
45
46
|
# File 'lib/freddie/handlers.rb', line 44
def params
context.params
end
|
29
|
# File 'lib/freddie/handlers.rb', line 29
def perform(*args) ; end
|
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/freddie/handlers.rb', line 64
def perform_freddie_block
if block
if block.arity == 1
block.call(self)
else
instance_exec &block
end
end
end
|
#request ⇒ Object
40
41
42
|
# File 'lib/freddie/handlers.rb', line 40
def request
context.request
end
|
#response ⇒ Object
36
37
38
|
# File 'lib/freddie/handlers.rb', line 36
def response
context.response
end
|
#session ⇒ Object
48
49
50
|
# File 'lib/freddie/handlers.rb', line 48
def session
context.request.session
end
|