syntropy 0.3 → 0.5
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/.rubocop.yml +10 -2
- data/CHANGELOG.md +14 -0
- data/README.md +30 -11
- data/TODO.md +135 -0
- data/bin/syntropy +3 -3
- data/cmd/setup/template/site/.gitignore +57 -0
- data/cmd/setup/template/site/Dockerfile +32 -0
- data/cmd/setup/template/site/Gemfile +3 -0
- data/cmd/setup/template/site/README.md +0 -0
- data/cmd/setup/template/site/bin/console +0 -0
- data/cmd/setup/template/site/bin/restart +0 -0
- data/cmd/setup/template/site/bin/server +0 -0
- data/cmd/setup/template/site/bin/start +0 -0
- data/cmd/setup/template/site/bin/stop +0 -0
- data/cmd/setup/template/site/docker-compose.yml +51 -0
- data/cmd/setup/template/site/proxy/Dockerfile +5 -0
- data/cmd/setup/template/site/proxy/etc/Caddyfile +7 -0
- data/cmd/setup/template/site/proxy/etc/tls_auto +2 -0
- data/cmd/setup/template/site/proxy/etc/tls_cloudflare +4 -0
- data/cmd/setup/template/site/proxy/etc/tls_custom +1 -0
- data/cmd/setup/template/site/proxy/etc/tls_selfsigned +1 -0
- data/cmd/setup/template/site/site/_layout/default.rb +11 -0
- data/cmd/setup/template/site/site/about.md +6 -0
- data/cmd/setup/template/site/site/articles/cage.rb +29 -0
- data/cmd/setup/template/site/site/articles/index.rb +3 -0
- data/cmd/setup/template/site/site/assets/css/style.css +40 -0
- data/cmd/setup/template/site/site/assets/img/syntropy.png +0 -0
- data/cmd/setup/template/site/site/index.rb +15 -0
- data/docker-compose.yml +51 -0
- data/lib/syntropy/app.rb +112 -134
- data/lib/syntropy/errors.rb +16 -2
- data/lib/syntropy/file_watch.rb +5 -4
- data/lib/syntropy/module.rb +26 -5
- data/lib/syntropy/request_extensions.rb +96 -0
- data/lib/syntropy/router.rb +208 -0
- data/lib/syntropy/rpc_api.rb +26 -9
- data/lib/syntropy/side_run.rb +46 -0
- data/lib/syntropy/version.rb +1 -1
- data/lib/syntropy.rb +15 -49
- data/syntropy.gemspec +1 -1
- data/test/app/baz.rb +3 -0
- data/test/app_custom/_site.rb +3 -0
- data/test/test_app.rb +96 -51
- data/test/test_file_watch.rb +4 -4
- data/test/test_router.rb +90 -0
- data/test/test_side_run.rb +43 -0
- data/test/test_validation.rb +1 -1
- metadata +34 -3
data/test/test_router.rb
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'helper'
|
4
|
+
|
5
|
+
class RouterTest < Minitest::Test
|
6
|
+
APP_ROOT = File.join(__dir__, 'app')
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@machine = UM.new
|
10
|
+
|
11
|
+
@tmp_path = '/test/tmp'
|
12
|
+
@tmp_fn = File.join(APP_ROOT, 'tmp.rb')
|
13
|
+
|
14
|
+
@router = Syntropy::Router.new(
|
15
|
+
machine: @machine,
|
16
|
+
location: APP_ROOT,
|
17
|
+
mount_path: '/test',
|
18
|
+
watch_files: 0.05
|
19
|
+
)
|
20
|
+
@router.start_file_watcher
|
21
|
+
end
|
22
|
+
|
23
|
+
def full_path(fn)
|
24
|
+
File.join(APP_ROOT, fn)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_find_route
|
28
|
+
# entry = @router['/']
|
29
|
+
# assert_equal :not_found, entry[:kind]
|
30
|
+
|
31
|
+
entry = @router['/test']
|
32
|
+
assert_equal :static, entry[:kind]
|
33
|
+
assert_equal full_path('index.html'), entry[:fn]
|
34
|
+
|
35
|
+
entry = @router['/test/about']
|
36
|
+
assert_equal :module, entry[:kind]
|
37
|
+
assert_equal full_path('about/index.rb'), entry[:fn]
|
38
|
+
|
39
|
+
entry = @router['/test/../test_app.rb']
|
40
|
+
assert_equal :not_found, entry[:kind]
|
41
|
+
|
42
|
+
entry = @router['/test/_layout/default']
|
43
|
+
assert_equal :not_found, entry[:kind]
|
44
|
+
|
45
|
+
entry = @router['/test/api']
|
46
|
+
assert_equal :module, entry[:kind]
|
47
|
+
assert_equal full_path('api+.rb'), entry[:fn]
|
48
|
+
|
49
|
+
entry = @router['/test/api/foo/bar']
|
50
|
+
assert_equal :module, entry[:kind]
|
51
|
+
assert_equal full_path('api+.rb'), entry[:fn]
|
52
|
+
|
53
|
+
entry = @router['/test/api/foo/../bar']
|
54
|
+
assert_equal :not_found, entry[:kind]
|
55
|
+
|
56
|
+
entry = @router['/test/api_1']
|
57
|
+
assert_equal :not_found, entry[:kind]
|
58
|
+
|
59
|
+
entry = @router['/test/about/foo']
|
60
|
+
assert_equal :markdown, entry[:kind]
|
61
|
+
assert_equal full_path('about/foo.md'), entry[:fn]
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_router_file_watching
|
65
|
+
@machine.sleep 0.2
|
66
|
+
|
67
|
+
entry = @router[@tmp_path]
|
68
|
+
assert_equal :module, entry[:kind]
|
69
|
+
|
70
|
+
# remove file
|
71
|
+
orig_body = IO.read(@tmp_fn)
|
72
|
+
FileUtils.rm(@tmp_fn)
|
73
|
+
@machine.sleep(0.3)
|
74
|
+
|
75
|
+
entry = @router[@tmp_path]
|
76
|
+
assert_equal :not_found, entry[:kind]
|
77
|
+
|
78
|
+
IO.write(@tmp_fn, 'foobar')
|
79
|
+
@machine.sleep(0.3)
|
80
|
+
entry = @router[@tmp_path]
|
81
|
+
assert_equal :module, entry[:kind]
|
82
|
+
|
83
|
+
entry[:proc] = ->(x) { x }
|
84
|
+
IO.write(@tmp_fn, 'barbaz')
|
85
|
+
@machine.sleep(0.3)
|
86
|
+
assert_nil entry[:proc]
|
87
|
+
ensure
|
88
|
+
IO.write(@tmp_fn, orig_body) if orig_body
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'helper'
|
4
|
+
|
5
|
+
class SideRunTest < Minitest::Test
|
6
|
+
def setup
|
7
|
+
@machine = UM.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_side_run
|
11
|
+
x = Syntropy::SideRun.call(@machine) { 42 }
|
12
|
+
assert_equal 42, x
|
13
|
+
|
14
|
+
hits = []
|
15
|
+
f = @machine.spin {
|
16
|
+
@machine.periodically(0.01) { hits << it }
|
17
|
+
}
|
18
|
+
|
19
|
+
y = Syntropy::SideRun.call(@machine) { sleep 0.10; 43 }
|
20
|
+
@machine.schedule(f, UM::Terminate.new)
|
21
|
+
assert_in_range 9..11, hits.size
|
22
|
+
end
|
23
|
+
|
24
|
+
class Bad < Exception
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_side_run_exception
|
28
|
+
assert_raises(Bad) { Syntropy::SideRun.call(@machine) { raise Bad } }
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_side_run_convenience_method
|
32
|
+
Syntropy.machine = nil
|
33
|
+
assert_raises { Syntropy.side_run { 42 } }
|
34
|
+
|
35
|
+
Syntropy.machine = @machine
|
36
|
+
x = Syntropy.side_run { 42 }
|
37
|
+
assert_equal 42, x
|
38
|
+
|
39
|
+
assert_raises(Bad) { Syntropy.side_run { raise Bad } }
|
40
|
+
ensure
|
41
|
+
Syntropy.machine = nil
|
42
|
+
end
|
43
|
+
end
|
data/test/test_validation.rb
CHANGED
@@ -27,7 +27,7 @@ class ValidationTest < Minitest::Test
|
|
27
27
|
assert_raises(VE) { @req.validate_param(:q, Integer) }
|
28
28
|
assert_raises(VE) { @req.validate_param(:q, Float) }
|
29
29
|
assert_raises(VE) { @req.validate_param(:q, nil) }
|
30
|
-
|
30
|
+
|
31
31
|
assert_raises(VE) { @req.validate_param(:y, Integer, 1..100) }
|
32
32
|
|
33
33
|
assert_raises(VE) { @req.validate_param(:y, :bool) }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: syntropy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.5'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sharon Rosner
|
@@ -71,14 +71,14 @@ dependencies:
|
|
71
71
|
requirements:
|
72
72
|
- - '='
|
73
73
|
- !ruby/object:Gem::Version
|
74
|
-
version: 0.
|
74
|
+
version: 0.13.2
|
75
75
|
type: :runtime
|
76
76
|
prerelease: false
|
77
77
|
version_requirements: !ruby/object:Gem::Requirement
|
78
78
|
requirements:
|
79
79
|
- - '='
|
80
80
|
- !ruby/object:Gem::Version
|
81
|
-
version: 0.
|
81
|
+
version: 0.13.2
|
82
82
|
- !ruby/object:Gem::Dependency
|
83
83
|
name: uringmachine
|
84
84
|
requirement: !ruby/object:Gem::Requirement
|
@@ -166,13 +166,40 @@ files:
|
|
166
166
|
- Rakefile
|
167
167
|
- TODO.md
|
168
168
|
- bin/syntropy
|
169
|
+
- cmd/setup/template/site/.gitignore
|
170
|
+
- cmd/setup/template/site/Dockerfile
|
171
|
+
- cmd/setup/template/site/Gemfile
|
172
|
+
- cmd/setup/template/site/README.md
|
173
|
+
- cmd/setup/template/site/bin/console
|
174
|
+
- cmd/setup/template/site/bin/restart
|
175
|
+
- cmd/setup/template/site/bin/server
|
176
|
+
- cmd/setup/template/site/bin/start
|
177
|
+
- cmd/setup/template/site/bin/stop
|
178
|
+
- cmd/setup/template/site/docker-compose.yml
|
179
|
+
- cmd/setup/template/site/proxy/Dockerfile
|
180
|
+
- cmd/setup/template/site/proxy/etc/Caddyfile
|
181
|
+
- cmd/setup/template/site/proxy/etc/tls_auto
|
182
|
+
- cmd/setup/template/site/proxy/etc/tls_cloudflare
|
183
|
+
- cmd/setup/template/site/proxy/etc/tls_custom
|
184
|
+
- cmd/setup/template/site/proxy/etc/tls_selfsigned
|
185
|
+
- cmd/setup/template/site/site/_layout/default.rb
|
186
|
+
- cmd/setup/template/site/site/about.md
|
187
|
+
- cmd/setup/template/site/site/articles/cage.rb
|
188
|
+
- cmd/setup/template/site/site/articles/index.rb
|
189
|
+
- cmd/setup/template/site/site/assets/css/style.css
|
190
|
+
- cmd/setup/template/site/site/assets/img/syntropy.png
|
191
|
+
- cmd/setup/template/site/site/index.rb
|
192
|
+
- docker-compose.yml
|
169
193
|
- lib/syntropy.rb
|
170
194
|
- lib/syntropy/app.rb
|
171
195
|
- lib/syntropy/connection_pool.rb
|
172
196
|
- lib/syntropy/errors.rb
|
173
197
|
- lib/syntropy/file_watch.rb
|
174
198
|
- lib/syntropy/module.rb
|
199
|
+
- lib/syntropy/request_extensions.rb
|
200
|
+
- lib/syntropy/router.rb
|
175
201
|
- lib/syntropy/rpc_api.rb
|
202
|
+
- lib/syntropy/side_run.rb
|
176
203
|
- lib/syntropy/version.rb
|
177
204
|
- syntropy.gemspec
|
178
205
|
- test/app/_layout/default.rb
|
@@ -184,15 +211,19 @@ files:
|
|
184
211
|
- test/app/api+.rb
|
185
212
|
- test/app/assets/style.css
|
186
213
|
- test/app/bar.rb
|
214
|
+
- test/app/baz.rb
|
187
215
|
- test/app/index.html
|
188
216
|
- test/app/tmp.rb
|
217
|
+
- test/app_custom/_site.rb
|
189
218
|
- test/helper.rb
|
190
219
|
- test/run.rb
|
191
220
|
- test/test_app.rb
|
192
221
|
- test/test_connection_pool.rb
|
193
222
|
- test/test_file_watch.rb
|
194
223
|
- test/test_module.rb
|
224
|
+
- test/test_router.rb
|
195
225
|
- test/test_rpc_api.rb
|
226
|
+
- test/test_side_run.rb
|
196
227
|
- test/test_validation.rb
|
197
228
|
homepage: https://github.com/noteflakes/syntropy
|
198
229
|
licenses:
|