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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f04b996ff2c05ed797a5bd010e11793584fcfdc7ebb26ebb67539cefb0ea2080
4
- data.tar.gz: 05b591e61746c8d3c4c4e30756e4a4a9c599c2d7b679a6cde7477a7a8f09490b
3
+ metadata.gz: 5e82f7900009e287932893cc734f12e6b224839c8bf98d99e6fcac1825c6bec1
4
+ data.tar.gz: 4917da036fa46ea1f8aeebadfe548f678e36a16ad48eb02a87b1e579fe0a1a87
5
5
  SHA512:
6
- metadata.gz: cb81dd1d404da49a819c2fe41289f0d55da187b25c1e4487aa1ae82d64e3d16342a3f65a15849274b0fce6a1c289fd58bf7f92bd3ac1e3b088e0e62d882be964
7
- data.tar.gz: 3208c376cfb6cb6f3c1212e2873e159368dc460827ebfe3702e984d6cafa485bd9f16da85ae27e65a94cd6b16eb4bb7366987c1558512522f102773892036720
6
+ metadata.gz: db5b9260252a9e92b8767c2cf16904497aaf6bba715aed6947aeed0d40cdd4af38461793f5fa961f8cbb05500cfa60ad3c2a76734dcd1b8e79d26d904d28f752
7
+ data.tar.gz: 51c9aa72d20f1f2be53a80e7336749882cae2f411fe8d19202be3d74613f16686448efd95da7484db20f336fd5c50b4b7462cf0827e746e6158c35c5355dbecd
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,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
@@ -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.2"
5
5
  end
data/lib/rubypit.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "rubypit/version"
4
+ require_relative 'rubypit/config/database'
5
+ require_relative "rubypit/cli"
4
6
 
5
7
  module Rubypit
6
8
  class Error < StandardError; 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.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