Skip to content

Commit e861080

Browse files
committed
Create new Rails API app
0 parents  commit e861080

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+724
-0
lines changed

.gitignore

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
2+
#
3+
# If you find yourself ignoring temporary files generated by your text editor
4+
# or operating system, you probably want to add a global ignore instead:
5+
# git config --global core.excludesfile '~/.gitignore_global'
6+
7+
# Ignore bundler config.
8+
/.bundle
9+
10+
# Ignore the default SQLite database.
11+
/db/*.sqlite3
12+
/db/*.sqlite3-journal
13+
14+
# Ignore all logfiles and tempfiles.
15+
/log/*
16+
/tmp/*
17+
!/log/.keep
18+
!/tmp/.keep
19+
20+
.byebug_history

Gemfile

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
source 'https://rubygems.org'
2+
3+
git_source(:github) do |repo_name|
4+
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
5+
"https://github.com/#{repo_name}.git"
6+
end
7+
8+
9+
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
10+
gem 'rails', '~> 5.1.1'
11+
# Use sqlite3 as the database for Active Record
12+
gem 'sqlite3'
13+
# Use Puma as the app server
14+
gem 'puma', '~> 3.7'
15+
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
16+
# gem 'jbuilder', '~> 2.5'
17+
# Use Redis adapter to run Action Cable in production
18+
# gem 'redis', '~> 3.0'
19+
# Use ActiveModel has_secure_password
20+
# gem 'bcrypt', '~> 3.1.7'
21+
22+
# Use Capistrano for deployment
23+
# gem 'capistrano-rails', group: :development
24+
25+
# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
26+
# gem 'rack-cors'
27+
28+
group :development, :test do
29+
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
30+
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
31+
end
32+
33+
group :development do
34+
gem 'listen', '>= 3.0.5', '< 3.2'
35+
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
36+
gem 'spring'
37+
gem 'spring-watcher-listen', '~> 2.0.0'
38+
end
39+
40+
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
41+
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
42+

README.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# README
2+
3+
This README would normally document whatever steps are necessary to get the
4+
application up and running.
5+
6+
Things you may want to cover:
7+
8+
* Ruby version
9+
10+
* System dependencies
11+
12+
* Configuration
13+
14+
* Database creation
15+
16+
* Database initialization
17+
18+
* How to run the test suite
19+
20+
* Services (job queues, cache servers, search engines, etc.)
21+
22+
* Deployment instructions
23+
24+
* ...

Rakefile

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Add your own tasks in files placed in lib/tasks ending in .rake,
2+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3+
4+
require_relative 'config/application'
5+
6+
Rails.application.load_tasks
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module ApplicationCable
2+
class Channel < ActionCable::Channel::Base
3+
end
4+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module ApplicationCable
2+
class Connection < ActionCable::Connection::Base
3+
end
4+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class ApplicationController < ActionController::API
2+
end

app/controllers/concerns/.keep

Whitespace-only changes.

app/jobs/application_job.rb

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class ApplicationJob < ActiveJob::Base
2+
end

app/mailers/application_mailer.rb

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class ApplicationMailer < ActionMailer::Base
2+
default from: '[email protected]'
3+
layout 'mailer'
4+
end

app/models/application_record.rb

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class ApplicationRecord < ActiveRecord::Base
2+
self.abstract_class = true
3+
end

app/models/concerns/.keep

Whitespace-only changes.

app/views/layouts/mailer.html.erb

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5+
<style>
6+
/* Email styles need to be inline */
7+
</style>
8+
</head>
9+
10+
<body>
11+
<%= yield %>
12+
</body>
13+
</html>

app/views/layouts/mailer.text.erb

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<%= yield %>

bin/bundle

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env ruby
2+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3+
load Gem.bin_path('bundler', 'bundle')

bin/rails

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env ruby
2+
begin
3+
load File.expand_path('../spring', __FILE__)
4+
rescue LoadError => e
5+
raise unless e.message.include?('spring')
6+
end
7+
APP_PATH = File.expand_path('../config/application', __dir__)
8+
require_relative '../config/boot'
9+
require 'rails/commands'

bin/rake

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env ruby
2+
begin
3+
load File.expand_path('../spring', __FILE__)
4+
rescue LoadError => e
5+
raise unless e.message.include?('spring')
6+
end
7+
require_relative '../config/boot'
8+
require 'rake'
9+
Rake.application.run

bin/setup

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env ruby
2+
require 'pathname'
3+
require 'fileutils'
4+
include FileUtils
5+
6+
# path to your application root.
7+
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
8+
9+
def system!(*args)
10+
system(*args) || abort("\n== Command #{args} failed ==")
11+
end
12+
13+
chdir APP_ROOT do
14+
# This script is a starting point to setup your application.
15+
# Add necessary setup steps to this file.
16+
17+
puts '== Installing dependencies =='
18+
system! 'gem install bundler --conservative'
19+
system('bundle check') || system!('bundle install')
20+
21+
22+
# puts "\n== Copying sample files =="
23+
# unless File.exist?('config/database.yml')
24+
# cp 'config/database.yml.sample', 'config/database.yml'
25+
# end
26+
27+
puts "\n== Preparing database =="
28+
system! 'bin/rails db:setup'
29+
30+
puts "\n== Removing old logs and tempfiles =="
31+
system! 'bin/rails log:clear tmp:clear'
32+
33+
puts "\n== Restarting application server =="
34+
system! 'bin/rails restart'
35+
end

bin/spring

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env ruby
2+
3+
# This file loads spring without using Bundler, in order to be fast.
4+
# It gets overwritten when you run the `spring binstub` command.
5+
6+
unless defined?(Spring)
7+
require 'rubygems'
8+
require 'bundler'
9+
10+
lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read)
11+
spring = lockfile.specs.detect { |spec| spec.name == "spring" }
12+
if spring
13+
Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path
14+
gem 'spring', spring.version
15+
require 'spring/binstub'
16+
end
17+
end

bin/update

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env ruby
2+
require 'pathname'
3+
require 'fileutils'
4+
include FileUtils
5+
6+
# path to your application root.
7+
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
8+
9+
def system!(*args)
10+
system(*args) || abort("\n== Command #{args} failed ==")
11+
end
12+
13+
chdir APP_ROOT do
14+
# This script is a way to update your development environment automatically.
15+
# Add necessary update steps to this file.
16+
17+
puts '== Installing dependencies =='
18+
system! 'gem install bundler --conservative'
19+
system('bundle check') || system!('bundle install')
20+
21+
puts "\n== Updating database =="
22+
system! 'bin/rails db:migrate'
23+
24+
puts "\n== Removing old logs and tempfiles =="
25+
system! 'bin/rails log:clear tmp:clear'
26+
27+
puts "\n== Restarting application server =="
28+
system! 'bin/rails restart'
29+
end

config.ru

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# This file is used by Rack-based servers to start the application.
2+
3+
require_relative 'config/environment'
4+
5+
run Rails.application

config/application.rb

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
require_relative 'boot'
2+
3+
require "rails"
4+
# Pick the frameworks you want:
5+
require "active_model/railtie"
6+
require "active_job/railtie"
7+
require "active_record/railtie"
8+
require "action_controller/railtie"
9+
require "action_mailer/railtie"
10+
require "action_view/railtie"
11+
require "action_cable/engine"
12+
# require "sprockets/railtie"
13+
require "rails/test_unit/railtie"
14+
15+
# Require the gems listed in Gemfile, including any gems
16+
# you've limited to :test, :development, or :production.
17+
Bundler.require(*Rails.groups)
18+
19+
module SmtNg
20+
class Application < Rails::Application
21+
# Initialize configuration defaults for originally generated Rails version.
22+
config.load_defaults 5.1
23+
24+
# Settings in config/environments/* take precedence over those specified here.
25+
# Application configuration should go into files in config/initializers
26+
# -- all .rb files in that directory are automatically loaded.
27+
28+
# Only loads a smaller set of middleware suitable for API only apps.
29+
# Middleware like session, flash, cookies can be added back manually.
30+
# Skip views, helpers and assets when generating a new resource.
31+
config.api_only = true
32+
end
33+
end

config/boot.rb

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
2+
3+
require 'bundler/setup' # Set up gems listed in the Gemfile.

config/cable.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
development:
2+
adapter: async
3+
4+
test:
5+
adapter: async
6+
7+
production:
8+
adapter: redis
9+
url: redis://localhost:6379/1
10+
channel_prefix: smt-ng_production

config/database.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# SQLite version 3.x
2+
# gem install sqlite3
3+
#
4+
# Ensure the SQLite 3 gem is defined in your Gemfile
5+
# gem 'sqlite3'
6+
#
7+
default: &default
8+
adapter: sqlite3
9+
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
10+
timeout: 5000
11+
12+
development:
13+
<<: *default
14+
database: db/development.sqlite3
15+
16+
# Warning: The database defined as "test" will be erased and
17+
# re-generated from your development database when you run "rake".
18+
# Do not set this db to the same as development or production.
19+
test:
20+
<<: *default
21+
database: db/test.sqlite3
22+
23+
production:
24+
<<: *default
25+
database: db/production.sqlite3

config/environment.rb

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Load the Rails application.
2+
require_relative 'application'
3+
4+
# Initialize the Rails application.
5+
Rails.application.initialize!

config/environments/development.rb

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
Rails.application.configure do
2+
# Settings specified here will take precedence over those in config/application.rb.
3+
4+
# In the development environment your application's code is reloaded on
5+
# every request. This slows down response time but is perfect for development
6+
# since you don't have to restart the web server when you make code changes.
7+
config.cache_classes = false
8+
9+
# Do not eager load code on boot.
10+
config.eager_load = false
11+
12+
# Show full error reports.
13+
config.consider_all_requests_local = true
14+
15+
# Enable/disable caching. By default caching is disabled.
16+
if Rails.root.join('tmp/caching-dev.txt').exist?
17+
config.action_controller.perform_caching = true
18+
19+
config.cache_store = :memory_store
20+
config.public_file_server.headers = {
21+
'Cache-Control' => "public, max-age=#{2.days.seconds.to_i}"
22+
}
23+
else
24+
config.action_controller.perform_caching = false
25+
26+
config.cache_store = :null_store
27+
end
28+
29+
# Don't care if the mailer can't send.
30+
config.action_mailer.raise_delivery_errors = false
31+
32+
config.action_mailer.perform_caching = false
33+
34+
# Print deprecation notices to the Rails logger.
35+
config.active_support.deprecation = :log
36+
37+
# Raise an error on page load if there are pending migrations.
38+
config.active_record.migration_error = :page_load
39+
40+
41+
# Raises error for missing translations
42+
# config.action_view.raise_on_missing_translations = true
43+
44+
# Use an evented file watcher to asynchronously detect changes in source code,
45+
# routes, locales, etc. This feature depends on the listen gem.
46+
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
47+
end

0 commit comments

Comments
 (0)