woyo-server 0.0.1.pre2 → 0.0.1
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 +4 -4
- data/bin/{woyo.rb → woyo} +7 -2
- data/lib/woyo/runner.rb +129 -0
- data/lib/woyo/server/server.rb +12 -3
- data/lib/woyo/server/version.rb +1 -1
- data/public/default.html +15 -0
- data/spec/spec_helper.rb +0 -1
- data/spec/woyo/server/{server_spec.rb → 1_server_spec.rb} +6 -3
- data/spec/woyo/server/runner_spec.rb +155 -0
- data/world/default.rb +76 -0
- metadata +13 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 463090a5a8f8f70bc5b6de114d5d1f57f26f08ac
|
4
|
+
data.tar.gz: 56378db7ab92e7fe2c062930987953fb7ec1da0b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d37fed73e100523edaa6a37019f62587549513cd7f2e2a4075bec8d0eff183a58ef23ed8fdf9f9c8c42c67e665b27d969007a0a0c5bc55a137bb7c48cab5fd6
|
7
|
+
data.tar.gz: 88d03ad3e5d1f022d655bdfa448c76dccc0a4755c3cf9f25db6d1f4c8a6a740d9c52c5ac5ef3da7a230a4817037ca1753a8b9ee971227f904305a0d17617cf57
|
data/bin/{woyo.rb → woyo}
RENAMED
@@ -1,7 +1,10 @@
|
|
1
1
|
#! /usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
require_relative '../lib/woyo/runner'
|
4
|
+
|
5
|
+
exit Woyo::Runner.run ARGV
|
6
|
+
|
7
|
+
=begin
|
5
8
|
|
6
9
|
@home_world = Woyo::World.new do
|
7
10
|
location :home do
|
@@ -50,4 +53,6 @@ end
|
|
50
53
|
|
51
54
|
Woyo::Server.set :world, @home_world
|
52
55
|
Woyo::Server.run!
|
56
|
+
|
57
|
+
=end
|
53
58
|
|
data/lib/woyo/runner.rb
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
require_relative 'server'
|
2
|
+
require 'logger'
|
3
|
+
|
4
|
+
module Woyo
|
5
|
+
|
6
|
+
class Runner
|
7
|
+
|
8
|
+
def self.run args, out: $stdout, err: $stderr
|
9
|
+
|
10
|
+
@args = args.dup
|
11
|
+
@out = out
|
12
|
+
@err = err
|
13
|
+
$stderr = @err if @err
|
14
|
+
$stdout = @out if @out
|
15
|
+
|
16
|
+
code = case @args.first
|
17
|
+
when 'new' then mode_new
|
18
|
+
when 'server' then mode_server
|
19
|
+
when 'console' then mode_console
|
20
|
+
end
|
21
|
+
return code if code
|
22
|
+
|
23
|
+
if @args.empty? || @args.include?('-h') || @args.include?('--help')
|
24
|
+
print_help
|
25
|
+
return 0
|
26
|
+
end
|
27
|
+
|
28
|
+
if @args.include?('-v') || @args.include?('--version')
|
29
|
+
print_version
|
30
|
+
return 0
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.fail msg, code
|
36
|
+
print_error msg
|
37
|
+
return code
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.mode_new
|
41
|
+
if @args.include?('-h') || @args.include?('--help')
|
42
|
+
print_help_new
|
43
|
+
return 0
|
44
|
+
end
|
45
|
+
mode, dir = @args.shift 2
|
46
|
+
if dir.nil?
|
47
|
+
print_error 'No directory provided'
|
48
|
+
return -1
|
49
|
+
end
|
50
|
+
if Dir.exists? dir
|
51
|
+
unless @args.include?('-f') || @args.include?('--force')
|
52
|
+
print_error 'Directory already exists'
|
53
|
+
return -2
|
54
|
+
end
|
55
|
+
end
|
56
|
+
if File.exists? dir
|
57
|
+
unless @args.include?('-f') || @args.include?('--force')
|
58
|
+
print_error 'File exists with same name'
|
59
|
+
return -3
|
60
|
+
end
|
61
|
+
end
|
62
|
+
FileUtils.mkdir_p dir
|
63
|
+
[ 'public', 'views', 'world' ].each do |subdir|
|
64
|
+
FileUtils.cp_r File.join( __dir__, '../../', subdir ), dir
|
65
|
+
end
|
66
|
+
return 0
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.mode_server
|
70
|
+
if @args.include?('-h') || @args.include?('--help')
|
71
|
+
print_help_server
|
72
|
+
return 0
|
73
|
+
end
|
74
|
+
Woyo::Server.run!
|
75
|
+
return 0
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.mode_console
|
79
|
+
if @args.include?('-h') || @args.include?('--help')
|
80
|
+
print_help_console
|
81
|
+
return 0
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def self.print_help
|
86
|
+
@err.puts "Usage: woyo ..."
|
87
|
+
@err.puts
|
88
|
+
@err.puts "............."
|
89
|
+
@err.puts "............."
|
90
|
+
@err.puts "............."
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.print_help_new
|
94
|
+
@err.puts "Usage: woyo new ..."
|
95
|
+
@err.puts
|
96
|
+
@err.puts "............."
|
97
|
+
@err.puts "............."
|
98
|
+
@err.puts "............."
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.print_help_server
|
102
|
+
@err.puts "Usage: woyo server ..."
|
103
|
+
@err.puts
|
104
|
+
@err.puts "............."
|
105
|
+
@err.puts "............."
|
106
|
+
@err.puts "............."
|
107
|
+
end
|
108
|
+
|
109
|
+
def self.print_help_console
|
110
|
+
@err.puts "Usage: woyo console ..."
|
111
|
+
@err.puts
|
112
|
+
@err.puts "............."
|
113
|
+
@err.puts "............."
|
114
|
+
@err.puts "............."
|
115
|
+
end
|
116
|
+
|
117
|
+
def self.print_error msg
|
118
|
+
@err.puts "Error: #{msg}"
|
119
|
+
end
|
120
|
+
|
121
|
+
def self.print_version
|
122
|
+
@err.puts "woyo server version #{Woyo::SERVER_VERSION}"
|
123
|
+
@err.puts "woyo world version #{Woyo::WORLD_VERSION}"
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
data/lib/woyo/server/server.rb
CHANGED
@@ -6,18 +6,27 @@ module Woyo
|
|
6
6
|
|
7
7
|
class Server < Sinatra::Application
|
8
8
|
|
9
|
+
def self.load_world
|
10
|
+
world = Woyo::World.new
|
11
|
+
Dir['world/*.rb'].each do |filename|
|
12
|
+
world.instance_eval File.read filename
|
13
|
+
end
|
14
|
+
world
|
15
|
+
end
|
16
|
+
|
9
17
|
configure do
|
10
|
-
set root: '.'
|
11
18
|
enable :sessions
|
19
|
+
set root: '.'
|
20
|
+
set world: self.load_world
|
12
21
|
end
|
13
22
|
|
14
23
|
def world
|
15
|
-
raise 'No world provided' unless settings.respond_to? :world
|
16
24
|
settings.world
|
17
25
|
end
|
18
26
|
|
19
27
|
get '/' do
|
20
|
-
|
28
|
+
redirect to '/default.html' if world.locations.empty?
|
29
|
+
@location ||= world.locations[:home] || world.locations.values.first
|
21
30
|
session[:location] = @location
|
22
31
|
haml :location
|
23
32
|
end
|
data/lib/woyo/server/version.rb
CHANGED
data/public/default.html
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<title>Welcome to WOYO - World Of Your Own</title>
|
4
|
+
</head>
|
5
|
+
<body>
|
6
|
+
<h1>Welcome to WOYO - World Of Your Own</h1>
|
7
|
+
<p>This is the default page on a Woyo server. You are seeing this page because the Woyo World has not been created yet.</p>
|
8
|
+
<p>To create the World, create and edit .rb files in the world/ directory.</p>
|
9
|
+
<h2>Links</h2>
|
10
|
+
<ul>
|
11
|
+
<li><a href='http://github.com/iqeo/woyo'>Woyo on github</a></li>
|
12
|
+
<li>...</li>
|
13
|
+
</ul>
|
14
|
+
</body>
|
15
|
+
</html>
|
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
+
require_relative '../../../lib/woyo/server'
|
1
2
|
require 'spec_helper.rb'
|
2
|
-
require 'woyo/server'
|
3
3
|
|
4
4
|
describe Woyo::Server, :type => :feature do
|
5
5
|
|
@@ -53,9 +53,12 @@ describe Woyo::Server, :type => :feature do
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
-
it '
|
56
|
+
it 'displays a welcome page if there is no world' do
|
57
|
+
# this must be the first test so that Woyo::Server.setting.world is not set
|
58
|
+
# that is why this file is name 1_server_spec.rb
|
57
59
|
visit '/'
|
58
|
-
status_code.should eq
|
60
|
+
status_code.should eq 200
|
61
|
+
page.should have_content 'Welcome'
|
59
62
|
end
|
60
63
|
|
61
64
|
it 'accepts a world' do
|
@@ -0,0 +1,155 @@
|
|
1
|
+
require_relative '../../../lib/woyo/runner'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'stringio'
|
4
|
+
require 'open-uri'
|
5
|
+
|
6
|
+
describe Woyo::Runner do
|
7
|
+
|
8
|
+
before :each do
|
9
|
+
@output = StringIO.new
|
10
|
+
@error = StringIO.new
|
11
|
+
end
|
12
|
+
|
13
|
+
before :all do
|
14
|
+
@original_path = Dir.pwd
|
15
|
+
File.basename(@original_path).should eq 'woyo-server'
|
16
|
+
@test_dir = 'tmp/test'
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'prints a helpful message to stderr for help (-h/--help) switch' do
|
20
|
+
[['-h'],['--help']].each do |args|
|
21
|
+
Woyo::Runner.run( args, out: @output, err: @error ).should eq 0
|
22
|
+
@error.string.should include 'woyo'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'prints version info to stderr for version (-v/--version) switch' do
|
27
|
+
[['-v'],['--version']].each do |args|
|
28
|
+
Woyo::Runner.run( args, out: @output, err: @error ).should eq 0
|
29
|
+
@error.string.should include 'woyo'
|
30
|
+
@error.string.should include Woyo::SERVER_VERSION
|
31
|
+
@error.string.should include Woyo::WORLD_VERSION
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'new' do
|
36
|
+
|
37
|
+
before :all do
|
38
|
+
@expected_entries = [ 'public', 'views', 'world' ]
|
39
|
+
end
|
40
|
+
|
41
|
+
before :each do
|
42
|
+
Dir.pwd.should eq @original_path
|
43
|
+
FileUtils.rm_rf @test_dir
|
44
|
+
FileUtils.mkdir_p @test_dir
|
45
|
+
Dir.chdir @test_dir
|
46
|
+
Dir.pwd.should eq File.join( @original_path, @test_dir )
|
47
|
+
end
|
48
|
+
|
49
|
+
after :each do
|
50
|
+
Dir.chdir @original_path
|
51
|
+
Dir.pwd.should eq @original_path
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'requires a directory be specified' do
|
55
|
+
Woyo::Runner.run( ['new'], out: @output, err: @error ).should eq -1
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'creates a world application directory' do
|
59
|
+
[['new','testworld'],['new','test/testworld']].each do |args|
|
60
|
+
Woyo::Runner.run( args, out: @output, err: @error ).should eq 0
|
61
|
+
Dir.should exist args[1]
|
62
|
+
(Dir.entries(args[1]) & @expected_entries).sort.should eq @expected_entries
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'populates directories' do
|
67
|
+
Woyo::Runner.run( ['new','testworld'], out: @output, err: @error ).should eq 0
|
68
|
+
@expected_entries.each do |dir|
|
69
|
+
dir_entries = Dir.entries(File.join('testworld',dir)).sort
|
70
|
+
dir_entries.count.should be > 2
|
71
|
+
original_entries = Dir.entries(File.join(@original_path,dir)).sort
|
72
|
+
(dir_entries & original_entries).should eq original_entries
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'requires force (-f/--force) for existing directory' do
|
77
|
+
[['new','testworld'],['new','test/testworld'],['new','.']].each do |args|
|
78
|
+
dir = args[1]
|
79
|
+
FileUtils.mkdir_p dir
|
80
|
+
Dir.should exist dir
|
81
|
+
Woyo::Runner.run( args, out: @output, err: @error ).should eq -2
|
82
|
+
[['--force'],['-f']].each do |force|
|
83
|
+
FileUtils.mkdir_p dir
|
84
|
+
Dir.should exist dir
|
85
|
+
Woyo::Runner.run( args + force, out: @output, err: @error ).should eq 0
|
86
|
+
Dir.should exist dir
|
87
|
+
(Dir.entries(dir) & @expected_entries).sort.should eq @expected_entries # subset
|
88
|
+
FileUtils.rm_rf dir
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'help (-h/--help) explains new command' do
|
94
|
+
[['-h'],['--help']].each do |help|
|
95
|
+
Woyo::Runner.run( ['new'] + help, out: @output, err: @error ).should eq 0
|
96
|
+
@error.string.should include 'woyo new'
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
context 'server' do
|
103
|
+
|
104
|
+
before :all do
|
105
|
+
Dir.pwd.should eq @original_path
|
106
|
+
FileUtils.rm_rf @test_dir
|
107
|
+
FileUtils.mkdir_p @test_dir
|
108
|
+
Dir.chdir @test_dir
|
109
|
+
Dir.pwd.should eq File.join( @original_path, @test_dir )
|
110
|
+
Woyo::Runner.run( ['new','testworld'], out: @output, err: @error ).should eq 0
|
111
|
+
Dir.chdir 'testworld'
|
112
|
+
Dir.pwd.should eq File.join( @original_path, @test_dir, 'testworld' )
|
113
|
+
end
|
114
|
+
|
115
|
+
after :all do
|
116
|
+
Dir.chdir @original_path
|
117
|
+
Dir.pwd.should eq @original_path
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'starts a world application server' do
|
121
|
+
thread = Thread.new { Woyo::Runner.run( ['server'], out: @output, err: @error ) }
|
122
|
+
thread.should be_alive
|
123
|
+
sleep 2
|
124
|
+
@error.string.should include 'has taken the stage'
|
125
|
+
Woyo::Server.set :world, Woyo::World.new { location(:home) { name 'Home' } }
|
126
|
+
page = ''
|
127
|
+
expect { page = open("http://127.0.0.1:4567/").read }.to_not raise_error
|
128
|
+
page.should include 'Home'
|
129
|
+
Woyo::Server.stop!
|
130
|
+
thread.join
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'help (-h/--help) explains server command' do
|
134
|
+
[['-h'],['--help']].each do |help|
|
135
|
+
Woyo::Runner.run( ['server'] + help, out: @output, err: @error ).should eq 0
|
136
|
+
@error.string.should include 'woyo server'
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
end
|
141
|
+
|
142
|
+
context 'console' do
|
143
|
+
|
144
|
+
it 'starts a world application console'
|
145
|
+
|
146
|
+
it 'help (-h/--help) explains console command' do
|
147
|
+
[['-h'],['--help']].each do |help|
|
148
|
+
Woyo::Runner.run( ['console'] + help, out: @output, err: @error ).should eq 0
|
149
|
+
@error.string.should include 'woyo console'
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|
154
|
+
|
155
|
+
end
|
data/world/default.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
|
2
|
+
=begin
|
3
|
+
|
4
|
+
# there may be multiple files in this world/ directory
|
5
|
+
# this is a Woyo world file
|
6
|
+
# it describe objects in a Woyo world
|
7
|
+
# it has an .rb extension
|
8
|
+
# it is just Ruby
|
9
|
+
# it is evaluated in the context of a Woyo::World instance
|
10
|
+
# methods avalable for World object creation include
|
11
|
+
# location
|
12
|
+
# character
|
13
|
+
# item
|
14
|
+
# etc...
|
15
|
+
|
16
|
+
# to see this example world in action delete the =begin and =end lines at the top and bottom of this file
|
17
|
+
|
18
|
+
location :home do
|
19
|
+
|
20
|
+
name 'Home'
|
21
|
+
description 'Where the heart is.'
|
22
|
+
|
23
|
+
way :out do
|
24
|
+
name 'Door'
|
25
|
+
description 'A sturdy wooden door, old fashioned farmhouse style of a bygone era.'
|
26
|
+
to :garden
|
27
|
+
end
|
28
|
+
|
29
|
+
way :down do
|
30
|
+
name 'Stairs'
|
31
|
+
description 'Rickety stairs lead down into darkness. A dank smell emanates from the darkness below'
|
32
|
+
to :cellar
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
location :garden do
|
38
|
+
|
39
|
+
name 'Garden'
|
40
|
+
description 'A peaceful green oasis of life in the midst of a gray city'
|
41
|
+
|
42
|
+
way :in do
|
43
|
+
name 'Door'
|
44
|
+
description 'Door leads inside a cute cottage'
|
45
|
+
to :home
|
46
|
+
end
|
47
|
+
|
48
|
+
way :down do
|
49
|
+
name 'Bulkhead'
|
50
|
+
description 'Rusty bulkhead door and stairs'
|
51
|
+
to :cellar
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
location :cellar do
|
57
|
+
|
58
|
+
name 'Cellar'
|
59
|
+
description 'Dark and damp, full of shadows and strange sounds'
|
60
|
+
|
61
|
+
way :out do
|
62
|
+
name 'Bulkhead'
|
63
|
+
description 'Rusty bulkhead stairs and door'
|
64
|
+
to :garden
|
65
|
+
end
|
66
|
+
|
67
|
+
way :up do
|
68
|
+
name 'Stairs'
|
69
|
+
description 'Rickety stairs lead up into light'
|
70
|
+
to :home
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
=end
|
76
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: woyo-server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1
|
4
|
+
version: 0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerard Fowley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -140,7 +140,7 @@ description: Game world server
|
|
140
140
|
email:
|
141
141
|
- gerard.fowley@iqeo.net
|
142
142
|
executables:
|
143
|
-
- woyo
|
143
|
+
- woyo
|
144
144
|
extensions: []
|
145
145
|
extra_rdoc_files: []
|
146
146
|
files:
|
@@ -151,15 +151,19 @@ files:
|
|
151
151
|
- LICENSE.txt
|
152
152
|
- README.md
|
153
153
|
- Rakefile
|
154
|
-
- bin/woyo
|
154
|
+
- bin/woyo
|
155
|
+
- lib/woyo/runner.rb
|
155
156
|
- lib/woyo/server.rb
|
156
157
|
- lib/woyo/server/server.rb
|
157
158
|
- lib/woyo/server/version.rb
|
159
|
+
- public/default.html
|
158
160
|
- spec/spec_helper.rb
|
159
|
-
- spec/woyo/server/
|
161
|
+
- spec/woyo/server/1_server_spec.rb
|
162
|
+
- spec/woyo/server/runner_spec.rb
|
160
163
|
- tmux
|
161
164
|
- views/layout.haml
|
162
165
|
- views/location.haml
|
166
|
+
- world/default.rb
|
163
167
|
- woyo-server.gemspec
|
164
168
|
homepage: ''
|
165
169
|
licenses:
|
@@ -176,9 +180,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
176
180
|
version: '0'
|
177
181
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
178
182
|
requirements:
|
179
|
-
- - "
|
183
|
+
- - ">="
|
180
184
|
- !ruby/object:Gem::Version
|
181
|
-
version:
|
185
|
+
version: '0'
|
182
186
|
requirements: []
|
183
187
|
rubyforge_project:
|
184
188
|
rubygems_version: 2.2.2
|
@@ -187,4 +191,5 @@ specification_version: 4
|
|
187
191
|
summary: World of Your Own
|
188
192
|
test_files:
|
189
193
|
- spec/spec_helper.rb
|
190
|
-
- spec/woyo/server/
|
194
|
+
- spec/woyo/server/1_server_spec.rb
|
195
|
+
- spec/woyo/server/runner_spec.rb
|