Module: Angelo::Base::DSL

Included in:
Angelo::Base
Defined in:
lib/angelo/base.rb,
lib/angelo/main.rb

Overview

Takes a block and/or modules that define methods that can be used from within request handlers. Methods can also be defined at the top level but they get defined as Object instance methods which isn’t good.

Instance Method Summary collapse

Instance Method Details

#addr(a = nil) ⇒ Object



23
24
25
26
# File 'lib/angelo/base.rb', line 23

def addr a = nil
  @addr = a if a
  @addr
end

#after(opts = {}, &block) ⇒ Object



86
87
88
# File 'lib/angelo/base.rb', line 86

def after opts = {}, &block
  filter :after, opts, &block
end

#before(opts = {}, &block) ⇒ Object



82
83
84
# File 'lib/angelo/base.rb', line 82

def before opts = {}, &block
  filter :before, opts, &block
end

#content_type(type) ⇒ Object



95
96
97
# File 'lib/angelo/base.rb', line 95

def content_type type
  Responder.content_type type
end

#default_headers(hs) ⇒ Object



99
100
101
# File 'lib/angelo/base.rb', line 99

def default_headers hs
  Responder.default_headers = Responder.default_headers.merge hs
end

#eventsource(path, headers = nil, &block) ⇒ Object



73
74
75
76
# File 'lib/angelo/base.rb', line 73

def eventsource path, headers = nil, &block
  path = ::Mustermann.new path
  routes[:get][path] = Responder::Eventsource.new headers, &block
end

#helpers(*args, &block) ⇒ Object



13
14
15
16
17
18
# File 'lib/angelo/main.rb', line 13

def helpers(*args, &block)
  args.each do |mod|
    include(mod)
  end
  block && class_exec(&block)
end

#log_level(ll = nil) ⇒ Object



33
34
35
36
# File 'lib/angelo/base.rb', line 33

def log_level ll = nil
  @log_level = ll if ll
  @log_level
end

#on_pong(&block) ⇒ Object



90
91
92
93
# File 'lib/angelo/base.rb', line 90

def on_pong &block
  @on_pong = block if block
  @on_pong
end

#ping_time(pt = nil) ⇒ Object



38
39
40
41
# File 'lib/angelo/base.rb', line 38

def ping_time pt = nil
  @ping_time = pt if pt
  @ping_time
end

#port(p = nil) ⇒ Object



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

def port p = nil
  @port = p if p
  @port
end

#public_dir(d = nil) ⇒ Object



52
53
54
55
# File 'lib/angelo/base.rb', line 52

def public_dir d = nil
  @public_dir = d if d
  File.join root, @public_dir
end

#reload_templates!(on = true) ⇒ Object



48
49
50
# File 'lib/angelo/base.rb', line 48

def reload_templates!(on = true)
  @reload_templates = on
end

#report_errors!Object



57
58
59
# File 'lib/angelo/base.rb', line 57

def report_errors!
  @report_errors = true
end

#task(name, &block) ⇒ Object



78
79
80
# File 'lib/angelo/base.rb', line 78

def task name, &block
  Angelo::Server.define_task name, &block
end

#views_dir(d = nil) ⇒ Object



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

def views_dir d = nil
  @views_dir = d if d
  File.join root, @views_dir
end

#websocket(path, &block) ⇒ Object



68
69
70
71
# File 'lib/angelo/base.rb', line 68

def websocket path, &block
  path = ::Mustermann.new path
  routes[:websocket][path] = Responder::Websocket.new nil, &block
end