barebones 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.
- checksums.yaml +7 -0
- data/.gitignore +7 -0
- data/LICENSE +21 -0
- data/README.md +78 -0
- data/barebones.gemspec +16 -0
- data/bin/barebones +5 -0
- data/lib/barebones.rb +4 -0
- data/lib/barebones/builders/app_builder.rb +152 -0
- data/lib/barebones/generators/app_generator.rb +156 -0
- data/lib/barebones/text_format_helpers.rb +15 -0
- data/lib/barebones/version.rb +4 -0
- data/templates/Gemfile.erb +50 -0
- data/templates/README.md.erb +18 -0
- data/templates/api_application_controller.rb +6 -0
- data/templates/api_constraints.rb.erb +10 -0
- data/templates/api_defaults_concern.rb +27 -0
- data/templates/barebones_decorator.rb.erb +17 -0
- data/templates/barebones_gitignore +20 -0
- data/templates/carrierwave.rb +19 -0
- data/templates/config_ping.json.jbuilder +1 -0
- data/templates/configs_controller.rb +5 -0
- data/templates/database.yml.erb +27 -0
- data/templates/layout.json.jbuilder +22 -0
- data/templates/multi_json.rb +2 -0
- data/templates/redis.rb +26 -0
- data/templates/resque.rake +9 -0
- data/templates/resque.rb +1 -0
- data/templates/routes.rb +17 -0
- data/templates/secrets.yml.erb +30 -0
- data/templates/test_job.rb +9 -0
- metadata +87 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 91b3b9832d19717a5e7cc86ebc367121867d91f1
|
4
|
+
data.tar.gz: f0753f193dd972965b1517686bfc737afdb21970
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 28970db0368a14bfc61917faec90e66ee0dbdd554c162a5358a099b95d6796669c15bd0edcd0915cd0708037dedf59ef184e6beecbe20d93ddaca9b37c66a66d
|
7
|
+
data.tar.gz: 6f6936a47fbdb12d240b542d6671fad5554a5bad592e01cd4cf6b23e595e674dea40d58e63265066e7c8da24176999d55337fe2caba38ddcf7c03ff41d428a52
|
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2015 Danny Yu
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
Barebones
|
2
|
+
===
|
3
|
+
Barebones is my personal base Rails application. After developing a
|
4
|
+
couple of Rails applications, I thought that there were some common
|
5
|
+
gems and patterns that would be nice to have out of the box.
|
6
|
+
|
7
|
+
Installation
|
8
|
+
---
|
9
|
+
For now, just run ./bin/barebones [AppName]
|
10
|
+
|
11
|
+
#### Flags
|
12
|
+
If you don't like using any of the below gems or configurations for whatever reason, you can skip them:
|
13
|
+
* --skip-api
|
14
|
+
* --skip-sorcery
|
15
|
+
* --skip-minitest
|
16
|
+
* --skip-resque
|
17
|
+
* --skip-carrierwave
|
18
|
+
|
19
|
+
For example:
|
20
|
+
`./bin/barebones [AppName] --skip-api --skip-sorcery`
|
21
|
+
|
22
|
+
Gemfile
|
23
|
+
---
|
24
|
+
Barebones' [Gemfile](templates/Gemfile.erb) includes various preconfigured gems such as:
|
25
|
+
####File Uploading
|
26
|
+
* [Carrierwave](https://github.com/carrierwaveuploader/carrierwave) for file uploading
|
27
|
+
* [Fog](https://github.com/fog/fog) for AWS/Google cloud storage
|
28
|
+
* [MiniMagick](https://github.com/minimagick/minimagick) for image cropping/resizing and all that good stuff
|
29
|
+
|
30
|
+
####Background Processing
|
31
|
+
* [Resque](https://github.com/resque/resque) for background workers
|
32
|
+
* [Resque-Scheduler](https://github.com/resque/resque-scheduler) for queueing workers in the future
|
33
|
+
|
34
|
+
####Database
|
35
|
+
* [Postgres](https://rubygems.org/gems/pg/versions/0.18.3)
|
36
|
+
|
37
|
+
####Dev/Testing
|
38
|
+
* [Byebug](https://github.com/deivid-rodriguez/byebug) for debugging
|
39
|
+
* [Pry Byebug](https://github.com/deivid-rodriguez/pry-byebug) for debugging background jobs
|
40
|
+
* [Web Console](https://github.com/rails/web-console) for debugging views
|
41
|
+
* [Quiet Assets](https://github.com/evrone/quiet_assets) for muting the Rails asset pipeline log
|
42
|
+
* [Awesome Print](https://github.com/michaeldv/awesome_print) for pretty printing command line objects
|
43
|
+
|
44
|
+
####Testing
|
45
|
+
* [Minitest](https://github.com/blowmage/minitest-rails) for TDD/BDD
|
46
|
+
* [Minitest Reporters](https://github.com/kern/minitest-reporters) for customizable Minitest output formats
|
47
|
+
|
48
|
+
####Authentication
|
49
|
+
* [Sorcery](https://github.com/NoamB/sorcery) for user authentication
|
50
|
+
|
51
|
+
####API
|
52
|
+
* [Jbuilder](https://github.com/rails/jbuilder) for building JSON structures
|
53
|
+
* [oj](https://github.com/ohler55/oj) for faster JSON parsing (and a faster Jbuilder)
|
54
|
+
* [oj_mimic_json](https://github.com/ohler55/oj_mimic_json)
|
55
|
+
* [MultiJSON](https://github.com/intridea/multi_json)
|
56
|
+
|
57
|
+
Design Patterns
|
58
|
+
---
|
59
|
+
* Services (Pre-made folder)
|
60
|
+
* [Custom Decorator Class](templates/barebones_decorator.rb.erb) (A custom subclass of SimpleDelegator)
|
61
|
+
|
62
|
+
API
|
63
|
+
---
|
64
|
+
* [Routes](templates/Gemfile.erb) with API subdomain and version namespacing
|
65
|
+
* [ApiConstraints](templates/api_constraints.rb.erb) for API version control
|
66
|
+
* [Configurations/Ping endpoint](templates/configs_controller.rb) to test that the API works :)
|
67
|
+
|
68
|
+
Dependencies
|
69
|
+
---
|
70
|
+
Barebones requires the latest version of Ruby (2.2.3), Rails (4.2.3), and
|
71
|
+
PostgreSQL (9.4) on your local machine.
|
72
|
+
|
73
|
+
License
|
74
|
+
---
|
75
|
+
Barebones is copyright © 2015 Danny Yu.
|
76
|
+
It is free software, and may be redistributed under the terms specified in the [LICENSE] file.
|
77
|
+
|
78
|
+
[LICENSE]: LICENSE
|
data/barebones.gemspec
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "./lib/barebones/version"
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "barebones"
|
5
|
+
s.version = "0.1.0"
|
6
|
+
s.date = "2015-10-19"
|
7
|
+
s.licenses = ['MIT']
|
8
|
+
s.summary = "Rails template generator"
|
9
|
+
s.description = "Personal Rails template generator for Danny Yu"
|
10
|
+
s.authors = ["Danny Yu"]
|
11
|
+
s.files = `git ls-files -z`.split("\x0")
|
12
|
+
s.executables = ["barebones"]
|
13
|
+
s.homepage = "https://rubygems.org/gems/barebones"
|
14
|
+
|
15
|
+
s.add_dependency 'rails', Barebones::RAILS_VERSION
|
16
|
+
end
|
data/bin/barebones
ADDED
data/lib/barebones.rb
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
module Barebones
|
2
|
+
class AppBuilder < Rails::AppBuilder
|
3
|
+
include Barebones::TextFormatHelpers
|
4
|
+
|
5
|
+
# Overrides
|
6
|
+
def readme
|
7
|
+
template "README.md.erb", "README.md"
|
8
|
+
end
|
9
|
+
|
10
|
+
def gemfile
|
11
|
+
template "Gemfile.erb", "Gemfile"
|
12
|
+
replace_regex_in_file("Gemfile", /\n{2,}/, "\n\n")
|
13
|
+
end
|
14
|
+
|
15
|
+
def gitignore
|
16
|
+
template "barebones_gitignore", ".gitignore"
|
17
|
+
end
|
18
|
+
|
19
|
+
def app
|
20
|
+
super
|
21
|
+
keep_file "app/services"
|
22
|
+
keep_file "app/decorators"
|
23
|
+
template "barebones_decorator.rb.erb",
|
24
|
+
"app/decorators/#{app_name.parameterize.underscore}_decorator.rb"
|
25
|
+
keep_file "app/workers"
|
26
|
+
end
|
27
|
+
|
28
|
+
def config
|
29
|
+
empty_directory "config"
|
30
|
+
|
31
|
+
inside "config" do
|
32
|
+
customize_routes
|
33
|
+
template "application.rb"
|
34
|
+
customize_application_rb
|
35
|
+
|
36
|
+
template "environment.rb"
|
37
|
+
|
38
|
+
directory "environments"
|
39
|
+
directory "initializers"
|
40
|
+
directory "locales"
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
def database_yml
|
46
|
+
template "database.yml.erb", "config/database.yml"
|
47
|
+
end
|
48
|
+
|
49
|
+
# Custom
|
50
|
+
def set_ruby_version
|
51
|
+
create_file ".ruby-version", "#{Barebones::RUBY_VERSION}"
|
52
|
+
end
|
53
|
+
|
54
|
+
def customize_application_rb
|
55
|
+
inject_into_file "application.rb",
|
56
|
+
after: "config.active_record.raise_in_transactional_callbacks = true\n" do
|
57
|
+
"\n#{spaces(4)}# Autoload 'lib' folder\n"\
|
58
|
+
"#{spaces(4)}config.autoload_paths << Rails.root.join('lib')\n"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def customize_routes
|
63
|
+
template "routes.rb", "config/routes.rb"
|
64
|
+
end
|
65
|
+
|
66
|
+
def setup_oj
|
67
|
+
template "multi_json.rb", "config/initializers/multi_json.rb"
|
68
|
+
end
|
69
|
+
|
70
|
+
def create_api_constraints
|
71
|
+
template "api_constraints.rb.erb", "lib/api_constraints.rb"
|
72
|
+
end
|
73
|
+
|
74
|
+
def create_api_v1_defaults
|
75
|
+
empty_directory "app/controllers/api"
|
76
|
+
empty_directory "app/controllers/api/v1"
|
77
|
+
template "api_application_controller.rb", "app/controllers/api/v1/application_controller.rb"
|
78
|
+
template "api_defaults_concern.rb", "app/controllers/concerns/api_defaults.rb"
|
79
|
+
end
|
80
|
+
|
81
|
+
def create_api_configurations
|
82
|
+
empty_directory "app/views/api/v1/configs"
|
83
|
+
template "configs_controller.rb", "app/controllers/api/v1/configs_controller.rb"
|
84
|
+
template "config_ping.json.jbuilder", "app/views/api/v1/configs/ping.json.jbuilder"
|
85
|
+
end
|
86
|
+
|
87
|
+
def create_api_layouts
|
88
|
+
empty_directory "app/views/layouts/api/v1"
|
89
|
+
template "layout.json.jbuilder", "app/views/layouts/api/v1/application.json.jbuilder"
|
90
|
+
empty_directory "app/views/api/defaults"
|
91
|
+
create_file "app/views/api/defaults/success.json.jbuilder"
|
92
|
+
create_file "app/views/api/defaults/fail.json.jbuilder"
|
93
|
+
end
|
94
|
+
|
95
|
+
def customize_secrets
|
96
|
+
template "secrets.yml.erb", "config/secrets.yml"
|
97
|
+
end
|
98
|
+
|
99
|
+
def raise_on_delivery_errors
|
100
|
+
file = "config/environments/development.rb"
|
101
|
+
gsub_file file, "config.action_mailer.raise_delivery_errors = false" do |match|
|
102
|
+
"config.action_mailer.raise_delivery_errors = true"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def create_staging_environment
|
107
|
+
environment_path = "config/environments"
|
108
|
+
run "cp #{environment_path}/development.rb #{environment_path}/staging.rb"
|
109
|
+
end
|
110
|
+
|
111
|
+
def configure_minitest
|
112
|
+
autoload_paths_line = "config.autoload_paths << Rails.root.join('lib')\n"
|
113
|
+
inject_into_file "config/application.rb",
|
114
|
+
after: autoload_paths_line do
|
115
|
+
"\n#{spaces(4)}# Auto generate test files\n"\
|
116
|
+
"#{spaces(4)}config.generators do |g|\n"\
|
117
|
+
"#{spaces(6)}g.test_framework :minitest, spec: false, fixture: false\n"\
|
118
|
+
"#{spaces(4)}end\n"
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def configure_active_job
|
123
|
+
autoload_paths_line = "config.autoload_paths << Rails.root.join('lib')\n"
|
124
|
+
inject_into_file "config/application.rb",
|
125
|
+
after: autoload_paths_line do
|
126
|
+
"\n#{spaces(4)}# Set ActiveJob to use Resque\n"\
|
127
|
+
"#{spaces(4)}config.active_job.queue_adapter = :resque\n"
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def configure_redis
|
132
|
+
template "redis.rb", "config/initializers/redis.rb"
|
133
|
+
end
|
134
|
+
|
135
|
+
def configure_resque
|
136
|
+
template "resque.rb", "config/initializers/resque.rb"
|
137
|
+
end
|
138
|
+
|
139
|
+
def create_test_job
|
140
|
+
template "test_job.rb", "app/workers/test_job.rb"
|
141
|
+
end
|
142
|
+
|
143
|
+
def create_resque_rake_task
|
144
|
+
template "resque.rake", "lib/tasks/resque.rake"
|
145
|
+
end
|
146
|
+
|
147
|
+
def configure_carrierwave
|
148
|
+
template "carrierwave.rb", "config/initializers/carrierwave.rb"
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
152
|
+
end
|
@@ -0,0 +1,156 @@
|
|
1
|
+
require 'rails/generators/rails/app/app_generator'
|
2
|
+
|
3
|
+
module Barebones
|
4
|
+
class AppGenerator < Rails::Generators::AppGenerator
|
5
|
+
|
6
|
+
class_option :skip_bundle, type: :boolean, aliases: "-B", default: true,
|
7
|
+
desc: "Don't run bundle install"
|
8
|
+
|
9
|
+
class_option :skip_api, type: :boolean, default: false,
|
10
|
+
desc: "Skip creating an API. Default is false."
|
11
|
+
|
12
|
+
class_option :skip_resque, type: :boolean, default: false,
|
13
|
+
desc: "Skip using Resque. Default is false."
|
14
|
+
|
15
|
+
class_option :skip_sorcery, type: :boolean, default: false,
|
16
|
+
desc: "Skip using Sorcery for user authentication. Default is false."
|
17
|
+
|
18
|
+
class_option :skip_minitest, type: :boolean, default: false,
|
19
|
+
desc: "Skip using Minitest. Default is false."
|
20
|
+
|
21
|
+
class_option :skip_carrierwave, type: :boolean, default: false,
|
22
|
+
desc: "Skip using Carrierwave. Default is false."
|
23
|
+
|
24
|
+
def customizations
|
25
|
+
say "Invoking customizations..."
|
26
|
+
invoke :setup_ruby
|
27
|
+
invoke :setup_api
|
28
|
+
invoke :setup_secrets
|
29
|
+
invoke :setup_environments
|
30
|
+
invoke :setup_gems
|
31
|
+
invoke :outro
|
32
|
+
end
|
33
|
+
|
34
|
+
def setup_ruby
|
35
|
+
say "Setting ruby version..."
|
36
|
+
build :set_ruby_version
|
37
|
+
end
|
38
|
+
|
39
|
+
def setup_api
|
40
|
+
if options[:with_api]
|
41
|
+
say "Setting up an API..."
|
42
|
+
build :customize_routes
|
43
|
+
build :setup_oj
|
44
|
+
build :create_api_constraints
|
45
|
+
build :create_api_v1_defaults
|
46
|
+
build :create_api_configurations
|
47
|
+
build :create_api_layouts
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def setup_secrets
|
52
|
+
say "Setting up secrets..."
|
53
|
+
build :customize_secrets
|
54
|
+
end
|
55
|
+
|
56
|
+
def setup_environments
|
57
|
+
say "Setting up environments..."
|
58
|
+
invoke :setup_development_environment
|
59
|
+
invoke :setup_staging_environment
|
60
|
+
invoke :setup_production_environment
|
61
|
+
end
|
62
|
+
|
63
|
+
def setup_development_environment
|
64
|
+
build :raise_on_delivery_errors
|
65
|
+
end
|
66
|
+
|
67
|
+
def setup_staging_environment
|
68
|
+
build :create_staging_environment
|
69
|
+
end
|
70
|
+
|
71
|
+
def setup_production_environment
|
72
|
+
end
|
73
|
+
|
74
|
+
def setup_gems
|
75
|
+
invoke :setup_minitest
|
76
|
+
#invoke :setup_sorcery
|
77
|
+
invoke :setup_resque
|
78
|
+
invoke :setup_carrierwave
|
79
|
+
end
|
80
|
+
|
81
|
+
def setup_minitest
|
82
|
+
unless options[:skip_minitest]
|
83
|
+
say "Setting up Minitest gem..."
|
84
|
+
build :configure_minitest
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def setup_resque
|
89
|
+
unless options[:skip_resque]
|
90
|
+
say "Setting up Resque/Redis gems..."
|
91
|
+
build :configure_active_job
|
92
|
+
build :configure_redis
|
93
|
+
build :configure_resque
|
94
|
+
build :create_test_job
|
95
|
+
build :create_resque_rake_task
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def setup_carrierwave
|
100
|
+
unless options[:setup_carrierwave]
|
101
|
+
say "Setting up Carrierwave gem..."
|
102
|
+
build :configure_carrierwave
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def outro
|
107
|
+
invoke :minitest_setup_reminder
|
108
|
+
invoke :resque_web_reminder
|
109
|
+
say "\e[34mSweet, we're done!\e[0m"
|
110
|
+
end
|
111
|
+
|
112
|
+
def minitest_setup_reminder
|
113
|
+
unless options[:skip_minitest]
|
114
|
+
say "==========================================\n"\
|
115
|
+
"Remember to run `rails g minitest:install` \n"\
|
116
|
+
"and to set up Minitest-Reporters!\n"\
|
117
|
+
"==========================================\n"
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def resque_web_reminder
|
122
|
+
unless options[:skip_resque]
|
123
|
+
say "==============================================\n"\
|
124
|
+
"If you'd like to have the resque-web dashboard, \n"\
|
125
|
+
"you should add the following to your routes: \n"\
|
126
|
+
"`require 'resque/scheduler/server'`\n"\
|
127
|
+
"`mount Resque::Server.new, :at => '/resque'`\n"\
|
128
|
+
"==============================================\n"
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
protected
|
133
|
+
|
134
|
+
# Supply Thor with template root path
|
135
|
+
def self.source_root
|
136
|
+
File.expand_path("../../../templates", File.dirname(__FILE__))
|
137
|
+
end
|
138
|
+
|
139
|
+
# Fall back to Rails default templates
|
140
|
+
def self.source_paths
|
141
|
+
paths = super
|
142
|
+
paths << Rails::Generators::AppGenerator.source_root
|
143
|
+
end
|
144
|
+
|
145
|
+
# Look for custom builder class
|
146
|
+
def get_builder_class
|
147
|
+
Barebones::AppBuilder
|
148
|
+
end
|
149
|
+
|
150
|
+
# Custom
|
151
|
+
def str_to_class(klass_str)
|
152
|
+
klass_str.gsub(/\s/,"_").camelize(:upper)
|
153
|
+
end
|
154
|
+
|
155
|
+
end
|
156
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
ruby "<%= Barebones::RUBY_VERSION %>"
|
4
|
+
|
5
|
+
# Defaults
|
6
|
+
gem "rails", "<%= Barebones::RAILS_VERSION %>"
|
7
|
+
gem "sass-rails", "~> 5.0"
|
8
|
+
gem "uglifier"
|
9
|
+
gem "jquery-rails"
|
10
|
+
gem "turbolinks"
|
11
|
+
gem "jbuilder", "~> 2.0"
|
12
|
+
|
13
|
+
group :development, :test do
|
14
|
+
gem "byebug"
|
15
|
+
gem "pry-byebug"
|
16
|
+
gem "web-console", "~> 2.0"
|
17
|
+
gem "spring", "1.3.6"
|
18
|
+
gem "quiet_assets"
|
19
|
+
gem "awesome_print"
|
20
|
+
<% unless options[:skip_minitest] %>
|
21
|
+
gem "minitest-rails"
|
22
|
+
gem "minitest-reporters"
|
23
|
+
<% end %>
|
24
|
+
end
|
25
|
+
|
26
|
+
<% unless options[:skip_carrierwave] %>
|
27
|
+
# File Uploads
|
28
|
+
gem "fog"
|
29
|
+
gem "mini_magick"
|
30
|
+
gem "carrierwave"
|
31
|
+
<% end %>
|
32
|
+
|
33
|
+
<% unless options[:skip_resque] %>
|
34
|
+
# Background Processing
|
35
|
+
gem "resque"
|
36
|
+
gem "resque-scheduler"
|
37
|
+
<% end %>
|
38
|
+
|
39
|
+
# Database
|
40
|
+
gem "pg", "~> 0.18.2"
|
41
|
+
|
42
|
+
<% unless options[:skip_sorcery] %>
|
43
|
+
# Authentication
|
44
|
+
gem "sorcery"
|
45
|
+
<% end %>
|
46
|
+
|
47
|
+
# Faster JSON Parsing
|
48
|
+
gem "oj"
|
49
|
+
gem "oj_mimic_json"
|
50
|
+
gem "multi_json"
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# <%= app_name.humanize %>
|
2
|
+
|
3
|
+
### Getting Started
|
4
|
+
|
5
|
+
## Setting Up Postgresql
|
6
|
+
`psql`
|
7
|
+
`CREATE ROLE <%= app_name.parameterize.underscore %>_admin`
|
8
|
+
`ALTER ROLE <%= app_name.parameterize.underscore %>_admin WITH LOGIN CREATEDB REPLICATION SUPERUSER;`
|
9
|
+
`rake db:migrate`
|
10
|
+
`rake db:setup`
|
11
|
+
|
12
|
+
## Setting Up The Server
|
13
|
+
|
14
|
+
`bundle install`
|
15
|
+
`rake db:migrate db:setup`
|
16
|
+
|
17
|
+
## Running The Server
|
18
|
+
Run `rails s -p [port#]` to start the server.
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class ApiConstraints
|
2
|
+
def initialize(options)
|
3
|
+
@version = options[:version]
|
4
|
+
@default = options[:default]
|
5
|
+
end
|
6
|
+
|
7
|
+
def matches?(req)
|
8
|
+
@default || req.headers['Accept'].include?("application/com.<%= app_name.parameterize.underscore %>.v#{@version}")
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module ApiDefaults
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
# Default Paths
|
5
|
+
API_VIEW_PATH = "api/v1"
|
6
|
+
API_DEFAULT_SUCCESS_PATH = "defaults/success"
|
7
|
+
API_DEFAULT_FAIL_PATH = "defaults/fail"
|
8
|
+
|
9
|
+
# Statuses
|
10
|
+
SUCCESS_STATUS = "success"
|
11
|
+
FAIL_STATUS = "fail"
|
12
|
+
|
13
|
+
included do
|
14
|
+
layout 'api/v1/application'
|
15
|
+
|
16
|
+
def render_api_success(path=ApiDefaults::API_DEFAULT_SUCCESS_PATH)
|
17
|
+
@status = ApiDefaults::SUCCESS_STATUS
|
18
|
+
return render template: "#{API_VIEW_PATH}/#{path}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def render_api_fail(path=ApiDefaults::API_DEFAULT_FAIL_PATH)
|
22
|
+
@status = ApiDefaults::FAIL_STATUS
|
23
|
+
return render template: "#{API_VIEW_PATH}/#{path}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class <%= "#{str_to_class(app_name)}Decorator" %> < SimpleDelegator
|
2
|
+
# Preserve the original obj class
|
3
|
+
def class
|
4
|
+
super
|
5
|
+
__getobj__.class
|
6
|
+
end
|
7
|
+
|
8
|
+
# Allow for decorator to wrap
|
9
|
+
# collections.
|
10
|
+
private
|
11
|
+
def self.wrap(collection)
|
12
|
+
collection.map do |obj|
|
13
|
+
new obj
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
!.keep
|
2
|
+
*.DS_Store
|
3
|
+
*.swo
|
4
|
+
*.swp
|
5
|
+
/.bundle
|
6
|
+
/coverage/*
|
7
|
+
/db/*.sqlite3
|
8
|
+
/db/*.sqlite3-journal
|
9
|
+
|
10
|
+
# Ignore all logfiles and tempfiles.
|
11
|
+
/log/*.log
|
12
|
+
/tmp/*
|
13
|
+
*.*~
|
14
|
+
|
15
|
+
# Ignore uploads from file management gems
|
16
|
+
/public/system
|
17
|
+
/public/uploads
|
18
|
+
|
19
|
+
# Redis stores
|
20
|
+
dump.rdb
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Uncomment for Google Cloud Storage
|
2
|
+
# CarrierWave.configure do |config|
|
3
|
+
# config.fog_credentials = {
|
4
|
+
# provider: 'Google',
|
5
|
+
# google_storage_access_key_id: Rails.application.secrets.cw_access_key_id,
|
6
|
+
# google_storage_secret_access_key: Rails.application.secrets.cw_secret_access_key
|
7
|
+
# }
|
8
|
+
# config.fog_directory = Rails.application.secrets.cw_bucket
|
9
|
+
# end
|
10
|
+
|
11
|
+
CarrierWave.configure do |config|
|
12
|
+
config.fog_credentials = {
|
13
|
+
:provider => 'AWS',
|
14
|
+
:aws_access_key_id => Rails.application.secrets.cw_access_key_id, # required
|
15
|
+
:aws_secret_access_key => Rails.application.secrets.cw_secret_access_key, # required
|
16
|
+
#:region => Rails.application.secrets.cw_region # optional, defaults to 'us-east-1'
|
17
|
+
}
|
18
|
+
config.fog_directory = Rails.application.secrets.cw_bucket # required
|
19
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
json.ping "pong!"
|
@@ -0,0 +1,27 @@
|
|
1
|
+
default: &default
|
2
|
+
adapter: postgresql
|
3
|
+
encoding: unicode
|
4
|
+
pool: 5
|
5
|
+
timeout: 5000
|
6
|
+
|
7
|
+
development:
|
8
|
+
<<: *default
|
9
|
+
database: <%= app_name.parameterize.underscore %>_development
|
10
|
+
username: <%= app_name.parameterize.underscore %>_admin
|
11
|
+
password: password
|
12
|
+
|
13
|
+
staging:
|
14
|
+
<<: *default
|
15
|
+
database: <%= app_name.parameterize.underscore %>_staging
|
16
|
+
username: <%= app_name.parameterize.underscore %>_admin
|
17
|
+
password: password
|
18
|
+
|
19
|
+
production:
|
20
|
+
<<: *default
|
21
|
+
database: <%= app_name.parameterize.underscore %>_production
|
22
|
+
username: <%= app_name.parameterize.underscore %>_admin
|
23
|
+
password: password
|
24
|
+
|
25
|
+
test:
|
26
|
+
<<: *default
|
27
|
+
database: <%= app_name.parameterize.underscore %>_test
|
@@ -0,0 +1,22 @@
|
|
1
|
+
json.status @status
|
2
|
+
|
3
|
+
if @errors.present? || @error_msg.present?
|
4
|
+
json.errors do
|
5
|
+
if @error_msg.present?
|
6
|
+
json.message @error_msg # Error message to display to the user
|
7
|
+
end
|
8
|
+
if @errors.present?
|
9
|
+
json.errors @errors do |error|
|
10
|
+
json.message error
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
else
|
15
|
+
# Don't show error block if there aren't any errors
|
16
|
+
end
|
17
|
+
|
18
|
+
if @data.present?
|
19
|
+
json.data @data
|
20
|
+
else
|
21
|
+
json.data JSON.parse(yield)
|
22
|
+
end
|
data/templates/redis.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
redis_db_0 = Redis.new(
|
2
|
+
:url => Rails.application.secrets.redis_url,
|
3
|
+
:port => Rails.application.secrets.redis_port,
|
4
|
+
:db => Rails.application.secrets.redis_db,
|
5
|
+
)
|
6
|
+
|
7
|
+
$redis_default = Redis::Namespace.new(
|
8
|
+
Rails.application.secrets.redis_namespace_default,
|
9
|
+
:redis => redis_db_0
|
10
|
+
)
|
11
|
+
|
12
|
+
# http://www.rubydoc.info/github/redis/redis-rb/Redis/Client
|
13
|
+
# :url => lambda { ENV["REDIS_URL"] },
|
14
|
+
# :scheme => "redis",
|
15
|
+
# :host => "127.0.0.1",
|
16
|
+
# :port => 6379,
|
17
|
+
# :path => nil,
|
18
|
+
# :timeout => 5.0,
|
19
|
+
# :connect_timeout => 5.0,
|
20
|
+
# :password => nil,
|
21
|
+
# :db => 0,
|
22
|
+
# :driver => nil,
|
23
|
+
# :id => nil,
|
24
|
+
# :tcp_keepalive => 0,
|
25
|
+
# :reconnect_attempts => 1,
|
26
|
+
# :inherit_socket => false
|
data/templates/resque.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Resque.redis = $redis_default
|
data/templates/routes.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
Rails.application.routes.draw do
|
2
|
+
|
3
|
+
root 'welcome#index'
|
4
|
+
|
5
|
+
# API
|
6
|
+
constraints subdomain: (/(dev){0,1}api/) do
|
7
|
+
namespace :api, path: "/", defaults: { format: "json" } do
|
8
|
+
scope module: :v1, constraints: ApiConstraints.new(version: 1, default: true) do
|
9
|
+
|
10
|
+
# Configurations
|
11
|
+
get "ping" => "configs#ping"
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
defaults: &DEFAULTS
|
2
|
+
|
3
|
+
development:
|
4
|
+
<<: *DEFAULTS
|
5
|
+
secret_key_base: <%= SecureRandom.hex(64) %>
|
6
|
+
redis_url: "redis://localhost"
|
7
|
+
redis_port: 6379
|
8
|
+
redis_db: 0
|
9
|
+
redis_namespace_default: "redis_default"
|
10
|
+
|
11
|
+
staging:
|
12
|
+
<<: *DEFAULTS
|
13
|
+
secret_key_base: <%= SecureRandom.hex(64) %>
|
14
|
+
redis_url:
|
15
|
+
redis_port:
|
16
|
+
redis_namespace_default:
|
17
|
+
|
18
|
+
production:
|
19
|
+
<<: *DEFAULTS
|
20
|
+
secret_key_base: <%%= ENV["SECRET_KEY_BASE"] %>
|
21
|
+
redis_url:
|
22
|
+
redis_port:
|
23
|
+
redis_namespace_default:
|
24
|
+
|
25
|
+
test:
|
26
|
+
<<: *DEFAULTS
|
27
|
+
secret_key_base: <%= SecureRandom.hex(64) %>
|
28
|
+
redis_url:
|
29
|
+
redis_port:
|
30
|
+
redis_namespace_default:
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: barebones
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Danny Yu
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.2.4
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.2.4
|
27
|
+
description: Personal Rails template generator for Danny Yu
|
28
|
+
email:
|
29
|
+
executables:
|
30
|
+
- barebones
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- LICENSE
|
36
|
+
- README.md
|
37
|
+
- barebones.gemspec
|
38
|
+
- bin/barebones
|
39
|
+
- lib/barebones.rb
|
40
|
+
- lib/barebones/builders/app_builder.rb
|
41
|
+
- lib/barebones/generators/app_generator.rb
|
42
|
+
- lib/barebones/text_format_helpers.rb
|
43
|
+
- lib/barebones/version.rb
|
44
|
+
- templates/Gemfile.erb
|
45
|
+
- templates/README.md.erb
|
46
|
+
- templates/api_application_controller.rb
|
47
|
+
- templates/api_constraints.rb.erb
|
48
|
+
- templates/api_defaults_concern.rb
|
49
|
+
- templates/barebones_decorator.rb.erb
|
50
|
+
- templates/barebones_gitignore
|
51
|
+
- templates/carrierwave.rb
|
52
|
+
- templates/config_ping.json.jbuilder
|
53
|
+
- templates/configs_controller.rb
|
54
|
+
- templates/database.yml.erb
|
55
|
+
- templates/layout.json.jbuilder
|
56
|
+
- templates/multi_json.rb
|
57
|
+
- templates/redis.rb
|
58
|
+
- templates/resque.rake
|
59
|
+
- templates/resque.rb
|
60
|
+
- templates/routes.rb
|
61
|
+
- templates/secrets.yml.erb
|
62
|
+
- templates/test_job.rb
|
63
|
+
homepage: https://rubygems.org/gems/barebones
|
64
|
+
licenses:
|
65
|
+
- MIT
|
66
|
+
metadata: {}
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 2.4.5.1
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: Rails template generator
|
87
|
+
test_files: []
|