Class: Sana

Inherits:
Object
  • Object
show all
Defined in:
lib/sana.rb,
lib/sana.rb

Overview

Ukagaka SHIORI submodule 'Sana'

Defined Under Namespace

Modules: ResponseHelper

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(events = Kernel) ⇒ Sana

initialize Sana



16
17
18
19
20
# File 'lib/sana.rb', line 16

def initialize(events = Kernel)
  @events = events
  @charset = 'UTF-8'
  @sender = 'Sana'
end

Instance Attribute Details

#charsetObject

default Charset header value



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

def charset
  @charset
end

#dirpathObject (readonly)

the ghost/master path



6
7
8
# File 'lib/sana.rb', line 6

def dirpath
  @dirpath
end

#eventsObject (readonly)

events object



8
9
10
# File 'lib/sana.rb', line 8

def events
  @events
end

#senderObject

default Sender header value



12
13
14
# File 'lib/sana.rb', line 12

def sender
  @sender
end

Instance Method Details

#load(dirpath) ⇒ Object

SHIORI load()



24
25
26
27
28
29
30
# File 'lib/sana.rb', line 24

def load(dirpath)
  @dirpath = dirpath
  begin
    events.send(:_load, dirpath)
  rescue NoMethodError
  end
end

#request(request_str) ⇒ String

SHIORI request()



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/sana.rb', line 43

def request(request_str)
  request = Shioruby.parse_request(request_str)
  if request.version[0] == '2'
    return build_response Sana::ResponseHelper.bad_request
  end
  begin
    response = events.send(request.ID, request)
  rescue NoMethodError
  end
  case response
  when OpenStruct
    build_response response
  else
    build_response Sana::ResponseHelper.ok response
  end
rescue => error
  case error
  when Shioruby::ParseError
    build_response Sana::ResponseHelper.bad_request
  else
    build_response Sana::ResponseHelper.internal_server_error
  end
end

#unloadObject

SHIORI unload()



33
34
35
36
37
38
# File 'lib/sana.rb', line 33

def unload
  begin
    events.send(:_unload)
  rescue NoMethodError
  end
end