rsodx 0.0.5 → 0.1.0
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 +34 -0
- data/lib/rsodx/cli/cli.rb +25 -0
- data/lib/rsodx/cli/commands/console.rb +33 -0
- data/lib/rsodx/cli/commands/db/migrate.rb +20 -0
- data/lib/rsodx/cli/commands/db/rollback.rb +27 -0
- data/lib/rsodx/cli/commands/scaffold.rb +7 -4
- data/lib/rsodx/cli/commands/scaffold_common.rb +25 -25
- data/lib/rsodx/tasks.rb +0 -13
- data/lib/rsodx/version.rb +1 -1
- data/lib/rsodx.rb +33 -0
- metadata +47 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61e9cf61ed88c22762b697fb6a3a2fdc9c5ce3ce52e4d37d866f5448434f331e
|
4
|
+
data.tar.gz: 894c422fa5d6a073bf768cdba0911745754809872fb50eb053e3b611608ae5a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07c13df22646b8ba6870b1c33cc6ca92bd88fb75bcd7e45aa0a3611406f1d5a3dd36f9d56c48a7cc5ad9c1230fd0f180c9f8d8b560efe23c77001bb2a4ba32e8
|
7
|
+
data.tar.gz: 8c8c3db72ea43d5f8da5c00ceaf0ef365589335f46932ffae464558e057de610dc5e06380aa8dcc70c8f2b6bdd3c345e82e8a83b04343e3edaa377390582dec9
|
data/README.md
CHANGED
@@ -69,6 +69,40 @@ bin/rsodx [command] [args]
|
|
69
69
|
|
70
70
|
---
|
71
71
|
|
72
|
+
Конечно! Вот секция для `README.md` на английском — про команды `db:migrate` и `db:rollback`:
|
73
|
+
|
74
|
+
---
|
75
|
+
|
76
|
+
## 🛠 Database Commands
|
77
|
+
|
78
|
+
The `rsodx` CLI provides simple tools for running Sequel migrations:
|
79
|
+
|
80
|
+
### 🔼 `db:migrate`
|
81
|
+
|
82
|
+
Runs all pending migrations in `db/migrations`.
|
83
|
+
|
84
|
+
```bash
|
85
|
+
bin/rsodx db:migrate
|
86
|
+
```
|
87
|
+
|
88
|
+
- Automatically creates the `schema_migrations` table if it doesn't exist.
|
89
|
+
- Supports timestamped migrations (e.g. `20250417061127_create_users.rb`).
|
90
|
+
- Prints a success message on completion.
|
91
|
+
|
92
|
+
### 🔽 `db:rollback`
|
93
|
+
|
94
|
+
Rolls back the last executed migration.
|
95
|
+
|
96
|
+
```bash
|
97
|
+
bin/rsodx db:rollback
|
98
|
+
```
|
99
|
+
|
100
|
+
- Determines the current version from the `schema_migrations` table.
|
101
|
+
- Rolls back to the previous migration based on timestamp.
|
102
|
+
- Skips rollback if only one migration is applied.
|
103
|
+
|
104
|
+
---
|
105
|
+
|
72
106
|
## 🔧 Generators
|
73
107
|
|
74
108
|
Generate various application components using simple commands:
|
data/lib/rsodx/cli/cli.rb
CHANGED
@@ -9,6 +9,31 @@ module Rsodx::Cli
|
|
9
9
|
extend Dry::CLI::Registry
|
10
10
|
|
11
11
|
def self.setup!
|
12
|
+
register_commands_with_alias(
|
13
|
+
group: "",
|
14
|
+
alias_prefix: "",
|
15
|
+
commands: {
|
16
|
+
"db:migrate" => ::Rsodx::Cli::Commands::Db::Migrate
|
17
|
+
}
|
18
|
+
)
|
19
|
+
|
20
|
+
register_commands_with_alias(
|
21
|
+
group: "",
|
22
|
+
alias_prefix: "",
|
23
|
+
commands: {
|
24
|
+
"db:rollback" => ::Rsodx::Cli::Commands::Db::Rollback
|
25
|
+
}
|
26
|
+
)
|
27
|
+
|
28
|
+
register_commands_with_alias(
|
29
|
+
group: "",
|
30
|
+
alias_prefix: "",
|
31
|
+
commands: {
|
32
|
+
"console" => ::Rsodx::Cli::Commands::Console,
|
33
|
+
"c" => ::Rsodx::Cli::Commands::Console
|
34
|
+
}
|
35
|
+
)
|
36
|
+
|
12
37
|
register_commands_with_alias(
|
13
38
|
group: "",
|
14
39
|
alias_prefix: "",
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "dry/cli"
|
2
|
+
require "irb"
|
3
|
+
require "irb/completion"
|
4
|
+
|
5
|
+
module Rsodx::Cli::Commands
|
6
|
+
class Console < Dry::CLI::Command
|
7
|
+
desc "Start the Rsodx development console"
|
8
|
+
|
9
|
+
def call(*)
|
10
|
+
project_root = Rsodx.project_root
|
11
|
+
environment_path = File.join(project_root, "config", "environment.rb")
|
12
|
+
|
13
|
+
unless File.exist?(environment_path)
|
14
|
+
abort "❌ Could not find config/environment.rb in #{project_root}"
|
15
|
+
end
|
16
|
+
|
17
|
+
require environment_path
|
18
|
+
|
19
|
+
TOPLEVEL_BINDING.eval('def reload!; Rsodx.reload!; end')
|
20
|
+
|
21
|
+
puts Rsodx::LOGO
|
22
|
+
puts "🔬 Welcome to Rsodx console (#{ENV['RACK_ENV'] || 'development'})"
|
23
|
+
puts "Tip: access Rsodx modules, models, services, etc."
|
24
|
+
|
25
|
+
ARGV.clear
|
26
|
+
IRB.start
|
27
|
+
rescue LoadError => e
|
28
|
+
abort "❌ Failed to load: #{e.message}"
|
29
|
+
rescue StandardError => e
|
30
|
+
abort "❌ An error occurred: #{e.message}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "sequel/extensions/migration"
|
2
|
+
|
3
|
+
module Rsodx::Cli::Commands::Db
|
4
|
+
class Migrate < Dry::CLI::Command
|
5
|
+
desc "Migrate"
|
6
|
+
|
7
|
+
def call(*)
|
8
|
+
project_root = Rsodx.project_root
|
9
|
+
environment_path = File.join(project_root, "config", "environment.rb")
|
10
|
+
|
11
|
+
unless File.exist?(environment_path)
|
12
|
+
abort "❌ Could not find config/environment.rb in #{project_root}"
|
13
|
+
end
|
14
|
+
|
15
|
+
require environment_path
|
16
|
+
|
17
|
+
Sequel::Migrator.run(Rsodx::Connect.db, "db/migrations")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "sequel/extensions/migration"
|
2
|
+
|
3
|
+
module Rsodx::Cli::Commands::Db
|
4
|
+
class Rollback < Dry::CLI::Command
|
5
|
+
desc "Rollback"
|
6
|
+
|
7
|
+
def call(*)
|
8
|
+
project_root = Rsodx.project_root
|
9
|
+
environment_path = File.join(project_root, "config", "environment.rb")
|
10
|
+
|
11
|
+
unless File.exist?(environment_path)
|
12
|
+
abort "❌ Could not find config/environment.rb in #{project_root}"
|
13
|
+
end
|
14
|
+
|
15
|
+
require environment_path
|
16
|
+
migration_table = :schema_migrations
|
17
|
+
migration_dir = 'db/migrations'
|
18
|
+
|
19
|
+
versions = Rsodx::Connect.db[migration_table].select(:filename).map { |r| r[:filename] }
|
20
|
+
version_numbers = versions.map { |f| f.to_s[/^\d+/].to_i }.sort
|
21
|
+
|
22
|
+
current_version = version_numbers.last
|
23
|
+
previous_version = version_numbers[-2] || 0
|
24
|
+
Sequel::Migrator.run(Rsodx::Connect.db, migration_dir, target: previous_version)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -28,8 +28,13 @@ module Rsodx::Cli::Commands
|
|
28
28
|
private
|
29
29
|
|
30
30
|
def create_folders
|
31
|
-
|
32
|
-
FileUtils.mkdir_p(File.join(@app_path,
|
31
|
+
KEEPABLE_FOLDERS.each do |folder|
|
32
|
+
FileUtils.mkdir_p(File.join(@app_path, folder))
|
33
|
+
FileUtils.touch(File.join(@app_path, folder, '.keep'))
|
34
|
+
end
|
35
|
+
|
36
|
+
FRAMEWORK_FOLDERS.each do |folder|
|
37
|
+
FileUtils.mkdir_p(File.join(@app_path, folder))
|
33
38
|
end
|
34
39
|
end
|
35
40
|
|
@@ -48,11 +53,9 @@ module Rsodx::Cli::Commands
|
|
48
53
|
write("app/router.rb", ROUTE)
|
49
54
|
write("config/environments/development.rb", "")
|
50
55
|
write("config.ru", CONFIGRU)
|
51
|
-
write("bin/console", CONSOLE)
|
52
56
|
write("bin/rsodx", BINRSODX)
|
53
57
|
|
54
58
|
FileUtils.chmod("+x", File.join(@app_path, "bin/rsodx"))
|
55
|
-
FileUtils.chmod("+x", File.join(@app_path, "bin/console"))
|
56
59
|
end
|
57
60
|
|
58
61
|
def write(relative_path, content)
|
@@ -2,8 +2,8 @@ module Rsodx::Cli::Commands::ScaffoldCommon
|
|
2
2
|
RUBY_VERSION = "3.4.2".freeze
|
3
3
|
|
4
4
|
GITIGNORE = <<~GITIGNORE.freeze
|
5
|
-
|
6
|
-
|
5
|
+
.env
|
6
|
+
tmp/
|
7
7
|
GITIGNORE
|
8
8
|
|
9
9
|
# path: "../rsodx"
|
@@ -25,32 +25,15 @@ module Rsodx::Cli::Commands::ScaffoldCommon
|
|
25
25
|
Rsodx::CLI.call
|
26
26
|
BINRSODX
|
27
27
|
|
28
|
-
CONSOLE = <<~CONSOLE.freeze
|
29
|
-
#!/usr/bin/env ruby
|
30
|
-
|
31
|
-
require "irb"
|
32
|
-
require "irb/completion"
|
33
|
-
|
34
|
-
def reload!
|
35
|
-
puts "🔄 Reloading..."
|
36
|
-
load File.expand_path("../config/environment.rb", __dir__)
|
37
|
-
end
|
38
|
-
|
39
|
-
require_relative "../config/environment"
|
40
|
-
|
41
|
-
puts "🔬 Welcome to Rsodx console (#{ENV['RACK_ENV'] || 'development'})"
|
42
|
-
puts "Tip: access Rsodx modules, models, services, etc."
|
43
|
-
|
44
|
-
IRB.start
|
45
|
-
CONSOLE
|
46
|
-
|
47
28
|
CONFIGRU = <<~RACK.freeze
|
48
29
|
require_relative "./app/app"
|
49
30
|
run App
|
50
31
|
RACK
|
51
32
|
|
52
33
|
ENV_LOADER = <<~ENV_LOADER.freeze
|
34
|
+
require "zeitwerk"
|
53
35
|
require "rsodx"
|
36
|
+
|
54
37
|
Rsodx::Environment.load_dotenv(ENV["RACK_ENV"] || "development")
|
55
38
|
|
56
39
|
Rsodx.configure do |config|
|
@@ -59,7 +42,8 @@ module Rsodx::Cli::Commands::ScaffoldCommon
|
|
59
42
|
Rsodx::Connect.connect
|
60
43
|
|
61
44
|
Rsodx::Environment.load_initializers(File.expand_path("../..", __FILE__))
|
62
|
-
|
45
|
+
|
46
|
+
Rsodx.loader
|
63
47
|
ENV_LOADER
|
64
48
|
|
65
49
|
ROUTE = <<~ROUTE.freeze
|
@@ -106,7 +90,23 @@ module Rsodx::Cli::Commands::ScaffoldCommon
|
|
106
90
|
DATABASE_URL=postgres://rsodx:paSs4321@localhost:5432/rsodx_development
|
107
91
|
ENVFILE
|
108
92
|
|
109
|
-
|
110
|
-
|
111
|
-
|
93
|
+
KEEPABLE_FOLDERS = %w[
|
94
|
+
lib
|
95
|
+
app/controllers
|
96
|
+
app/workers
|
97
|
+
app/services
|
98
|
+
app/models
|
99
|
+
app/presenters
|
100
|
+
app/serializers
|
101
|
+
config/initializers
|
102
|
+
config/environments
|
103
|
+
db/migrations
|
104
|
+
spec
|
105
|
+
].freeze
|
106
|
+
|
107
|
+
FRAMEWORK_FOLDERS = %w[
|
108
|
+
bin
|
109
|
+
config
|
110
|
+
].freeze
|
111
|
+
|
112
112
|
end
|
data/lib/rsodx/tasks.rb
CHANGED
@@ -1,15 +1,2 @@
|
|
1
1
|
return unless defined?(Rake::DSL) rescue false
|
2
2
|
include Rake::DSL if defined?(Rake::DSL)
|
3
|
-
|
4
|
-
require "sequel/extensions/migration"
|
5
|
-
|
6
|
-
namespace :db do
|
7
|
-
task :migrate do
|
8
|
-
Sequel::Migrator.run(Rsodx::Connect.db, "db/migrations")
|
9
|
-
end
|
10
|
-
|
11
|
-
task :rollback do
|
12
|
-
target = Sequel::Migrator.apply(Rsodx::Connect.db, "db/migrations", :down) - 1
|
13
|
-
Sequel::Migrator.run(Rsodx::Connect.db, "db/migrations", target: target)
|
14
|
-
end
|
15
|
-
end
|
data/lib/rsodx/version.rb
CHANGED
data/lib/rsodx.rb
CHANGED
@@ -22,6 +22,39 @@ module Rsodx
|
|
22
22
|
yield(config)
|
23
23
|
end
|
24
24
|
end
|
25
|
+
|
26
|
+
def self.project_root
|
27
|
+
@root ||= Dir.pwd
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.loader
|
31
|
+
@loader ||= begin
|
32
|
+
loader = Zeitwerk::Loader.new
|
33
|
+
|
34
|
+
# need to be merged with ScaffoldCommon
|
35
|
+
%w[
|
36
|
+
app/models
|
37
|
+
app/services
|
38
|
+
app/workers
|
39
|
+
app/presenters
|
40
|
+
app/serializers
|
41
|
+
app/controllers
|
42
|
+
].each do |subdir|
|
43
|
+
path = File.join(project_root, subdir)
|
44
|
+
loader.push_dir(path) if Dir.exist?(path)
|
45
|
+
end
|
46
|
+
|
47
|
+
loader.enable_reloading
|
48
|
+
loader.setup
|
49
|
+
loader
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.reload!
|
54
|
+
puts "🔄 Reloading..."
|
55
|
+
loader.reload
|
56
|
+
end
|
25
57
|
end
|
26
58
|
|
27
59
|
Rsodx.config ||= Rsodx::Configuration.new
|
60
|
+
Rsodx.loader
|
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.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eugene Pervushin
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-04-
|
10
|
+
date: 2025-04-17 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: rake
|
@@ -191,6 +191,48 @@ dependencies:
|
|
191
191
|
- - "~>"
|
192
192
|
- !ruby/object:Gem::Version
|
193
193
|
version: '1.2'
|
194
|
+
- !ruby/object:Gem::Dependency
|
195
|
+
name: zeitwerk
|
196
|
+
requirement: !ruby/object:Gem::Requirement
|
197
|
+
requirements:
|
198
|
+
- - "~>"
|
199
|
+
- !ruby/object:Gem::Version
|
200
|
+
version: '2.7'
|
201
|
+
type: :runtime
|
202
|
+
prerelease: false
|
203
|
+
version_requirements: !ruby/object:Gem::Requirement
|
204
|
+
requirements:
|
205
|
+
- - "~>"
|
206
|
+
- !ruby/object:Gem::Version
|
207
|
+
version: '2.7'
|
208
|
+
- !ruby/object:Gem::Dependency
|
209
|
+
name: rdoc
|
210
|
+
requirement: !ruby/object:Gem::Requirement
|
211
|
+
requirements:
|
212
|
+
- - "~>"
|
213
|
+
- !ruby/object:Gem::Version
|
214
|
+
version: '6.13'
|
215
|
+
type: :runtime
|
216
|
+
prerelease: false
|
217
|
+
version_requirements: !ruby/object:Gem::Requirement
|
218
|
+
requirements:
|
219
|
+
- - "~>"
|
220
|
+
- !ruby/object:Gem::Version
|
221
|
+
version: '6.13'
|
222
|
+
- !ruby/object:Gem::Dependency
|
223
|
+
name: irb
|
224
|
+
requirement: !ruby/object:Gem::Requirement
|
225
|
+
requirements:
|
226
|
+
- - "~>"
|
227
|
+
- !ruby/object:Gem::Version
|
228
|
+
version: '1.15'
|
229
|
+
type: :runtime
|
230
|
+
prerelease: false
|
231
|
+
version_requirements: !ruby/object:Gem::Requirement
|
232
|
+
requirements:
|
233
|
+
- - "~>"
|
234
|
+
- !ruby/object:Gem::Version
|
235
|
+
version: '1.15'
|
194
236
|
description: Rsodx is a lightweight Ruby microframework designed for modular, service-oriented
|
195
237
|
applications. Built with simplicity and performance in mind, it's perfect for small
|
196
238
|
web apps, microservices, and CLI tools.
|
@@ -211,6 +253,9 @@ files:
|
|
211
253
|
- lib/rsodx/base.rb
|
212
254
|
- lib/rsodx/boot.rb
|
213
255
|
- lib/rsodx/cli/cli.rb
|
256
|
+
- lib/rsodx/cli/commands/console.rb
|
257
|
+
- lib/rsodx/cli/commands/db/migrate.rb
|
258
|
+
- lib/rsodx/cli/commands/db/rollback.rb
|
214
259
|
- lib/rsodx/cli/commands/generator.rb
|
215
260
|
- lib/rsodx/cli/commands/generators/action.rb
|
216
261
|
- lib/rsodx/cli/commands/generators/controller.rb
|