rubypit 0.2.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f04b996ff2c05ed797a5bd010e11793584fcfdc7ebb26ebb67539cefb0ea2080
4
- data.tar.gz: 05b591e61746c8d3c4c4e30756e4a4a9c599c2d7b679a6cde7477a7a8f09490b
3
+ metadata.gz: 55475ffe4a528b4539650f345780a7e61f87b6641b5d6e495d4cf2e3bbac14ed
4
+ data.tar.gz: 93d2f48a3104f561673517fbe48f174603d406b07585ed5aff0c287ae6960861
5
5
  SHA512:
6
- metadata.gz: cb81dd1d404da49a819c2fe41289f0d55da187b25c1e4487aa1ae82d64e3d16342a3f65a15849274b0fce6a1c289fd58bf7f92bd3ac1e3b088e0e62d882be964
7
- data.tar.gz: 3208c376cfb6cb6f3c1212e2873e159368dc460827ebfe3702e984d6cafa485bd9f16da85ae27e65a94cd6b16eb4bb7366987c1558512522f102773892036720
6
+ metadata.gz: 9f02c05ba0d358ea373f7c4046219ea9e605b9d2f1d5af817165b0e70b1a8545a62417e1835b8045256aef35409afc3df272f7301d0072138f8defdd0588e947
7
+ data.tar.gz: 5792f7fb054f8ec41b94adb8f0eff820525b04bd8e5e2e977f1c914df3d824b1a543c7be04a1432c71c29b717b194d75f7c4c0a84892a2b3eefc1a3d0455a7c5
data/exe/rubypit ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubypit'
3
+
4
+ # Your CLI logic here
5
+ Rubypit::CLI.new(ARGV)
@@ -0,0 +1,117 @@
1
+ require 'thor'
2
+ require 'fileutils'
3
+
4
+ module RubyPit
5
+ class CLI < Thor
6
+ desc "create_project NAME", "Create a new RubyPit project"
7
+ def create_project(name)
8
+ generator = ProjectGenerator.new(name)
9
+ generator.generate
10
+ end
11
+ end
12
+
13
+ class ProjectGenerator
14
+ attr_reader :name
15
+
16
+ def initialize(name)
17
+ @name = name
18
+ end
19
+
20
+ def generate
21
+ create_project_directory
22
+ create_config_directory
23
+ create_database_config
24
+ create_gitignore
25
+ create_gemfile
26
+ end
27
+
28
+ private
29
+
30
+ def create_project_directory
31
+ FileUtils.mkdir_p(project_path)
32
+ FileUtils.mkdir_p(File.join(project_path, 'app'))
33
+ FileUtils.mkdir_p(File.join(project_path, 'app', 'models'))
34
+ end
35
+
36
+ def create_config_directory
37
+ FileUtils.mkdir_p(File.join(project_path, 'config'))
38
+ end
39
+
40
+ def create_database_config
41
+ File.open(File.join(project_path, 'config', 'database.rb'), 'w') do |file|
42
+ file.write(database_config_template)
43
+ end
44
+ end
45
+
46
+ def create_gitignore
47
+ File.open(File.join(project_path, '.gitignore'), 'w') do |file|
48
+ file.write(gitignore_template)
49
+ end
50
+ end
51
+
52
+ def create_gemfile
53
+ File.open(File.join(project_path, 'Gemfile'), 'w') do |file|
54
+ file.write(gemfile_template)
55
+ end
56
+ end
57
+
58
+ def project_path
59
+ File.join(Dir.pwd, name)
60
+ end
61
+
62
+ def database_config_template
63
+ <<~RUBY
64
+ {
65
+ development: {
66
+ adapter: 'postgres',
67
+ host: 'localhost',
68
+ database: '#{name}_development',
69
+ username: 'user',
70
+ password: 'password',
71
+ port: 5432
72
+ },
73
+
74
+ test: {
75
+ adapter: 'postgres',
76
+ host: 'localhost',
77
+ database: '#{name}_test',
78
+ username: 'user',
79
+ password: 'password',
80
+ port: 5432
81
+ },
82
+
83
+ production: {
84
+ adapter: 'postgres',
85
+ host: ENV['DB_HOST'],
86
+ database: ENV['DB_NAME'],
87
+ username: ENV['DB_USER'],
88
+ password: ENV['DB_PASSWORD'],
89
+ port: ENV['DB_PORT']
90
+ }
91
+ }
92
+ RUBY
93
+ end
94
+
95
+ def gitignore_template
96
+ <<~TEXT
97
+ .env
98
+ .DS_Store
99
+ /log/*
100
+ !/log/.keep
101
+ /tmp/*
102
+ !/tmp/.keep
103
+ config/database.yml
104
+ TEXT
105
+ end
106
+
107
+ def gemfile_template
108
+ <<~RUBY
109
+ source 'https://rubygems.org'
110
+
111
+ gem 'rubypit'
112
+ gem 'sequel'
113
+ gem 'pg'
114
+ RUBY
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "sequel"
4
+ require "yaml"
5
+ require "erb"
6
+
7
+ module RubyPit
8
+ module Config
9
+ module Database
10
+ class << self
11
+ attr_accessor :connection
12
+
13
+ def connect!
14
+ return connection if connected?
15
+
16
+ config = load_configuration
17
+ self.connection = Sequel.connect(config)
18
+ setup_connection_pool
19
+ connection
20
+ end
21
+
22
+ def connected?
23
+ !connection.nil? && !connection.pool.disconnected?
24
+ end
25
+
26
+ private
27
+
28
+ def load_configuration
29
+ config_file = find_database_config
30
+ yaml = ERB.new(File.read(config_file)).result
31
+ config = YAML.safe_load(yaml)[environment]
32
+
33
+
34
+ config.transform_keys(&:to_sym)
35
+ end
36
+
37
+ def find_database_config
38
+ paths = [
39
+ File.join(Dir.pwd, "config", "database.rb"),
40
+ File.join(Dir.pwd, "database.rb")
41
+ ]
42
+
43
+ config_file = paths.find { |path| File.exist?(path) }
44
+ raise "Database configuration file not found! Expected at: #{paths.join(" or ")}" unless config_file
45
+
46
+ config_file
47
+ end
48
+
49
+ def environment
50
+ ENV["RACK_ENV"] || ENV["RAILS_ENV"] || "development"
51
+ end
52
+
53
+ def setup_connection_pool
54
+ connection.pool.max_size = 5 # Adjust pool size as needed
55
+ connection.logger = RubyPit.logger if defined?(RubyPit.logger)
56
+ connection.sql_log_level = :debug
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rubypit
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubypit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - raushan_raman
@@ -27,7 +27,8 @@ dependencies:
27
27
  description: Framework in Ruby
28
28
  email:
29
29
  - raushan.raman23011999@gmail.com
30
- executables: []
30
+ executables:
31
+ - rubypit
31
32
  extensions: []
32
33
  extra_rdoc_files: []
33
34
  files:
@@ -37,7 +38,10 @@ files:
37
38
  - LICENSE.txt
38
39
  - README.md
39
40
  - Rakefile
41
+ - exe/rubypit
40
42
  - lib/rubypit.rb
43
+ - lib/rubypit/cli.rb
44
+ - lib/rubypit/config/database.rb
41
45
  - lib/rubypit/version.rb
42
46
  - sig/rubypit.rbs
43
47
  homepage: https://rubygems.org/gems/rubypit