rsodx 0.1.0 → 0.1.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/lib/rsodx/cli/commands/scaffold.rb +1 -1
- data/lib/rsodx/configuration.rb +13 -2
- data/lib/rsodx/delegate.rb +12 -2
- data/lib/rsodx/environment.rb +7 -1
- data/lib/rsodx/logger.rb +51 -0
- data/lib/rsodx/logger_adapter.rb +32 -0
- data/lib/rsodx/service.rb +4 -10
- data/lib/rsodx/version.rb +1 -1
- data/lib/rsodx.rb +3 -0
- metadata +18 -3
- data/LICENSE.txt +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3cf0b729bdc4f7c8028726664039d5370f7a859031cd128edd221d15f479e743
|
4
|
+
data.tar.gz: cd2b5dc997bef4c10dc51a0aa7c3e56413f1f55b38be7136240d35b02c66ce5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7905ace36dadb5da1e100d7257f4dba96697eedb1306d229655a4d12e42db9a20d7da40eeb0eec270d1c071c507b26a46fa8d615212e270f610711e7693502e0
|
7
|
+
data.tar.gz: 50291c0daaa94f34a7466c2bb15e2528a0aabf8d6be6be272e0953e2e34463670272bd010ef6aea2b38c82a81294e6c1f04b67317240b57fc2361f911ad3b188
|
@@ -46,7 +46,7 @@ module Rsodx::Cli::Commands
|
|
46
46
|
write("config/environment.rb", ENV_LOADER)
|
47
47
|
write("Rakefile", RAKEFILE)
|
48
48
|
write("app/controllers/app_controller.rb", APP_CONTROLLER)
|
49
|
-
write("app/services/
|
49
|
+
write("app/services/app_service.rb", APP_SERVICE)
|
50
50
|
write("app/serializers/app_serializer.rb", APP_SERIALIZER)
|
51
51
|
write("app/presenters/app_presenter.rb", APP_PRESENTER)
|
52
52
|
write("app/app.rb", APP)
|
data/lib/rsodx/configuration.rb
CHANGED
@@ -1,9 +1,20 @@
|
|
1
1
|
module Rsodx
|
2
2
|
class Configuration
|
3
|
-
attr_accessor :database_url
|
3
|
+
attr_accessor :database_url, :logger, :appname
|
4
4
|
|
5
5
|
def initialize
|
6
|
-
@
|
6
|
+
@appname = Rsodx::RSODX_NAME
|
7
|
+
init_database
|
8
|
+
init_logger
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def init_database
|
14
|
+
@database_url = ENV['DATABASE_URL']
|
15
|
+
end
|
16
|
+
def init_logger
|
17
|
+
@logger ||= Rsodx::Logger.new(Rsodx::LoggerAdapter.new($stdout))
|
7
18
|
end
|
8
19
|
end
|
9
20
|
end
|
data/lib/rsodx/delegate.rb
CHANGED
@@ -2,12 +2,22 @@ require "forwardable"
|
|
2
2
|
|
3
3
|
module Rsodx
|
4
4
|
module Delegate
|
5
|
-
def delegate(*methods, to:)
|
5
|
+
def delegate(*methods, to:, prefix: nil)
|
6
6
|
raise ArgumentError, "Missing target for delegation (to:)" unless to
|
7
7
|
|
8
8
|
mod = Module.new do
|
9
9
|
extend Forwardable
|
10
|
-
|
10
|
+
|
11
|
+
methods.each do |method_name|
|
12
|
+
delegated_name = if prefix
|
13
|
+
prefix_str = prefix == true ? to.to_s : prefix.to_s
|
14
|
+
"#{prefix_str}_#{method_name}"
|
15
|
+
else
|
16
|
+
method_name
|
17
|
+
end
|
18
|
+
|
19
|
+
def_delegator to, method_name, delegated_name
|
20
|
+
end
|
11
21
|
end
|
12
22
|
|
13
23
|
include mod
|
data/lib/rsodx/environment.rb
CHANGED
@@ -2,11 +2,17 @@ module Rsodx
|
|
2
2
|
module Environment
|
3
3
|
def self.load_dotenv(env = nil)
|
4
4
|
require "dotenv"
|
5
|
-
|
5
|
+
Rsodx.instance_variable_set(:@env, env.to_s.freeze) unless Rsodx.instance_variable_defined?(:@env)
|
6
|
+
|
7
|
+
Dotenv.overload(".env.#{env}") if env
|
6
8
|
end
|
7
9
|
|
8
10
|
def self.load_initializers(app_root)
|
9
11
|
Dir[File.join(app_root, "config", "initializers", "*.rb")].sort.each { |file| require file }
|
10
12
|
end
|
13
|
+
|
14
|
+
def self.env
|
15
|
+
@env || "development"
|
16
|
+
end
|
11
17
|
end
|
12
18
|
end
|
data/lib/rsodx/logger.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'time'
|
3
|
+
require 'syslog/logger'
|
4
|
+
|
5
|
+
module Rsodx
|
6
|
+
class Logger
|
7
|
+
attr_accessor :adapter, :options
|
8
|
+
|
9
|
+
LEVELS = %i[info debug warn error fatal].freeze
|
10
|
+
OPTIONS = { with_backtrace: false }.freeze
|
11
|
+
LogEntry = Struct.new(:timestamp, :appname, :level, :code, :message, :context, :backtrace)
|
12
|
+
|
13
|
+
def initialize(adapter, options = {})
|
14
|
+
raise ArgumentError, 'Invalid LoggerAdapter' unless adapter.is_a?(LoggerAdapter)
|
15
|
+
@adapter = adapter
|
16
|
+
@options = OPTIONS.merge(options).slice(*OPTIONS.keys)
|
17
|
+
end
|
18
|
+
|
19
|
+
def log(level = :info, code:, message:, context: {}, backtrace: nil)
|
20
|
+
raise ArgumentError, "Invalid log level: #{level}" unless LEVELS.include?(level)
|
21
|
+
|
22
|
+
entry = LogEntry.new(
|
23
|
+
timestamp: Time.now.utc.iso8601,
|
24
|
+
appname: appname,
|
25
|
+
level: level,
|
26
|
+
code: code,
|
27
|
+
message: message,
|
28
|
+
context: context,
|
29
|
+
backtrace: include_backtrace?(level) ? (backtrace || caller).take(10) : nil
|
30
|
+
)
|
31
|
+
|
32
|
+
adapter.puts(entry)
|
33
|
+
end
|
34
|
+
|
35
|
+
LEVELS.each do |level|
|
36
|
+
define_method(level) do |code, message, context = {}|
|
37
|
+
log(level, code: code, message: message, context: context)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def include_backtrace?(level)
|
44
|
+
options[:with_backtrace] || level == :debug
|
45
|
+
end
|
46
|
+
|
47
|
+
def appname
|
48
|
+
Rsodx.config.appname
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Rsodx
|
2
|
+
class LoggerAdapter
|
3
|
+
def initialize(target)
|
4
|
+
@target = target
|
5
|
+
end
|
6
|
+
|
7
|
+
def puts(log)
|
8
|
+
case @target
|
9
|
+
when IO
|
10
|
+
@target.puts(log_format(log).to_json)
|
11
|
+
when ::Logger
|
12
|
+
@target.send(log.level, log_format(log).to_json)
|
13
|
+
when Syslog::Logger
|
14
|
+
@target.send(log.level, "[#{log.appname}] [#{log.code}] #{log.message} #{log.context}")
|
15
|
+
else
|
16
|
+
raise "Unsupported log target: #{@target.class}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def log_format(log)
|
21
|
+
{
|
22
|
+
app: log.appname,
|
23
|
+
timestamp: log.timestamp,
|
24
|
+
level: log.level,
|
25
|
+
code: log.code,
|
26
|
+
message: log.message,
|
27
|
+
context: (log.context.empty? ? nil : log.context),
|
28
|
+
backtrace: log.backtrace
|
29
|
+
}.compact
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/rsodx/service.rb
CHANGED
@@ -6,6 +6,7 @@ module Rsodx
|
|
6
6
|
extend Delegate
|
7
7
|
|
8
8
|
delegate :params, :object, to: :context
|
9
|
+
delegate :log, :info, :debug, :warn, :fatal, :error, to: :logger, prefix: :log
|
9
10
|
|
10
11
|
class << self
|
11
12
|
attr_accessor :contract_class
|
@@ -25,18 +26,11 @@ module Rsodx
|
|
25
26
|
def halt(code, message)
|
26
27
|
log_error(code, message)
|
27
28
|
context.fail!(error_code: code, error: message)
|
29
|
+
Rsodx.config.logger&.error(code, message, context)
|
28
30
|
end
|
29
31
|
|
30
|
-
|
31
|
-
|
32
|
-
def log_error(code, message)
|
33
|
-
puts JSON.pretty_generate({
|
34
|
-
level: "error",
|
35
|
-
code: code,
|
36
|
-
message: message,
|
37
|
-
context: context.to_h,
|
38
|
-
backtrace: caller
|
39
|
-
})
|
32
|
+
def logger
|
33
|
+
Rsodx.config.logger
|
40
34
|
end
|
41
35
|
end
|
42
36
|
end
|
data/lib/rsodx/version.rb
CHANGED
data/lib/rsodx.rb
CHANGED
@@ -14,6 +14,8 @@ Dir.glob("#{base}/rsodx/**/*.rb").sort.each do |file|
|
|
14
14
|
end
|
15
15
|
|
16
16
|
module Rsodx
|
17
|
+
RSODX_NAME = 'Rsodx'.freeze
|
18
|
+
|
17
19
|
class << self
|
18
20
|
attr_accessor :config
|
19
21
|
|
@@ -39,6 +41,7 @@ module Rsodx
|
|
39
41
|
app/presenters
|
40
42
|
app/serializers
|
41
43
|
app/controllers
|
44
|
+
app/lib
|
42
45
|
].each do |subdir|
|
43
46
|
path = File.join(project_root, subdir)
|
44
47
|
loader.push_dir(path) if Dir.exist?(path)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rsodx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eugene Pervushin
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-05-15 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: rake
|
@@ -233,6 +233,20 @@ dependencies:
|
|
233
233
|
- - "~>"
|
234
234
|
- !ruby/object:Gem::Version
|
235
235
|
version: '1.15'
|
236
|
+
- !ruby/object:Gem::Dependency
|
237
|
+
name: syslog
|
238
|
+
requirement: !ruby/object:Gem::Requirement
|
239
|
+
requirements:
|
240
|
+
- - "~>"
|
241
|
+
- !ruby/object:Gem::Version
|
242
|
+
version: '0.3'
|
243
|
+
type: :runtime
|
244
|
+
prerelease: false
|
245
|
+
version_requirements: !ruby/object:Gem::Requirement
|
246
|
+
requirements:
|
247
|
+
- - "~>"
|
248
|
+
- !ruby/object:Gem::Version
|
249
|
+
version: '0.3'
|
236
250
|
description: Rsodx is a lightweight Ruby microframework designed for modular, service-oriented
|
237
251
|
applications. Built with simplicity and performance in mind, it's perfect for small
|
238
252
|
web apps, microservices, and CLI tools.
|
@@ -243,7 +257,6 @@ executables:
|
|
243
257
|
extensions: []
|
244
258
|
extra_rdoc_files: []
|
245
259
|
files:
|
246
|
-
- LICENSE.txt
|
247
260
|
- README.md
|
248
261
|
- bin/console
|
249
262
|
- bin/rsodx
|
@@ -274,6 +287,8 @@ files:
|
|
274
287
|
- lib/rsodx/environment.rb
|
275
288
|
- lib/rsodx/error.rb
|
276
289
|
- lib/rsodx/headers.rb
|
290
|
+
- lib/rsodx/logger.rb
|
291
|
+
- lib/rsodx/logger_adapter.rb
|
277
292
|
- lib/rsodx/presenter.rb
|
278
293
|
- lib/rsodx/request.rb
|
279
294
|
- lib/rsodx/router.rb
|
data/LICENSE.txt
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2025 Первушин
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|