kirei 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/kirei.gemspec +6 -4
- data/lib/boot.rb +2 -3
- data/lib/cli/commands/new_app/execute.rb +3 -2
- data/lib/cli/commands/start.rb +1 -2
- data/lib/kirei/app_base.rb +2 -2
- data/lib/kirei/base_controller.rb +1 -1
- data/lib/kirei/base_model.rb +9 -2
- data/lib/kirei/helpers.rb +70 -0
- data/lib/kirei/logger.rb +7 -5
- data/lib/kirei/version.rb +1 -1
- data/lib/kirei.rb +1 -3
- metadata +8 -20
- data/sorbet/rbi/dsl/active_support/callbacks.rbi +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b67435621f32def7ede1b291b5d0fe529125bda4dd34149afa5b7db6d2193ddd
|
4
|
+
data.tar.gz: fb6c0e91a22bdb8cf726f638c5a250c5245c9a2de4e662f853d2b436a865d2fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5529b60454e2389fb5df0ff5fad1cdc5f3b1c8385396aa3f65d977db9bb6ceccbd9e93de70de7dba4f719681f8332cc30a2dfd087117589c274b7ad5f99926ef
|
7
|
+
data.tar.gz: 61f28174f219f9968e59183d473a4296d0fe659e3104b4ab2debe8e7cef27de077f653279a9897f7fc71af541597b8b90c3cf8ef66c0cbbadd40984f1520d1a4
|
data/kirei.gemspec
CHANGED
@@ -13,10 +13,12 @@ Gem::Specification.new do |spec|
|
|
13
13
|
"oss@dbl.works",
|
14
14
|
]
|
15
15
|
|
16
|
-
spec.summary = "Kirei is a strictly typed Ruby micro/REST-framework for building scaleable and performant
|
16
|
+
spec.summary = "Kirei is a strictly typed Ruby micro/REST-framework for building scaleable and performant microservices." # rubocop:disable Layout/LineLength
|
17
17
|
spec.description = <<~TXT
|
18
|
-
Kirei
|
19
|
-
It
|
18
|
+
Kirei is a strictly typed Ruby micro/REST-framework for building scaleable and performant microservices.
|
19
|
+
It is built from the ground up to be clean and easy to use.
|
20
|
+
Kirei is based on Sequel as an ORM, Sorbet for typing, and Sinatra for routing.
|
21
|
+
It strives to have zero magic and to be as explicit as possible.
|
20
22
|
TXT
|
21
23
|
spec.homepage = "https://github.com/swiknaba/kirei"
|
22
24
|
spec.license = "MIT"
|
@@ -29,6 +31,7 @@ Gem::Specification.new do |spec|
|
|
29
31
|
"kirei.gemspec",
|
30
32
|
".irbrc",
|
31
33
|
"lib/**/*",
|
34
|
+
# do not include RBIs for gems, because users might use different verions
|
32
35
|
"sorbet/rbi/dsl/**/*.rbi",
|
33
36
|
"sorbet/rbi/shims/**/*.rbi",
|
34
37
|
"LICENSE",
|
@@ -41,7 +44,6 @@ Gem::Specification.new do |spec|
|
|
41
44
|
spec.require_paths = ["lib"]
|
42
45
|
|
43
46
|
# Utilities
|
44
|
-
spec.add_dependency "activesupport", "~> 6.0"
|
45
47
|
spec.add_dependency "oj", "~> 3.0"
|
46
48
|
spec.add_dependency "rake", "~> 13.0"
|
47
49
|
spec.add_dependency "sorbet-runtime", "~> 0.5"
|
data/lib/boot.rb
CHANGED
@@ -12,15 +12,14 @@
|
|
12
12
|
require "bundler/setup"
|
13
13
|
|
14
14
|
# Second: load all gems (runtime dependencies only)
|
15
|
+
require "logger"
|
15
16
|
require "sorbet-runtime"
|
16
17
|
require "oj"
|
17
|
-
require "active_support/all"
|
18
18
|
require "puma"
|
19
19
|
require "sinatra"
|
20
20
|
require "sinatra/namespace" # from sinatra-contrib
|
21
21
|
require "pg"
|
22
|
-
require "sequel"
|
23
|
-
# "sequel_pg" should be auto-required by "sequel"
|
22
|
+
require "sequel" # "sequel_pg" is auto-required by "sequel"
|
24
23
|
|
25
24
|
Oj.default_options = {
|
26
25
|
mode: :compat, # required to dump hashes with symbol-keys
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# typed: false
|
2
2
|
|
3
3
|
require "fileutils"
|
4
|
-
require "active_support/all"
|
5
4
|
|
6
5
|
module Cli
|
7
6
|
module Commands
|
@@ -12,7 +11,9 @@ module Cli
|
|
12
11
|
Files::App.call(app_name)
|
13
12
|
Files::Irbrc.call
|
14
13
|
|
15
|
-
|
14
|
+
Kirei::Logger.logger.info(
|
15
|
+
"Kirei app '#{app_name}' scaffolded successfully!",
|
16
|
+
)
|
16
17
|
end
|
17
18
|
end
|
18
19
|
end
|
data/lib/cli/commands/start.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# typed: false
|
2
2
|
|
3
3
|
require "fileutils"
|
4
|
-
require "active_support/all"
|
5
4
|
|
6
5
|
module Cli
|
7
6
|
module Commands
|
@@ -13,7 +12,7 @@ module Cli
|
|
13
12
|
app_name = app_name.gsub(/[-\s]/, "_").classify
|
14
13
|
NewApp::Execute.call(app_name: app_name)
|
15
14
|
else
|
16
|
-
|
15
|
+
Kirei::Logger.logger.info("Unknown command")
|
17
16
|
end
|
18
17
|
end
|
19
18
|
end
|
data/lib/kirei/app_base.rb
CHANGED
@@ -29,13 +29,13 @@ module Kirei
|
|
29
29
|
end
|
30
30
|
|
31
31
|
sig { returns(String) }
|
32
|
-
def
|
32
|
+
def environment
|
33
33
|
ENV.fetch("RACK_ENV", "development")
|
34
34
|
end
|
35
35
|
|
36
36
|
sig { returns(String) }
|
37
37
|
def default_db_name
|
38
|
-
@default_db_name ||= T.let("#{config.app_name}_#{
|
38
|
+
@default_db_name ||= T.let("#{config.app_name}_#{environment}".freeze, T.nilable(String))
|
39
39
|
end
|
40
40
|
|
41
41
|
sig { returns(String) }
|
data/lib/kirei/base_model.rb
CHANGED
@@ -62,9 +62,16 @@ module Kirei
|
|
62
62
|
|
63
63
|
include BaseClassInterface
|
64
64
|
|
65
|
+
# defaults to a pluralized, underscored version of the class name
|
65
66
|
sig { override.returns(String) }
|
66
67
|
def table_name
|
67
|
-
T.
|
68
|
+
@table_name ||= T.let(
|
69
|
+
begin
|
70
|
+
table_name_ = Kirei::Helpers.underscore(T.must(name.split("::").last))
|
71
|
+
"#{table_name_}s"
|
72
|
+
end,
|
73
|
+
T.nilable(String),
|
74
|
+
)
|
68
75
|
end
|
69
76
|
|
70
77
|
sig { override.returns(Sequel::Dataset) }
|
@@ -106,7 +113,7 @@ module Kirei
|
|
106
113
|
|
107
114
|
query.map do |row|
|
108
115
|
row = T.cast(row, T::Hash[Symbol, T.untyped])
|
109
|
-
row.
|
116
|
+
row.transform_keys!(&:to_s) # sequel returns symbolized keys
|
110
117
|
from_hash(row, strict_loading)
|
111
118
|
end
|
112
119
|
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Kirei
|
5
|
+
module Helpers
|
6
|
+
class << self
|
7
|
+
extend T::Sig
|
8
|
+
|
9
|
+
# Simplified version from Rails' ActiveSupport::Inflector#underscore
|
10
|
+
sig { params(string: String).returns(String) }
|
11
|
+
def underscore(string)
|
12
|
+
string.gsub!(/([A-Z])(?=[A-Z][a-z])|([a-z\d])(?=[A-Z])/) do
|
13
|
+
T.must((::Regexp.last_match(1) || ::Regexp.last_match(2))) << "_"
|
14
|
+
end
|
15
|
+
string.tr!("-", "_")
|
16
|
+
string.downcase!
|
17
|
+
string
|
18
|
+
end
|
19
|
+
|
20
|
+
# Simplified version from Rails' ActiveSupport
|
21
|
+
sig { params(string: T.any(String, Symbol)).returns(T::Boolean) }
|
22
|
+
def blank?(string)
|
23
|
+
string.nil? || string.to_s.empty?
|
24
|
+
end
|
25
|
+
|
26
|
+
# Simplified version from Rails' ActiveSupport
|
27
|
+
sig do
|
28
|
+
params(
|
29
|
+
object: T.untyped, # could be anything due to recursive calls
|
30
|
+
block: Proc,
|
31
|
+
).returns(T.untyped) # could be anything due to recursive calls
|
32
|
+
end
|
33
|
+
def deep_transform_keys(object, &block)
|
34
|
+
case object
|
35
|
+
when Hash
|
36
|
+
object.each_with_object({}) do |(key, value), result|
|
37
|
+
result[yield(key)] = deep_transform_keys(value, &block)
|
38
|
+
end
|
39
|
+
when Array
|
40
|
+
object.map { |e| deep_transform_keys(e, &block) }
|
41
|
+
else
|
42
|
+
object
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
sig do
|
47
|
+
params(
|
48
|
+
object: T.untyped, # could be anything due to recursive calls
|
49
|
+
block: Proc,
|
50
|
+
).returns(T.untyped) # could be anything due to recursive calls
|
51
|
+
end
|
52
|
+
def deep_transform_keys!(object, &block)
|
53
|
+
case object
|
54
|
+
when Hash
|
55
|
+
# using `each_key` results in a `RuntimeError: can't add a new key into hash during iteration`
|
56
|
+
# which is, because the receiver here does not necessarily have a `Hash` type
|
57
|
+
object.keys.each do |key| # rubocop:disable Style/HashEachMethods
|
58
|
+
value = object.delete(key)
|
59
|
+
object[yield(key)] = deep_transform_keys!(value, &block)
|
60
|
+
end
|
61
|
+
object
|
62
|
+
when Array
|
63
|
+
object.map! { |e| deep_transform_keys!(e, &block) }
|
64
|
+
else
|
65
|
+
object
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/lib/kirei/logger.rb
CHANGED
@@ -98,7 +98,7 @@ module Kirei
|
|
98
98
|
label = log_data.fetch(:label)
|
99
99
|
meta = T.let(log_data.fetch(:meta), T::Hash[Symbol, T.untyped])
|
100
100
|
meta[:"service.version"] ||= Kirei::AppBase.version
|
101
|
-
meta[:timestamp] ||= Time.
|
101
|
+
meta[:timestamp] ||= Time.now.utc.iso8601
|
102
102
|
meta[:level] ||= level.to_s.upcase
|
103
103
|
meta[:label] ||= label
|
104
104
|
|
@@ -137,13 +137,13 @@ module Kirei
|
|
137
137
|
end
|
138
138
|
def self.flatten_hash_and_mask_sensitive_values(hash, prefix = :'')
|
139
139
|
result = T.let({}, T::Hash[Symbol, T.untyped])
|
140
|
-
hash.
|
140
|
+
Kirei::Helpers.deep_transform_keys!(hash) { _1.to_sym rescue _1 } # rubocop:disable Style/RescueModifier
|
141
141
|
|
142
142
|
hash.each do |key, value|
|
143
|
-
new_prefix =
|
143
|
+
new_prefix = Kirei::Helpers.blank?(prefix) ? key : :"#{prefix}.#{key}"
|
144
144
|
|
145
145
|
case value
|
146
|
-
when Hash then result.merge!(flatten_hash_and_mask_sensitive_values(value.
|
146
|
+
when Hash then result.merge!(flatten_hash_and_mask_sensitive_values(value.transform_keys(&:to_sym), new_prefix))
|
147
147
|
when Array
|
148
148
|
value.each_with_index do |element, index|
|
149
149
|
if element.is_a?(Hash) || element.is_a?(Array)
|
@@ -158,7 +158,9 @@ module Kirei
|
|
158
158
|
if value.respond_to?(:serialize)
|
159
159
|
serialized_value = value.serialize
|
160
160
|
if serialized_value.is_a?(Hash)
|
161
|
-
result.merge!(
|
161
|
+
result.merge!(
|
162
|
+
flatten_hash_and_mask_sensitive_values(serialized_value.transform_keys(&:to_sym), new_prefix),
|
163
|
+
)
|
162
164
|
else
|
163
165
|
result[new_prefix] = serialized_value&.to_s
|
164
166
|
end
|
data/lib/kirei/version.rb
CHANGED
data/lib/kirei.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# typed: strict
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
puts "Booting Kirei..." # rubocop:disable all
|
5
|
-
|
6
4
|
require "boot"
|
7
5
|
|
8
6
|
module Kirei
|
@@ -33,4 +31,4 @@ end
|
|
33
31
|
|
34
32
|
Kirei.configure(&:itself)
|
35
33
|
|
36
|
-
|
34
|
+
Kirei::Logger.logger.info("Kirei (#{Kirei::VERSION}) booted successfully!")
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kirei
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ludwig Reinmiedl
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-12-
|
11
|
+
date: 2023-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: activesupport
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '6.0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '6.0'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: oj
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -165,8 +151,10 @@ dependencies:
|
|
165
151
|
- !ruby/object:Gem::Version
|
166
152
|
version: '1.0'
|
167
153
|
description: |
|
168
|
-
Kirei
|
169
|
-
It
|
154
|
+
Kirei is a strictly typed Ruby micro/REST-framework for building scaleable and performant microservices.
|
155
|
+
It is built from the ground up to be clean and easy to use.
|
156
|
+
Kirei is based on Sequel as an ORM, Sorbet for typing, and Sinatra for routing.
|
157
|
+
It strives to have zero magic and to be as explicit as possible.
|
170
158
|
email:
|
171
159
|
- lud@reinmiedl.com
|
172
160
|
- oss@dbl.works
|
@@ -193,9 +181,9 @@ files:
|
|
193
181
|
- lib/kirei/base_controller.rb
|
194
182
|
- lib/kirei/base_model.rb
|
195
183
|
- lib/kirei/config.rb
|
184
|
+
- lib/kirei/helpers.rb
|
196
185
|
- lib/kirei/logger.rb
|
197
186
|
- lib/kirei/version.rb
|
198
|
-
- sorbet/rbi/dsl/active_support/callbacks.rbi
|
199
187
|
- sorbet/rbi/shims/base_model.rbi
|
200
188
|
homepage: https://github.com/swiknaba/kirei
|
201
189
|
licenses:
|
@@ -222,5 +210,5 @@ rubygems_version: 3.5.3
|
|
222
210
|
signing_key:
|
223
211
|
specification_version: 4
|
224
212
|
summary: Kirei is a strictly typed Ruby micro/REST-framework for building scaleable
|
225
|
-
and performant
|
213
|
+
and performant microservices.
|
226
214
|
test_files: []
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# typed: true
|
2
|
-
|
3
|
-
# DO NOT EDIT MANUALLY
|
4
|
-
# This is an autogenerated file for dynamic methods in `ActiveSupport::Callbacks`.
|
5
|
-
# Please instead update this file by running `bin/tapioca dsl ActiveSupport::Callbacks`.
|
6
|
-
|
7
|
-
module ActiveSupport::Callbacks
|
8
|
-
include GeneratedInstanceMethods
|
9
|
-
|
10
|
-
mixes_in_class_methods GeneratedClassMethods
|
11
|
-
|
12
|
-
module GeneratedClassMethods
|
13
|
-
def __callbacks; end
|
14
|
-
def __callbacks=(value); end
|
15
|
-
def __callbacks?; end
|
16
|
-
end
|
17
|
-
|
18
|
-
module GeneratedInstanceMethods
|
19
|
-
def __callbacks; end
|
20
|
-
def __callbacks?; end
|
21
|
-
end
|
22
|
-
end
|