whiskey 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +24 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +8 -0
- data/CHANGELOG.md +9 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +74 -0
- data/ROADMAP.md +13 -0
- data/Rakefile +24 -0
- data/bin/whiskey +17 -0
- data/lib/whiskey.rb +16 -0
- data/lib/whiskey/command.rb +30 -0
- data/lib/whiskey/command/build.rb +89 -0
- data/lib/whiskey/command/start_server.rb +15 -0
- data/lib/whiskey/command/templates/Gemfile +10 -0
- data/lib/whiskey/command/templates/LICENSE.txt +22 -0
- data/lib/whiskey/command/templates/Procfile +1 -0
- data/lib/whiskey/command/templates/Thorfile +4 -0
- data/lib/whiskey/command/templates/db/seed.rb +15 -0
- data/lib/whiskey/command/templates/gitignore +17 -0
- data/lib/whiskey/command/templates/lib/action.rb +3 -0
- data/lib/whiskey/command/templates/lib/controls.rb +7 -0
- data/lib/whiskey/command/templates/lib/controls/router_control.rb +19 -0
- data/lib/whiskey/command/templates/lib/controls/world_control.rb +6 -0
- data/lib/whiskey/command/templates/lib/example.rb +7 -0
- data/lib/whiskey/command/templates/lib/models.rb +3 -0
- data/lib/whiskey/command/templates/lib/models/account.rb +6 -0
- data/lib/whiskey/command/templates/lib/models/actor.rb +6 -0
- data/lib/whiskey/command/templates/lib/models/place.rb +6 -0
- data/lib/whiskey/command/templates/ruby-gemset +1 -0
- data/lib/whiskey/command/templates/ruby-version +1 -0
- data/lib/whiskey/command/templates/server.rb +20 -0
- data/lib/whiskey/server.rb +81 -0
- data/lib/whiskey/server/action.rb +22 -0
- data/lib/whiskey/server/configuration.rb +9 -0
- data/lib/whiskey/server/connection.rb +51 -0
- data/lib/whiskey/server/control.rb +33 -0
- data/lib/whiskey/server/cycle.rb +35 -0
- data/lib/whiskey/server/deserializer.rb +21 -0
- data/lib/whiskey/server/error.rb +79 -0
- data/lib/whiskey/server/handler.rb +17 -0
- data/lib/whiskey/server/interpretor.rb +32 -0
- data/lib/whiskey/server/receiver.rb +19 -0
- data/lib/whiskey/server/responder.rb +19 -0
- data/lib/whiskey/server/router.rb +45 -0
- data/lib/whiskey/server/serializer.rb +22 -0
- data/lib/whiskey/version.rb +3 -0
- data/spec/lib/command/build_spec.rb +5 -0
- data/spec/lib/command/start_server_spec.rb +5 -0
- data/spec/lib/command_spec.rb +5 -0
- data/spec/lib/server/configuration_spec.rb +5 -0
- data/spec/lib/server/connection_spec.rb +43 -0
- data/spec/lib/server/cycle_spec.rb +23 -0
- data/spec/lib/server/deserializer_spec.rb +11 -0
- data/spec/lib/server/error_spec.rb +5 -0
- data/spec/lib/server/handler_spec.rb +5 -0
- data/spec/lib/server/interpretor_spec.rb +5 -0
- data/spec/lib/server/receiver_spec.rb +5 -0
- data/spec/lib/server/responder_spec.rb +15 -0
- data/spec/lib/server/serializer_spec.rb +11 -0
- data/spec/lib/server_spec.rb +31 -0
- data/spec/spec_helper.rb +9 -0
- data/test/lib/whiskey/server/connection_test.rb +42 -0
- data/test/lib/whiskey/server/cycle_test.rb +16 -0
- data/test/lib/whiskey/server/handler_test.rb +18 -0
- data/whiskey.gemspec +39 -0
- metadata +383 -0
@@ -0,0 +1,32 @@
|
|
1
|
+
module Whiskey
|
2
|
+
class Server
|
3
|
+
class Interpretor
|
4
|
+
def initialize(input)
|
5
|
+
@instruction = input
|
6
|
+
@response = if has_resource? && has_verb?
|
7
|
+
Router.new(instruction.resource, instruction.verb, instruction.parameters)
|
8
|
+
else
|
9
|
+
Error.new(:not_found)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def response
|
14
|
+
@response.to_hash
|
15
|
+
end
|
16
|
+
|
17
|
+
def instruction
|
18
|
+
OpenStruct.new(@instruction)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def has_resource?
|
24
|
+
@instruction.has_key?("resource")
|
25
|
+
end
|
26
|
+
|
27
|
+
def has_verb?
|
28
|
+
@instruction.has_key?("verb")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Whiskey
|
2
|
+
class Server
|
3
|
+
class Receiver
|
4
|
+
attr_reader :deserializer
|
5
|
+
|
6
|
+
def initialize(input)
|
7
|
+
@deserializer = Deserializer.new(input)
|
8
|
+
end
|
9
|
+
|
10
|
+
def deserialize
|
11
|
+
deserializer.data
|
12
|
+
end
|
13
|
+
|
14
|
+
def valid?
|
15
|
+
deserializer.valid?
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Whiskey
|
2
|
+
class Server
|
3
|
+
class Responder
|
4
|
+
attr_reader :serializer
|
5
|
+
|
6
|
+
def initialize(output)
|
7
|
+
@serializer = Serializer.new(output)
|
8
|
+
end
|
9
|
+
|
10
|
+
def serialize
|
11
|
+
serializer.data
|
12
|
+
end
|
13
|
+
|
14
|
+
def valid?
|
15
|
+
serializer.valid?
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Whiskey
|
2
|
+
class Server
|
3
|
+
class Router
|
4
|
+
def initialize(resource, verb, parameters = {})
|
5
|
+
@control = resource
|
6
|
+
@action = verb.upcase
|
7
|
+
@body = parameters
|
8
|
+
|
9
|
+
@route = if control.safe_constantize && control_action.safe_constantize
|
10
|
+
Whiskey.logger.info("#{@action} /#{@control} #{@body.inspect}")
|
11
|
+
control_action.safe_constantize.new(body)
|
12
|
+
else
|
13
|
+
Error.new(:not_found)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def body
|
18
|
+
OpenStruct.new(@parameters)
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_hash
|
22
|
+
@route.to_hash
|
23
|
+
end
|
24
|
+
|
25
|
+
def control
|
26
|
+
"Controls::#{@control.classify}Control"
|
27
|
+
end
|
28
|
+
|
29
|
+
def action
|
30
|
+
case
|
31
|
+
when @action == "PULL" then "ListAction"
|
32
|
+
when @action == "PUSH" then "CreateAction"
|
33
|
+
when @action == "PULL" && parameters.id then "ShowAction"
|
34
|
+
when @action == "PUSH" && parameters.id then "UpdateAction"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def control_action
|
41
|
+
"#{control}::#{action}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Whiskey
|
2
|
+
class Server
|
3
|
+
class Serializer
|
4
|
+
attr_reader :data
|
5
|
+
|
6
|
+
def initialize(raw)
|
7
|
+
@errors = []
|
8
|
+
begin
|
9
|
+
@data = MultiJson.dump(raw)
|
10
|
+
@valid = true
|
11
|
+
rescue Exception => error
|
12
|
+
puts error
|
13
|
+
@valid = false
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def valid?
|
18
|
+
@valid
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Whiskey::Server::Connection do
|
4
|
+
describe "#initialize(socket)" do
|
5
|
+
pending
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "#id" do
|
9
|
+
pending
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#process" do
|
13
|
+
pending
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#cycle" do
|
17
|
+
pending
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#incoming" do
|
21
|
+
pending
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#port" do
|
25
|
+
pending
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#ip" do
|
29
|
+
pending
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#write(*args)" do
|
33
|
+
pending
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#readpartial(*args)" do
|
37
|
+
pending
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#peeraddr(*args)" do
|
41
|
+
pending
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Whiskey::Server::Cycle do
|
4
|
+
describe "#initialize(input)" do
|
5
|
+
pending
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "#interpret!" do
|
9
|
+
pending
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#output" do
|
13
|
+
pending
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#deserialized(input)" do
|
17
|
+
pending
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#serialized(response)" do
|
21
|
+
pending
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Whiskey::Server do
|
4
|
+
describe ".configure(configuration)" do
|
5
|
+
pending
|
6
|
+
end
|
7
|
+
|
8
|
+
describe ".start(configuration)" do
|
9
|
+
pending
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#server" do
|
13
|
+
pending
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#initialize" do
|
17
|
+
pending
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#run" do
|
21
|
+
pending
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#finalizer" do
|
25
|
+
pending
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#handle_connection" do
|
29
|
+
pending
|
30
|
+
end
|
31
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require "helper"
|
2
|
+
require "whiskey/server/connection"
|
3
|
+
|
4
|
+
class TestWhiskeyServerConnection < MiniTestCase
|
5
|
+
def setup
|
6
|
+
@socket = mock
|
7
|
+
@socket.stubs(:peeraddr).returns(["AF_INET", 9999, "foo.example.com", "127.0.0.1"])
|
8
|
+
@connection = Whiskey::Server::Connection.new(@socket)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_id
|
12
|
+
expected = "127.0.0.1:9999"
|
13
|
+
actual = @connection.id
|
14
|
+
assert_equal(expected, actual)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_socket
|
18
|
+
refute(@connection.socket.nil?, "Connection has no socket")
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_write
|
22
|
+
@socket.expects(:write).with("foo").at_least_once
|
23
|
+
@connection.write("foo")
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_readpartial
|
27
|
+
@socket.expects(:readpartial).with(4096).at_least_once
|
28
|
+
@connection.readpartial(4096)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_readpartial
|
32
|
+
@socket.expects(:peeraddr).at_least_once
|
33
|
+
@connection.peeraddr
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_cycle
|
37
|
+
Whiskey::Server::Connection.any_instance.stubs(:cycle)
|
38
|
+
@connection.expects(:write).at_least_once
|
39
|
+
@connection.process
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "helper"
|
2
|
+
require "whiskey/server/cycle"
|
3
|
+
|
4
|
+
class TestWhiskeyServerCycle < MiniTestCase
|
5
|
+
def setup
|
6
|
+
@cycle = Whiskey::Server::Cycle.new("foo")
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_initialize
|
10
|
+
Whiskey::Server::Cycle.any_instance.stubs(:deserialized)
|
11
|
+
expected = "foo"
|
12
|
+
actual = @cycle.to_s
|
13
|
+
assert_equal(expected, actual)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "helper"
|
2
|
+
require "whiskey/server"
|
3
|
+
|
4
|
+
class TestWhiskeyServerHandler < MiniTestCase
|
5
|
+
def setup
|
6
|
+
@connection = mock
|
7
|
+
@handler = Whiskey::Server::Handler.new(@connection)
|
8
|
+
end
|
9
|
+
|
10
|
+
# def initialize(socket)
|
11
|
+
# self.connection = Connection.new(socket)
|
12
|
+
# end
|
13
|
+
def test_initialize
|
14
|
+
expected = @connection
|
15
|
+
actual = @handler.connection
|
16
|
+
assert_equal(expected, actual)
|
17
|
+
end
|
18
|
+
end
|