em-midori 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 63375f6e8a60a297804f655301642f3a4301bae3
4
- data.tar.gz: 7862191b4a720a0568759b8a325eec7f6e4d6277
3
+ metadata.gz: cde61e335c329326e0e04c9d2e433077923260ed
4
+ data.tar.gz: f866ca5439372bde2d084e4cded2f66c27283904
5
5
  SHA512:
6
- metadata.gz: ea4d98047259403a5c37ca083639a72b93612cc37e1879a2deecee2a2abca4aaccf25922df172d5a48750fea1cec614b4ccd07f5eddc85ea262d58e5d3d9971d
7
- data.tar.gz: c4860155f3ae3a2ae0861604c637c36fbe883d6a633e5bfa744fbafbd9db59c31945e8c5c1b278e74947375ff075dfa50944d548d18070ac6801bfb26a0ff610
6
+ metadata.gz: 93593618d3d46c284937ad42d1fce33e4fe7375644717744773b537fd1c8a8e9717b86334f5b968c4388b9fd40daece5a94b2b0ce5e9f9d89cd6c61cfd12916f
7
+ data.tar.gz: 28a9dae73071f578989377e7e312606a7a88feada47057b264e4e7363dbe1a5b3162f8c2926fd393d5208db769d4cf91c643590e1b588b5c22636f6e17810637
data/lib/em-midori.rb CHANGED
@@ -15,7 +15,7 @@ require_relative 'em-midori/core_ext/proc'
15
15
 
16
16
  require_relative 'em-midori/version'
17
17
  require_relative 'em-midori/const'
18
- require_relative 'em-midori/error'
18
+ require_relative 'em-midori/exception'
19
19
  require_relative 'em-midori/clean_room'
20
20
  require_relative 'em-midori/request'
21
21
  require_relative 'em-midori/response'
@@ -70,7 +70,7 @@ class Midori::APIEngine
70
70
  return response
71
71
  end
72
72
  end
73
- raise Midori::Error::NotFound
73
+ raise Midori::Exception::NotFound
74
74
  end
75
75
 
76
76
  # Return websocket header with given key
@@ -12,7 +12,7 @@ class Midori::EventSource
12
12
  # Send data and close the connection
13
13
  # @param [String] data data to be sent
14
14
  def send(data)
15
- raise Midori::Error::EventSourceTypeError unless data.is_a?String
15
+ raise Midori::Exception::EventSourceTypeError unless data.is_a? String
16
16
  @connection.send_data(data.split("\n").map {|str| "data: #{str}\n"}.join + "\n")
17
17
  @connection.close_connection_after_writing
18
18
  end
@@ -1,6 +1,6 @@
1
1
  ##
2
2
  # This module store errors to be handled inside Midori
3
- module Midori::Error
3
+ module Midori::Exception
4
4
  # No route matched
5
5
  class NotFound < StandardError; end
6
6
  # Internal Error
@@ -1,19 +1,11 @@
1
1
  class Midori::File
2
2
  class << self
3
- def read_promise(*args)
4
- defer { File.read(*args) }
5
- end
6
-
7
3
  def read(*args)
8
- await read_promise(*args)
9
- end
10
-
11
- def write_promise(*args)
12
- defer { File.write(*args) }
4
+ await(defer{File.read(*args)})
13
5
  end
14
6
 
15
7
  def write(*args)
16
- await write_promise(*args)
8
+ await(defer{File.write(*args)})
17
9
  end
18
10
  end
19
11
  end
@@ -0,0 +1,21 @@
1
+ class Midori::Postgres
2
+ def initialize(*args)
3
+ @db = EM.connect(*args, EM::P::Postgres3)
4
+ end
5
+
6
+ def connect(db_name, username, password)
7
+ await(Promise.new(->(resolve, _reject) {
8
+ @db.connect(db_name, username, password).callback do |status|
9
+ resolve.call(status)
10
+ end
11
+ }))
12
+ end
13
+
14
+ def query(sql)
15
+ await(Promise.new(->(resolve, _reject) {
16
+ @db.query(sql).callback do |status, result, errors|
17
+ status ? resolve.call(result) : (puts errors; raise RuntimeError)
18
+ end
19
+ }))
20
+ end
21
+ end
@@ -2,8 +2,8 @@ class Midori::Sandbox
2
2
  class << self
3
3
  def class_initialize
4
4
  @handlers = Hash.new
5
- @handlers[Midori::Error::InternalError] = proc {|_e| Midori::Response.new(500, {}, 'Internal Server Error')}
6
- @handlers[Midori::Error::NotFound] = proc {|_e| Midori::Response.new(404, {}, '404 Not Found')}
5
+ @handlers[Midori::Exception::InternalError] = proc {|_e| Midori::Response.new(500, {}, 'Internal Server Error')}
6
+ @handlers[Midori::Exception::NotFound] = proc {|_e| Midori::Response.new(404, {}, '404 Not Found')}
7
7
  end
8
8
 
9
9
  def add_rule(class_name, block)
@@ -12,7 +12,7 @@ class Midori::Sandbox
12
12
 
13
13
  def capture(error)
14
14
  if @handlers[error.class].nil?
15
- @handlers[Midori::Error::InternalError].call(error)
15
+ @handlers[Midori::Exception::InternalError].call(error)
16
16
  else
17
17
  @handlers[error.class].call(error)
18
18
  end
@@ -44,7 +44,7 @@ module Midori::Server
44
44
  @request.parse(data)
45
45
  @response = @api.receive(request, self)
46
46
  call_event(:open) if @request.websocket?
47
- rescue Midori::Error::NotFound => e
47
+ rescue Midori::Exception::NotFound => e
48
48
  @response = Midori::Sandbox.capture(e)
49
49
  rescue => e
50
50
  @response = Midori::Sandbox.capture(e)
@@ -70,11 +70,11 @@ module Midori::Server
70
70
  when 0xA
71
71
  call_event(:pong)
72
72
  end
73
- rescue Midori::Error::FrameEnd => _e
73
+ rescue Midori::Exception::FrameEnd => _e
74
74
  call_event(:close)
75
75
  send_data "\b" # Opcode 0x8
76
76
  close_connection_after_writing
77
- rescue Midori::Error::PingPongSizeTooLarge => e
77
+ rescue Midori::Exception::PingPongSizeTooLarge => e
78
78
  @logger.warn e.inspect.yellow
79
79
  call_event(:error) # Too large ping request
80
80
  send_data "\b" # Opcode 0x8
@@ -1,5 +1,5 @@
1
1
  # Midori Module
2
2
  module Midori
3
3
  # Current Version Code
4
- VERSION = '0.1.3'.freeze
4
+ VERSION = '0.1.4'.freeze
5
5
  end
@@ -21,8 +21,8 @@ class Midori::WebSocket
21
21
  fin = byte_tmp & 0b10000000
22
22
  @opcode = byte_tmp & 0b00001111
23
23
  # NOT Support Multiple Fragments
24
- raise Midori::Error::ContinuousFrame unless fin
25
- raise Midori::Error::OpCodeError unless [0x1, 0x2, 0x8, 0x9, 0xA].include?opcode
24
+ raise Midori::Exception::ContinuousFrame unless fin
25
+ raise Midori::Exception::OpCodeError unless [0x1, 0x2, 0x8, 0x9, 0xA].include? opcode
26
26
  close if @opcode == 0x8 # Close Frame
27
27
  # return if @opcode == 0x9 || @opcode == 0xA # Ping Pong
28
28
  decode_mask(data)
@@ -34,7 +34,7 @@ class Midori::WebSocket
34
34
  # Mask
35
35
  byte_tmp = data.getbyte
36
36
  is_masked = byte_tmp & 0b10000000
37
- raise Midori::Error::NotMasked unless is_masked == 128
37
+ raise Midori::Exception::NotMasked unless is_masked == 128
38
38
  # Payload
39
39
  payload = byte_tmp & 0b01111111
40
40
  mask = Array.new(4) { data.getbyte }
@@ -72,7 +72,7 @@ class Midori::WebSocket
72
72
  output.concat msg
73
73
  @connection.send_data(output.pack('C*'))
74
74
  else
75
- raise Midori::Error::OpCodeError
75
+ raise Midori::Exception::OpCodeError
76
76
  end
77
77
  end
78
78
 
@@ -92,12 +92,12 @@ class Midori::WebSocket
92
92
  # @param [Fixnum] method opcode
93
93
  # @param [String] str string to send
94
94
  def heartbeat(method, str)
95
- raise Midori::Error::PingPongSizeTooLarge if str.size > 125
95
+ raise Midori::Exception::PingPongSizeTooLarge if str.size > 125
96
96
  @connection.send_data [method, str.size, str].pack("CCA#{str.size}")
97
97
  end
98
98
 
99
99
  # Close a websocket connection
100
100
  def close
101
- raise Midori::Error::FrameEnd
101
+ raise Midori::Exception::FrameEnd
102
102
  end
103
103
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: em-midori
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - HeckPsi Lab
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-27 00:00:00.000000000 Z
11
+ date: 2016-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eventmachine
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: postgres-pr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.7'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.7'
55
69
  description: EM Midori is an EventMachine-based Web Framework written in pure Ruby,
56
70
  providing high performance and proper abstraction.
57
71
  email: business@heckpsi.com
@@ -72,9 +86,10 @@ files:
72
86
  - lib/em-midori/core_ext/proc.rb
73
87
  - lib/em-midori/core_ext/promise.rb
74
88
  - lib/em-midori/core_ext/string.rb
75
- - lib/em-midori/error.rb
76
89
  - lib/em-midori/eventsource.rb
90
+ - lib/em-midori/exception.rb
77
91
  - lib/em-midori/extension/file.rb
92
+ - lib/em-midori/extension/postgres.rb
78
93
  - lib/em-midori/middleware.rb
79
94
  - lib/em-midori/request.rb
80
95
  - lib/em-midori/response.rb