rubypit 0.2.0 → 0.2.2
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/exe/rubypit +5 -0
- data/lib/rubypit/cli.rb +117 -0
- data/lib/rubypit/config/database.rb +59 -0
- data/lib/rubypit/version.rb +1 -1
- data/lib/rubypit.rb +2 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e82f7900009e287932893cc734f12e6b224839c8bf98d99e6fcac1825c6bec1
|
4
|
+
data.tar.gz: 4917da036fa46ea1f8aeebadfe548f678e36a16ad48eb02a87b1e579fe0a1a87
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db5b9260252a9e92b8767c2cf16904497aaf6bba715aed6947aeed0d40cdd4af38461793f5fa961f8cbb05500cfa60ad3c2a76734dcd1b8e79d26d904d28f752
|
7
|
+
data.tar.gz: 51c9aa72d20f1f2be53a80e7336749882cae2f411fe8d19202be3d74613f16686448efd95da7484db20f336fd5c50b4b7462cf0827e746e6158c35c5355dbecd
|
data/exe/rubypit
ADDED
data/lib/rubypit/cli.rb
ADDED
@@ -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,59 @@
|
|
1
|
+
require "sequel"
|
2
|
+
require "yaml"
|
3
|
+
require "erb"
|
4
|
+
|
5
|
+
module Rubypit
|
6
|
+
module Config
|
7
|
+
module Database
|
8
|
+
class << self
|
9
|
+
attr_accessor :connection
|
10
|
+
|
11
|
+
def connect!
|
12
|
+
return connection if connected?
|
13
|
+
|
14
|
+
config = load_configuration
|
15
|
+
self.connection = Sequel.connect(config)
|
16
|
+
setup_connection_pool
|
17
|
+
connection
|
18
|
+
end
|
19
|
+
|
20
|
+
def connected?
|
21
|
+
!connection.nil? && !connection.pool.disconnected?
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def load_configuration
|
27
|
+
config_file = find_database_config
|
28
|
+
yaml = ERB.new(File.read(config_file)).result
|
29
|
+
config = YAML.safe_load(yaml)[environment]
|
30
|
+
|
31
|
+
|
32
|
+
config.transform_keys(&:to_sym)
|
33
|
+
end
|
34
|
+
|
35
|
+
def find_database_config
|
36
|
+
paths = [
|
37
|
+
File.join(Dir.pwd, "config", "database.rb"),
|
38
|
+
File.join(Dir.pwd, "database.rb")
|
39
|
+
]
|
40
|
+
|
41
|
+
config_file = paths.find { |path| File.exist?(path) }
|
42
|
+
raise "Database configuration file not found! Expected at: #{paths.join(" or ")}" unless config_file
|
43
|
+
|
44
|
+
config_file
|
45
|
+
end
|
46
|
+
|
47
|
+
def environment
|
48
|
+
ENV["RACK_ENV"] || ENV["RAILS_ENV"] || "development"
|
49
|
+
end
|
50
|
+
|
51
|
+
def setup_connection_pool
|
52
|
+
connection.pool.max_size = 5
|
53
|
+
connection.logger = RubyPit.logger if defined?(RubyPit.logger)
|
54
|
+
connection.sql_log_level = :debug
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/lib/rubypit/version.rb
CHANGED
data/lib/rubypit.rb
CHANGED
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.
|
4
|
+
version: 0.2.2
|
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
|