snails 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/example/app.rb +3 -1
- data/example/app2.rb +19 -0
- data/example/config.ru +37 -1
- data/lib/snails/loader.rb +57 -0
- data/snails.gemspec +2 -1
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ace977fc33f80028eb415424addddbb1f6e9dcda49b35e4a852aaa7daa032524
|
4
|
+
data.tar.gz: a371db3ebc879c315e5b6b9fca7de42526963f053a2d128fb485acf07cf02214
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a24db7e0c46fe2bdfaa2ca0b19132116b8a39594f5bc59cd4bf14b4c5d433bb783fb1fa1702c82b36c0b94397d949dfecddc18727dba05629137d3c09db3a08
|
7
|
+
data.tar.gz: fac56d5ef6dac6db26678867090b88af56addbb792de515f835944698c079cab854110ed4e8f77f9b1ea690b6c515e5f670b032979ece8bd88b975c04924cc75
|
data/example/app.rb
CHANGED
@@ -4,7 +4,9 @@ require 'snails/mailer'
|
|
4
4
|
|
5
5
|
class MyApp < Snails::App
|
6
6
|
|
7
|
-
set :session_secret,
|
7
|
+
set :session_secret, SESSION_SECRET
|
8
|
+
set :session_domain, "app.localhost"
|
9
|
+
|
8
10
|
register Snails::Assets
|
9
11
|
register Snails::Sessions
|
10
12
|
# register Snails::Database
|
data/example/app2.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'snails'
|
3
|
+
require 'snails/mailer'
|
4
|
+
|
5
|
+
class MyOtherApp < Snails::App
|
6
|
+
|
7
|
+
set :session_secret, SESSION_SECRET
|
8
|
+
set :session_domain, "app.localhost"
|
9
|
+
|
10
|
+
register Snails::Assets
|
11
|
+
register Snails::Sessions
|
12
|
+
# register Snails::Database
|
13
|
+
|
14
|
+
get '/' do
|
15
|
+
number = session[:number] || 0
|
16
|
+
session[:number] = number.to_i + 1
|
17
|
+
"<h1>Hello world!</h1><p>This is your visit number #{number}. Come again!</p>"
|
18
|
+
end
|
19
|
+
end
|
data/example/config.ru
CHANGED
@@ -1,2 +1,38 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
SESSION_SECRET = SecureRandom.hex(32) # generates a new session cookie on each login
|
3
|
+
MAIN_DOMAIN = 'app.localhost'
|
4
|
+
|
1
5
|
require './app'
|
2
|
-
|
6
|
+
require './app2'
|
7
|
+
|
8
|
+
class SubdomainDispatcher
|
9
|
+
def initialize(mappings)
|
10
|
+
@mappings = mappings
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(env)
|
14
|
+
subdomain = env['HTTP_HOST'].split('.').first
|
15
|
+
|
16
|
+
if subdomain.start_with?(MAIN_DOMAIN) # no domain, so see if first part of url matches one of the subdomains
|
17
|
+
parts = env['PATH_INFO'][1..].split('/')
|
18
|
+
if @mappings.key?(parts.first) # found match!
|
19
|
+
subdomain = parts.shift # get subdomain and remove it from path
|
20
|
+
env['PATH_INFO'] = parts.join('/')
|
21
|
+
else
|
22
|
+
subdomain = '' # map to root app, if present
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
if app = @mappings[subdomain]
|
27
|
+
app.call(env)
|
28
|
+
else
|
29
|
+
[404, { 'Content-Type' => 'text/html' }, "Not found"]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
use Bugsnag::Rack if defined?(Bugsnag)
|
35
|
+
run SubdomainDispatcher.new({
|
36
|
+
'one' => MyApp,
|
37
|
+
'two' => MyOtherApp
|
38
|
+
})
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require_relative '../snails'
|
2
|
+
require 'zeitwerk'
|
3
|
+
|
4
|
+
module Snails
|
5
|
+
|
6
|
+
def self.loader
|
7
|
+
@loader ||= Loader.new
|
8
|
+
end
|
9
|
+
|
10
|
+
class Loader
|
11
|
+
|
12
|
+
attr_reader :loader
|
13
|
+
attr_accessor :load_paths, :preload_paths, :ignore_paths, :no_eager_load_paths
|
14
|
+
|
15
|
+
def initialize(loader: nil, load_paths: nil, preload_paths: nil)
|
16
|
+
@loader = loader || Zeitwerk::Loader.new
|
17
|
+
@load_paths = load_paths || DEFAULT_LOAD_PATHS
|
18
|
+
@preload_paths = preload_paths || DEFAULT_PRELOAD_PATHS
|
19
|
+
@ignore_paths = []
|
20
|
+
@no_eager_load_paths = []
|
21
|
+
end
|
22
|
+
|
23
|
+
def load!(opts = {})
|
24
|
+
# $LOAD_PATH.unshift(File.join(Snails.root, 'lib'))
|
25
|
+
|
26
|
+
load_paths.each do |path|
|
27
|
+
loader.push_dir(Snails.root.join(path))
|
28
|
+
end
|
29
|
+
|
30
|
+
ignore_paths.each do |path|
|
31
|
+
loader.ignore(Snails.root.join(path))
|
32
|
+
end
|
33
|
+
|
34
|
+
no_eager_load_paths.each do |path|
|
35
|
+
loader.do_not_eager_load(Snails.root.join(path))
|
36
|
+
end
|
37
|
+
|
38
|
+
loader.enable_reloading if opts[:enable_reload]
|
39
|
+
loader.setup
|
40
|
+
|
41
|
+
preload_paths.each do |path|
|
42
|
+
Dir.glob(Snails.root.join(path, '*.rb')).each { |f| require f }
|
43
|
+
end
|
44
|
+
|
45
|
+
loader.eager_load if opts[:eager_load]
|
46
|
+
end
|
47
|
+
|
48
|
+
def reload!
|
49
|
+
loader.reload
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
DEFAULT_LOAD_PATHS = ['lib']
|
55
|
+
DEFAULT_PRELOAD_PATHS = ['config/initializers']
|
56
|
+
end
|
57
|
+
end
|
data/snails.gemspec
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "snails"
|
6
|
-
s.version = '0.
|
6
|
+
s.version = '0.8.0'
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
8
|
s.authors = ['Tomás Pollak']
|
9
9
|
s.email = ['tomas@forkhq.com']
|
@@ -17,6 +17,7 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.add_development_dependency "fuubar", '>= 2.3.2'
|
18
18
|
|
19
19
|
s.add_runtime_dependency "i18n", ">= 1.0.1"
|
20
|
+
s.add_runtime_dependency "zeitwerk", "~> 2.6"
|
20
21
|
s.add_runtime_dependency "sinatra-contrib", ">= 2.0.3"
|
21
22
|
s.add_runtime_dependency "activesupport", "> 6.0.0"
|
22
23
|
# s.add_runtime_dependency "activerecord", "< 6.0"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: snails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomás Pollak
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -72,6 +72,20 @@ dependencies:
|
|
72
72
|
- - ">="
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: 1.0.1
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: zeitwerk
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '2.6'
|
82
|
+
type: :runtime
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '2.6'
|
75
89
|
- !ruby/object:Gem::Dependency
|
76
90
|
name: sinatra-contrib
|
77
91
|
requirement: !ruby/object:Gem::Requirement
|
@@ -141,9 +155,11 @@ files:
|
|
141
155
|
- example/Gemfile
|
142
156
|
- example/Rakefile
|
143
157
|
- example/app.rb
|
158
|
+
- example/app2.rb
|
144
159
|
- example/config.ru
|
145
160
|
- lib/snails.rb
|
146
161
|
- lib/snails/app.rb
|
162
|
+
- lib/snails/loader.rb
|
147
163
|
- lib/snails/mailer.rb
|
148
164
|
- lib/snails/markdown.rb
|
149
165
|
- lib/snails/rspec.rb
|