kirei 0.8.0 → 0.8.2
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/README.md +1 -1
- data/kirei.gemspec +0 -1
- data/lib/cli/commands/new_app/files/app.rb +5 -5
- data/lib/cli/commands/new_app/files/db_rake.rb +4 -4
- data/lib/kirei/controller.rb +3 -26
- data/lib/kirei/routing/request.rb +40 -0
- data/lib/kirei/version.rb +1 -1
- metadata +2 -2
- data/CHANGELOG.md +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e16807cffd59ce38ba7cb3e8a0474e26fff5c4d6598ee63ac745382d0c4d30f
|
4
|
+
data.tar.gz: 180c00ecc9ad0668cffcf3f1448779acbe2e5fb35c8f7632159358d8637734c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 780e826760bd7ff48e1decf31446c7f9d5b3fc9504c5b3674af04b746cda67f1bba61fe27658fdec5993e1c2c0bba3030a45557f32d8cc0465342a85da1fd6db
|
7
|
+
data.tar.gz: 7e32df47ece711cc97471801bad3085e2f1008abca7f0be1af8acf402c8569199018284bbeb6ece672a6745cd06957f30e29802218372ef1816c64e431813b36
|
data/README.md
CHANGED
@@ -21,7 +21,7 @@ TL;DR:
|
|
21
21
|
|
22
22
|
This gem follows SemVer, however only after a stable release 1.0.0 is made.
|
23
23
|
|
24
|
-
A changelog is maintained
|
24
|
+
A changelog is maintained via the [GitHub Releases page](https://github.com/swiknaba/kirei/releases).
|
25
25
|
|
26
26
|
## Installation
|
27
27
|
|
data/kirei.gemspec
CHANGED
@@ -29,8 +29,8 @@ module Cli
|
|
29
29
|
Dir[File.join(__dir__, "config/initializers", "*.rb")].each { require(_1) }
|
30
30
|
|
31
31
|
# Fourth: load all application code
|
32
|
-
|
33
|
-
|
32
|
+
APP_LOADER = Zeitwerk::Loader.new
|
33
|
+
APP_LOADER.tag = File.basename(__FILE__, ".rb")
|
34
34
|
[
|
35
35
|
"/app",
|
36
36
|
"/app/models",
|
@@ -38,9 +38,9 @@ module Cli
|
|
38
38
|
].each do |root_namespace|
|
39
39
|
# a root namespace skips the auto-infered module for this folder
|
40
40
|
# so we don't have to write e.g. `Models::` or `Services::`
|
41
|
-
|
41
|
+
APP_LOADER.push_dir("\#{File.dirname(__FILE__)}\#{root_namespace}")
|
42
42
|
end
|
43
|
-
|
43
|
+
APP_LOADER.setup
|
44
44
|
|
45
45
|
# Fifth: load configs
|
46
46
|
Dir[File.join(__dir__, "config", "**", "*.rb")].each do |cnf|
|
@@ -52,7 +52,7 @@ module Cli
|
|
52
52
|
config.app_name = "#{snake_case_app_name}"
|
53
53
|
end
|
54
54
|
|
55
|
-
|
55
|
+
APP_LOADER.eager_load
|
56
56
|
RUBY
|
57
57
|
end
|
58
58
|
end
|
@@ -173,24 +173,23 @@ module Cli
|
|
173
173
|
next if !model_file_name.nil? && model_file == model_file_name
|
174
174
|
|
175
175
|
model_path = File.expand_path(model_file, app_root_dir)
|
176
|
-
loader = Zeitwerk::Registry.loaders.find { |l| l.tag == "app" }
|
177
176
|
|
178
177
|
full_path = File.expand_path(model_file, app_root_dir)
|
179
|
-
klass_constant_name =
|
178
|
+
klass_constant_name = APP_LOADER.inflector.camelize(File.basename(model_file, ".rb"), full_path)
|
180
179
|
|
181
180
|
#
|
182
181
|
# root namespaces in Zeitwerk are flattend, e.g. if "app/models" is a root namespace
|
183
182
|
# then a file "app/models/airport.rb" is loaded as "::Airport".
|
184
183
|
# if it weren't a root namespace, it would be "::Models::Airport".
|
185
184
|
#
|
186
|
-
root_dir_namespaces =
|
185
|
+
root_dir_namespaces = APP_LOADER.dirs.filter_map { |dir| dir == app_dir ? nil : Pathname.new(dir).relative_path_from(Pathname.new(app_dir)).to_s }
|
187
186
|
relative_path = Pathname.new(full_path).relative_path_from(Pathname.new(app_dir)).to_s
|
188
187
|
root_dir_of_model = root_dir_namespaces.find { |root_dir| relative_path.start_with?(root_dir) }
|
189
188
|
relative_path.sub!("\#{root_dir_of_model}/", "") unless root_dir_of_model.nil? || root_dir_of_model.empty?
|
190
189
|
|
191
190
|
namespace_parts = relative_path.split("/")
|
192
191
|
namespace_parts.pop
|
193
|
-
namespace_parts.map! { |part|
|
192
|
+
namespace_parts.map! { |part| APP_LOADER.inflector.camelize(part, full_path) }
|
194
193
|
|
195
194
|
constant_name = "\#{namespace_parts.join('::')}::\#{klass_constant_name}"
|
196
195
|
|
@@ -231,6 +230,7 @@ module Cli
|
|
231
230
|
name, info = column
|
232
231
|
type = "\#{info[:db_type]}(\#{info[:max_length]})" if info[:max_length]
|
233
232
|
type ||= info[:db_type]
|
233
|
+
type = "\#{type}, " if type.size >= 20 \# e.g. "timestamp without time zone" exceeds 20 characters
|
234
234
|
null = info[:allow_null] ? 'null' : 'not null'
|
235
235
|
primary_key = info[:primary_key] ? ', primary key' : ''
|
236
236
|
lines << "# \#{name.to_s.ljust(20)}:\#{type.to_s.ljust(20)}\#{null}\#{primary_key}"
|
data/lib/kirei/controller.rb
CHANGED
@@ -41,32 +41,9 @@ module Kirei
|
|
41
41
|
@after_hooks.add(block) if block
|
42
42
|
end
|
43
43
|
|
44
|
-
sig { returns(
|
45
|
-
def
|
46
|
-
env.
|
47
|
-
end
|
48
|
-
|
49
|
-
sig { returns(String) }
|
50
|
-
def req_domain
|
51
|
-
T.must(req_host.split(":").first).split(".").last(2).join(".")
|
52
|
-
end
|
53
|
-
|
54
|
-
sig { returns(T.nilable(String)) }
|
55
|
-
def req_subdomain
|
56
|
-
parts = T.must(req_host.split(":").first).split(".")
|
57
|
-
return if parts.size <= 2
|
58
|
-
|
59
|
-
T.must(parts[0..-3]).join(".")
|
60
|
-
end
|
61
|
-
|
62
|
-
sig { returns(Integer) }
|
63
|
-
def req_port
|
64
|
-
env.fetch("SERVER_PORT")&.to_i
|
65
|
-
end
|
66
|
-
|
67
|
-
sig { returns(T::Boolean) }
|
68
|
-
def req_ssl?
|
69
|
-
env.fetch("HTTPS", env.fetch("rack.url_scheme", "http")) == "https"
|
44
|
+
sig { returns(Routing::Request) }
|
45
|
+
def request
|
46
|
+
@request ||= T.let(Routing::Request.new(env: env), T.nilable(Routing::Request))
|
70
47
|
end
|
71
48
|
|
72
49
|
sig { returns(T::Hash[String, T.untyped]) }
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Kirei
|
5
|
+
module Routing
|
6
|
+
class Request < T::Struct
|
7
|
+
extend T::Sig
|
8
|
+
|
9
|
+
const :env, T::Hash[String, T.untyped]
|
10
|
+
|
11
|
+
sig { returns(String) }
|
12
|
+
def host
|
13
|
+
env.fetch("HTTP_HOST")
|
14
|
+
end
|
15
|
+
|
16
|
+
sig { returns(String) }
|
17
|
+
def domain
|
18
|
+
T.must(host.split(":").first).split(".").last(2).join(".")
|
19
|
+
end
|
20
|
+
|
21
|
+
sig { returns(T.nilable(String)) }
|
22
|
+
def subdomain
|
23
|
+
parts = T.must(host.split(":").first).split(".")
|
24
|
+
return if parts.size <= 2
|
25
|
+
|
26
|
+
T.must(parts[0..-3]).join(".")
|
27
|
+
end
|
28
|
+
|
29
|
+
sig { returns(Integer) }
|
30
|
+
def port
|
31
|
+
env.fetch("SERVER_PORT")&.to_i
|
32
|
+
end
|
33
|
+
|
34
|
+
sig { returns(T::Boolean) }
|
35
|
+
def ssl?
|
36
|
+
env.fetch("HTTPS", env.fetch("rack.url_scheme", "http")) == "https"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/kirei/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kirei
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ludwig Reinmiedl
|
@@ -163,7 +163,6 @@ extensions: []
|
|
163
163
|
extra_rdoc_files: []
|
164
164
|
files:
|
165
165
|
- ".irbrc"
|
166
|
-
- CHANGELOG.md
|
167
166
|
- README.md
|
168
167
|
- bin/kirei
|
169
168
|
- kirei.gemspec
|
@@ -198,6 +197,7 @@ files:
|
|
198
197
|
- lib/kirei/routing/nilable_hooks_type.rb
|
199
198
|
- lib/kirei/routing/rack_env_type.rb
|
200
199
|
- lib/kirei/routing/rack_response_type.rb
|
200
|
+
- lib/kirei/routing/request.rb
|
201
201
|
- lib/kirei/routing/route.rb
|
202
202
|
- lib/kirei/routing/router.rb
|
203
203
|
- lib/kirei/routing/verb.rb
|
data/CHANGELOG.md
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
# Changelog
|
2
|
-
|
3
|
-
## [Unreleased]
|
4
|
-
|
5
|
-
## [0.1.0] - 2023-09-02
|
6
|
-
|
7
|
-
- Initial release
|
8
|
-
- added base model
|
9
|
-
- added database connection
|
10
|
-
- WIP: basic cli to scaffold a new project
|
11
|
-
|
12
|
-
## [0.2.0] - 2023-09-02
|
13
|
-
|
14
|
-
- added routing
|
15
|
-
- added base controller
|
16
|
-
- added database tasks (create, drop, migrate, rollback, generate migration)
|