rsodx 0.0.1 → 0.0.3
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 +219 -55
- data/bin/console +6 -4
- data/bin/rsodx +3 -6
- data/lib/rsodx/action.rb +63 -0
- data/lib/rsodx/boot.rb +2 -1
- data/lib/rsodx/cli/cli.rb +56 -0
- data/lib/rsodx/cli/commands/generator.rb +60 -0
- data/lib/rsodx/cli/commands/generators/action.rb +13 -0
- data/lib/rsodx/cli/commands/generators/controller.rb +12 -0
- data/lib/rsodx/cli/commands/generators/migration.rb +52 -0
- data/lib/rsodx/cli/commands/generators/presenter.rb +11 -0
- data/lib/rsodx/cli/commands/generators/serializer.rb +11 -0
- data/lib/rsodx/cli/commands/scaffold.rb +63 -0
- data/lib/rsodx/cli/commands/scaffold_common.rb +107 -0
- data/lib/rsodx/cli/commands/server.rb +27 -0
- data/lib/rsodx/constants.rb +16 -0
- data/lib/rsodx/controller.rb +4 -0
- data/lib/rsodx/delegate.rb +16 -0
- data/lib/rsodx/error.rb +1 -3
- data/lib/rsodx/headers.rb +31 -0
- data/lib/rsodx/presenter.rb +19 -0
- data/lib/rsodx/request.rb +39 -0
- data/lib/rsodx/router_dsl.rb +8 -18
- data/lib/rsodx/serializer.rb +24 -0
- data/lib/rsodx/{interactor.rb → service.rb} +5 -2
- data/lib/rsodx/tasks.rb +0 -5
- data/lib/rsodx/version.rb +1 -1
- data/lib/rsodx.rb +12 -2
- metadata +43 -18
- data/lib/rsodx/cli/generate.rb +0 -17
- data/lib/rsodx/cli/generate_interactor.rb +0 -34
- data/lib/rsodx/cli/generate_migration.rb +0 -43
- data/lib/rsodx/cli/handler.rb +0 -26
- data/lib/rsodx/cli/scaffold.rb +0 -133
- data/lib/rsodx/cli/server.rb +0 -12
- data/lib/rsodx/interactors/healthcheck.rb +0 -7
@@ -1,43 +0,0 @@
|
|
1
|
-
require "fileutils"
|
2
|
-
require "time"
|
3
|
-
|
4
|
-
module Rsodx::Cli
|
5
|
-
class GenerateMigration
|
6
|
-
def initialize(name)
|
7
|
-
@name = name
|
8
|
-
@timestamp = Time.now.utc.strftime("%Y%m%d%H%M%S")
|
9
|
-
@file_name = File.join("db/migrations", "#{@timestamp}_#{snake_case(name)}.rb")
|
10
|
-
end
|
11
|
-
|
12
|
-
def create
|
13
|
-
puts "📦 Creating migration: #{@file_name}"
|
14
|
-
FileUtils.mkdir_p("db/migrations")
|
15
|
-
File.write(@file_name, content)
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def content
|
21
|
-
<<~RUBY
|
22
|
-
Sequel.migration do
|
23
|
-
change do
|
24
|
-
# create_table(:example) do
|
25
|
-
# primary_key :id
|
26
|
-
# String :name
|
27
|
-
# DateTime :created_at
|
28
|
-
# DateTime :updated_at
|
29
|
-
# end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
RUBY
|
33
|
-
end
|
34
|
-
|
35
|
-
def snake_case(str)
|
36
|
-
str.gsub(/::/, '/')
|
37
|
-
.gsub(/([A-Z]+)([A-Z][a-z])/,'\\1_\\2')
|
38
|
-
.gsub(/([a-z\\d])([A-Z])/,'\\1_\\2')
|
39
|
-
.tr("-", "_")
|
40
|
-
.downcase
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
data/lib/rsodx/cli/handler.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
require_relative "scaffold"
|
2
|
-
|
3
|
-
module Rsodx::Cli
|
4
|
-
class Handler
|
5
|
-
def self.run
|
6
|
-
command = ARGV.shift
|
7
|
-
case command
|
8
|
-
when "s", "server"
|
9
|
-
Rsodx::Cli::Server.run
|
10
|
-
when "generate", "g"
|
11
|
-
Rsodx::Cli::Generate.run(ARGV)
|
12
|
-
when "new"
|
13
|
-
name = ARGV.shift
|
14
|
-
if name.nil? || name.empty?
|
15
|
-
puts "Usage: rsodx new <project_name>"
|
16
|
-
exit(1)
|
17
|
-
end
|
18
|
-
Scaffold.new(name).create
|
19
|
-
else
|
20
|
-
puts "Unknown command: #{command}"
|
21
|
-
puts "Usage: rsodx new <project_name>"
|
22
|
-
exit(1)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
data/lib/rsodx/cli/scaffold.rb
DELETED
@@ -1,133 +0,0 @@
|
|
1
|
-
module Rsodx::Cli
|
2
|
-
class Scaffold
|
3
|
-
attr_reader :name
|
4
|
-
|
5
|
-
RUBY_VERSION = "3.4.2".freeze
|
6
|
-
|
7
|
-
# path: "../rsodx"
|
8
|
-
GEMFILE = <<~GEMFILE.freeze
|
9
|
-
source "https://rubygems.org"
|
10
|
-
|
11
|
-
gem "rsodx"
|
12
|
-
gem "pg"
|
13
|
-
GEMFILE
|
14
|
-
|
15
|
-
BINRSODX = <<~BINRSODX.freeze
|
16
|
-
#!/usr/bin/env ruby
|
17
|
-
|
18
|
-
require "fileutils"
|
19
|
-
require "optparse"
|
20
|
-
require "rsodx"
|
21
|
-
|
22
|
-
if __FILE__ == $0
|
23
|
-
Rsodx::Cli::Handler.run
|
24
|
-
end
|
25
|
-
BINRSODX
|
26
|
-
|
27
|
-
CONSOLE = <<~CONSOLE.freeze
|
28
|
-
#!/usr/bin/env ruby
|
29
|
-
|
30
|
-
require "irb"
|
31
|
-
require "irb/completion"
|
32
|
-
|
33
|
-
def reload!
|
34
|
-
puts "🔄 Reloading..."
|
35
|
-
load File.expand_path("../config/environment.rb", __dir__)
|
36
|
-
end
|
37
|
-
|
38
|
-
require_relative "../config/environment"
|
39
|
-
|
40
|
-
puts "🔬 Welcome to Rsodx console (#{ENV['RACK_ENV'] || 'development'})"
|
41
|
-
puts "Tip: access Rsodx modules, models, interactors, etc."
|
42
|
-
|
43
|
-
IRB.start
|
44
|
-
CONSOLE
|
45
|
-
|
46
|
-
CONFIGRU = <<~RACK.freeze
|
47
|
-
require_relative "./app/app"
|
48
|
-
run App
|
49
|
-
RACK
|
50
|
-
|
51
|
-
ROUTE = <<~ROUTE.freeze
|
52
|
-
class Router < Rsodx::Router
|
53
|
-
get "/healthcheck", Rsodx::Interactors::Healthcheck
|
54
|
-
end
|
55
|
-
ROUTE
|
56
|
-
|
57
|
-
APP = <<~APP.freeze
|
58
|
-
require "rsodx"
|
59
|
-
require_relative "router"
|
60
|
-
|
61
|
-
class App < Rsodx::Base
|
62
|
-
use Router
|
63
|
-
end
|
64
|
-
APP
|
65
|
-
|
66
|
-
APP_INTERACTOR = <<~APP_INTERACTOR.freeze
|
67
|
-
class AppInteractor < Rsodx::Interactor
|
68
|
-
end
|
69
|
-
APP_INTERACTOR
|
70
|
-
|
71
|
-
RAKEFILE = <<~RAKEFILE.freeze
|
72
|
-
require_relative "config/environment"
|
73
|
-
require "rsodx/tasks"
|
74
|
-
RAKEFILE
|
75
|
-
|
76
|
-
ENVFILE = <<~ENVFILE.freeze
|
77
|
-
DATABASE_URL=postgres://user:password@localhost:5432/base_development
|
78
|
-
ENVFILE
|
79
|
-
|
80
|
-
FOLDERS = %w[app/api app/interactors app/models app/presenters
|
81
|
-
app/serializers config/initializers
|
82
|
-
config/environments db/migrations spec bin].freeze
|
83
|
-
|
84
|
-
def initialize(name)
|
85
|
-
@name = name
|
86
|
-
@app_path = File.join(Dir.pwd, name)
|
87
|
-
end
|
88
|
-
|
89
|
-
def create
|
90
|
-
puts "Creating project: #{name}"
|
91
|
-
create_folders
|
92
|
-
create_files
|
93
|
-
puts "✅ Done!"
|
94
|
-
end
|
95
|
-
|
96
|
-
def create_folders
|
97
|
-
FOLDERS.each do |path|
|
98
|
-
FileUtils.mkdir_p(File.join(@app_path, path))
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
def create_files
|
103
|
-
write("Gemfile", GEMFILE)
|
104
|
-
write(".ruby-version", RUBY_VERSION)
|
105
|
-
write(".env", ENVFILE)
|
106
|
-
write("config/environment.rb", env_loader)
|
107
|
-
write("Rakefile", RAKEFILE)
|
108
|
-
write("app/interactors/app_interactor.rb", APP_INTERACTOR)
|
109
|
-
write("app/app.rb", APP)
|
110
|
-
write("app/router.rb", ROUTE)
|
111
|
-
write("config/environments/development.rb", "")
|
112
|
-
write("config.ru", CONFIGRU)
|
113
|
-
write("bin/console", CONSOLE)
|
114
|
-
write("bin/rsodx", BINRSODX)
|
115
|
-
FileUtils.chmod("+x", File.join(@app_path, "bin/console"))
|
116
|
-
end
|
117
|
-
|
118
|
-
def write(relative_path, content)
|
119
|
-
full_path = File.join(@app_path, relative_path)
|
120
|
-
File.write(full_path, content)
|
121
|
-
end
|
122
|
-
|
123
|
-
def env_loader
|
124
|
-
<<~RB
|
125
|
-
require "rsodx"
|
126
|
-
Rsodx::Environment.load_dotenv(ENV["RACK_ENV"] || "development")
|
127
|
-
Rsodx::Connect.connect ENV["DATABASE_URL"]
|
128
|
-
Rsodx::Environment.load_initializers(File.expand_path("../..", __FILE__))
|
129
|
-
Rsodx::Boot.load_app_structure(File.expand_path("../..", __FILE__))
|
130
|
-
RB
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
data/lib/rsodx/cli/server.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
require "rack/handler/puma"
|
2
|
-
module Rsodx::Cli
|
3
|
-
class Server
|
4
|
-
def self.run
|
5
|
-
pid = spawn("bundle exec rake server")
|
6
|
-
Process.wait(pid)
|
7
|
-
puts "🚀 Starting Rsodx server PID: #{pid} at http://localhost:9292"
|
8
|
-
rescue LoadError => e
|
9
|
-
abort "❌ Error #{e.message}"
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|