quartet 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: df871a1266a1a6a40e05b76a7d89766b4c4760b4c161055c169a8f2762f8496d
4
+ data.tar.gz: af2820266e299556cacf71e0f07afc218a579f1bf4b32ab2e23b823e92f039b3
5
+ SHA512:
6
+ metadata.gz: 8dd1f79f524a71f43759cf30f9b17187ff272dfa0bd218b70a92282c0aa5978d040cb5a519c2fb2cfbc83470967702ae5885b83659b395deb5a3e81435ec6da8
7
+ data.tar.gz: 99b0a2c45dbfb63fa09459fdc5443883204c37ca4b499ccd182f6e93e5c19e2aeeb77826b275e66c75192dc1e24ed340c00bf5d89f1f48d96495cabe7e9ac181
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in quartet.gemspec
8
+ gemspec
9
+
10
+ gem 'rainbow', '~> 3.0'
@@ -0,0 +1,22 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ quartet (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ rainbow (3.0.0)
10
+ rake (10.5.0)
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ bundler (~> 1.17)
17
+ quartet!
18
+ rainbow (~> 3.0)
19
+ rake (~> 10.0)
20
+
21
+ BUNDLED WITH
22
+ 1.17.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Cian Guinee
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,18 @@
1
+ # Quartet - Sinatra + ActiveRecord + MySQL + Rake
2
+ A quick start generator for database backed Sinatra apps
3
+
4
+ ## Installation
5
+ Install by running
6
+ `$ gem install quartet`
7
+
8
+ ## Usage
9
+ Run as follows
10
+ `$ quartet <app_name>`
11
+
12
+ ## Contributing
13
+
14
+ Bug reports and pull requests are welcome on GitHub at https://github.com/guineec/quartet.
15
+
16
+ ## License
17
+
18
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'rainbow/refinement'
5
+ require 'quartet'
6
+
7
+ if ARGV.count < 1
8
+ puts 'Error! No app name provided'.red
9
+ exit 11
10
+ end
11
+
12
+ Quartet.create_app(ARGV[0])
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'quartet/version'
4
+ require 'quartet/builder'
5
+ require 'rainbow/refinement'
6
+ require 'fileutils'
7
+
8
+ module Quartet
9
+ using Rainbow
10
+
11
+ class Error < StandardError; end
12
+ class BundlerFailedError < StandardError; end
13
+
14
+ def create_app(app_name)
15
+ puts "Creating #{app_name}...".green
16
+ print 'Creating directories... '
17
+ create_directories(app_name)
18
+ puts '[ DONE ]'.green
19
+ print 'Building app files... '
20
+ build_app_files(app_name)
21
+ puts '[ DONE ]'.green
22
+ puts 'Running bundler...'
23
+ Dir.chdir(app_name)
24
+ output = `bundle`
25
+ puts output
26
+ puts "Project #{app_name} created!".green
27
+ puts 'The following rake tasks are now available...'
28
+ puts %(
29
+ rake db:create # Create the database from DATABASE_URL or config/database.yml for the current Rails.env (use db:create:all to create all dbs in the config)
30
+ rake db:create_migration # Create a migration (parameters: NAME, VERSION)
31
+ rake db:drop # Drops the database using DATABASE_URL or the current Rails.env (use db:drop:all to drop all databases)
32
+ rake db:fixtures:load # Load fixtures into the current environment's database
33
+ rake db:migrate # Migrate the database (options: VERSION=x, VERBOSE=false)
34
+ rake db:migrate:status # Display status of migrations
35
+ rake db:rollback # Rolls the schema back to the previous version (specify steps w/ STEP=n)
36
+ rake db:schema:dump # Create a db/schema.rb file that can be portably used against any DB supported by AR
37
+ rake db:schema:load # Load a schema.rb file into the database
38
+ rake db:seed # Load the seed data from db/seeds.rb
39
+ rake db:setup # Create the database, load the schema, and initialize with the seed data (use db:reset to also drop the db first)
40
+ rake db:structure:dump # Dump the database structure to db/structure.sql
41
+ rake db:version # Retrieves the current schema version number
42
+ rake serve # Start the development server
43
+ rake console # Start the interactive shell
44
+ )
45
+ end
46
+
47
+ def create_directories(app_name)
48
+ base_dir = Dir.getwd
49
+ app_dir = "#{base_dir}/#{app_name}"
50
+ FileUtils.mkdir_p(app_dir)
51
+ %w[config db models public tmp views].each { |dirname| FileUtils.mkdir_p("#{app_dir}/#{dirname}") }
52
+ end
53
+
54
+ def build_app_files(app_name)
55
+ Gem.find_files('quartet/builders/*.rb').each do |file|
56
+ file_name = file.split('/')[-1].gsub('.rb', '')
57
+ require "quartet/builders/#{file_name}"
58
+
59
+ file_builder = Kernel.const_get("Quartet::Builders::#{file_name.capitalize}").new
60
+
61
+ File.open(file_builder.filepath(app_name), 'w') do |f|
62
+ f.write(file_builder.build(app_name))
63
+ f.flush
64
+ end
65
+ end
66
+ end
67
+
68
+ module_function :create_app, :create_directories, :build_app_files
69
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Quartet::Builders
4
+ class Builder
5
+ def initialize
6
+ @directory = ''
7
+ @file_type = '.rb'
8
+ end
9
+
10
+ def filepath(app_name)
11
+ unless @name_override
12
+ return "#{app_name}/#{@directory}/#{underscore(self.class.to_s.split('::')[-1])}#{@file_type}"
13
+ end
14
+
15
+ "#{app_name}/#{@directory}/#{@name_override}#{@file_type}"
16
+ end
17
+
18
+ def underscore(string)
19
+ string.gsub(/::/, '/')
20
+ .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
21
+ .gsub(/([a-z\d])([A-Z])/, '\1_\2')
22
+ .tr('-', '_')
23
+ .downcase
24
+ end
25
+
26
+ def build(app_name); end
27
+ end
28
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Quartet::Builders
4
+ class App < Quartet::Builders::Builder
5
+ def build(_app_name)
6
+ %{# frozen_string_literal: true
7
+
8
+ require 'sinatra'
9
+ require 'sinatra/activerecord'
10
+
11
+ # Require files in models and lib directories
12
+ Dir["./models/*.rb"].each {|file| require file }
13
+ Dir[File.join("./lib", "**/*.rb")].each {|file| require file }
14
+
15
+ get '/' do
16
+ erb :welcome
17
+ end
18
+ }
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Quartet::Builders
4
+ class Config < Quartet::Builders::Builder
5
+ def initialize
6
+ @directory = ''
7
+ @file_type = '.ru'
8
+ end
9
+
10
+ def build(_app_name)
11
+ %{# frozen_string_literal: true
12
+
13
+ require 'rubygems'
14
+ require 'bundler'
15
+
16
+ Bundler.require
17
+
18
+ require File.join(File.dirname(__FILE__), 'app.rb')
19
+ run Sinatra::Application
20
+ }
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Quartet::Builders
4
+ class Database < Quartet::Builders::Builder
5
+ def initialize
6
+ @directory = 'config'
7
+ @file_type = '.yml'
8
+ end
9
+
10
+ def build(app_name)
11
+ %(development:
12
+ adapter: mysql2
13
+ encoding: utf8
14
+ reconnect: false
15
+ database: #{underscore(app_name)}
16
+ pool: 5
17
+ username: root
18
+ password: root
19
+ )
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Quartet::Builders
4
+ class Gemfile < Quartet::Builders::Builder
5
+ def initialize
6
+ @name_override = "Gemfile"
7
+ @directory = ''
8
+ @file_type = ''
9
+ end
10
+
11
+ def build(app_name)
12
+ %{# frozen_string_literal: true
13
+
14
+ # Gemfile for #{app_name} generated by Quartet
15
+
16
+ source "https://rubygems.org"
17
+
18
+ git_source(:github) {|repo_name| "https://github.com/\#{repo_name}" }
19
+
20
+ # gem "rails"
21
+
22
+ gem "sinatra", "~> 2.0"
23
+
24
+ gem "sinatra-activerecord", "~> 2.0"
25
+
26
+ gem "mysql2", "~> 0.5.3"
27
+
28
+ gem "rake", "~> 13.0"
29
+
30
+ gem "irb", "~> 1.2"
31
+ }
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Quartet::Builders
4
+ class Index < Quartet::Builders::Builder
5
+ def initialize
6
+ @directory = 'public'
7
+ @file_type = '.html'
8
+ end
9
+
10
+ def build(_app_name)
11
+ %(<!DOCTYPE html>
12
+ <html lang="en">
13
+ <head>
14
+ <meta charset="UTF-8">
15
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
16
+ <title>Unexpected Error</title>
17
+ <style>
18
+ .msg-container {
19
+ display: flex;
20
+ flex-direction: column;
21
+ align-items: center;
22
+ justify-content: center;
23
+ width: 100vw;
24
+ height: 100vh;
25
+ font-family: arial,sans-serif;
26
+ color: #333;
27
+ }
28
+
29
+ .header {
30
+ font-size: 3rem;
31
+ margin-bottom: 1rem;
32
+ }
33
+
34
+ .message {
35
+ font-size: 1.2rem;
36
+ margin-top: 0.3rem;
37
+ }
38
+ </style>
39
+ </head>
40
+ <body>
41
+ <div class="msg-container">
42
+ <h2 class="header">If you're seeing this...</h2>
43
+ <h4 class="message">Something is wrong!</h4>
44
+ </div>
45
+ </body>
46
+ </html>
47
+ )
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Quartet::Builders
4
+ class Rakefile < Quartet::Builders::Builder
5
+ def initialize
6
+ @name_override = "Rakefile"
7
+ @directory = ''
8
+ @file_type = ''
9
+ end
10
+
11
+ def build(app_name)
12
+ %(# frozen_string_literal: true
13
+
14
+ # Rakefile generated for #{app_name} by Quartet
15
+ # Add tasks as required here
16
+
17
+ require 'sinatra/activerecord/rake'
18
+
19
+ namespace :db do
20
+ task :load_config do
21
+ require './app'
22
+ end
23
+ end
24
+
25
+ task :c do
26
+ sh 'bundle exec irb -I. -r app.rb'
27
+ end
28
+
29
+ task :console do
30
+ sh 'bundle exec irb -I. -r app.rb'
31
+ end
32
+
33
+ task :serve do
34
+ sh 'bundle exec rackup config.ru'
35
+ end
36
+
37
+ task :s do
38
+ sh 'bundle exec rackup config.ru'
39
+ end
40
+ )
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Quartet::Builders
4
+ class Readme < Quartet::Builders::Builder
5
+ def initialize
6
+ @name_override = 'README'
7
+ @directory = ''
8
+ @file_type = '.md'
9
+ end
10
+
11
+ def build(app_name)
12
+ %(# #{app_name}
13
+ Things to include here:
14
+ - A description of your app
15
+ - Instructions for installation/build
16
+ - Instructions for development/running tests etc
17
+ - Licence information
18
+ - ...
19
+ )
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Quartet::Builders
4
+ class Welcome < Quartet::Builders::Builder
5
+ def initialize
6
+ @directory = 'views'
7
+ @file_type = '.erb'
8
+ end
9
+
10
+ def build(app_name)
11
+ %(<!DOCTYPE html>
12
+ <html lang="en">
13
+ <head>
14
+ <meta charset="UTF-8">
15
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
16
+ <title>#{app_name}</title>
17
+ <style>
18
+ .msg-container {
19
+ display: flex;
20
+ flex-direction: column;
21
+ align-items: center;
22
+ justify-content: center;
23
+ width: 100vw;
24
+ height: 100vh;
25
+ font-family: arial,sans-serif;
26
+ color: #333;
27
+ }
28
+
29
+ .header {
30
+ font-size: 3rem;
31
+ margin-bottom: 1rem;
32
+ }
33
+
34
+ .message {
35
+ font-size: 1.2rem;
36
+ margin-top: 0.3rem;
37
+ }
38
+ </style>
39
+ </head>
40
+ <body>
41
+ <div class="msg-container">
42
+ <h2 class="header">Quartet executed successfully!</h2>
43
+ <h4 class="message">Welcome to #{app_name}</h4>
44
+ </div>åå
45
+ </body>
46
+ </html>
47
+ )
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,3 @@
1
+ module Quartet
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,39 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "quartet/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "quartet"
8
+ spec.version = Quartet::VERSION
9
+ spec.authors = ["Cian Guinee"]
10
+ spec.email = ["cian.guinee@gmail.com"]
11
+
12
+ spec.summary = %q{Sinatra + ActiveRecord + MySQL + Rake}
13
+ spec.description = %q{A quick start generator for database backed Sinatra apps}
14
+ spec.homepage = "https://github.com/guineec/quartet"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["homepage_uri"] = spec.homepage
21
+ spec.metadata["source_code_uri"] = "https://github.com/guineec/quartet"
22
+ spec.metadata["changelog_uri"] = "https://github.com/guineec/quartet"
23
+ else
24
+ raise "RubyGems 2.0 or newer is required to protect against " \
25
+ "public gem pushes."
26
+ end
27
+
28
+ # Specify which files should be added to the gem when it is released.
29
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
30
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
31
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
32
+ end
33
+ spec.bindir = "exe"
34
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
+ spec.require_paths = ["lib"]
36
+
37
+ spec.add_development_dependency "bundler", "~> 1.17"
38
+ spec.add_development_dependency "rake", "~> 10.0"
39
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: quartet
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Cian Guinee
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-08-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: A quick start generator for database backed Sinatra apps
42
+ email:
43
+ - cian.guinee@gmail.com
44
+ executables:
45
+ - quartet
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - Gemfile
51
+ - Gemfile.lock
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - bin/setup
56
+ - exe/quartet
57
+ - lib/quartet.rb
58
+ - lib/quartet/builder.rb
59
+ - lib/quartet/builders/app.rb
60
+ - lib/quartet/builders/config.rb
61
+ - lib/quartet/builders/database.rb
62
+ - lib/quartet/builders/gemfile.rb
63
+ - lib/quartet/builders/index.rb
64
+ - lib/quartet/builders/rakefile.rb
65
+ - lib/quartet/builders/readme.rb
66
+ - lib/quartet/builders/welcome.rb
67
+ - lib/quartet/version.rb
68
+ - quartet.gemspec
69
+ homepage: https://github.com/guineec/quartet
70
+ licenses:
71
+ - MIT
72
+ metadata:
73
+ homepage_uri: https://github.com/guineec/quartet
74
+ source_code_uri: https://github.com/guineec/quartet
75
+ changelog_uri: https://github.com/guineec/quartet
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubygems_version: 3.0.3
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: Sinatra + ActiveRecord + MySQL + Rake
95
+ test_files: []