Add Rails5 sample

This commit is contained in:
Newell Zhu 2016-05-15 00:19:51 +08:00
parent d0dcec85cc
commit 83b5c2eeec
62 changed files with 1248 additions and 0 deletions

View File

@ -0,0 +1,36 @@
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '>= 5.0.0.racecar1', '< 5.1'
# Use mysql as the database for Active Record
gem 'mysql2', '>= 0.3.18', '< 0.5'
# Use Puma as the app server
gem 'puma', '~> 3.0'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
# gem 'rack-cors'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platform: :mri
end
group :development do
gem 'listen', '~> 3.0.5'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

View File

@ -0,0 +1,141 @@
GEM
remote: https://rubygems.org/
specs:
actioncable (5.0.0.rc1)
actionpack (= 5.0.0.rc1)
nio4r (~> 1.2)
websocket-driver (~> 0.6.1)
actionmailer (5.0.0.rc1)
actionpack (= 5.0.0.rc1)
actionview (= 5.0.0.rc1)
activejob (= 5.0.0.rc1)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 1.0, >= 1.0.5)
actionpack (5.0.0.rc1)
actionview (= 5.0.0.rc1)
activesupport (= 5.0.0.rc1)
rack (~> 2.x)
rack-test (~> 0.6.3)
rails-dom-testing (~> 1.0, >= 1.0.5)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (5.0.0.rc1)
activesupport (= 5.0.0.rc1)
builder (~> 3.1)
erubis (~> 2.7.0)
rails-dom-testing (~> 1.0, >= 1.0.5)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
activejob (5.0.0.rc1)
activesupport (= 5.0.0.rc1)
globalid (>= 0.3.6)
activemodel (5.0.0.rc1)
activesupport (= 5.0.0.rc1)
activerecord (5.0.0.rc1)
activemodel (= 5.0.0.rc1)
activesupport (= 5.0.0.rc1)
arel (~> 7.0)
activesupport (5.0.0.rc1)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (~> 0.7)
minitest (~> 5.1)
tzinfo (~> 1.1)
arel (7.0.0)
builder (3.2.2)
byebug (9.0.0)
concurrent-ruby (1.0.2)
erubis (2.7.0)
ffi (1.9.10)
globalid (0.3.6)
activesupport (>= 4.1.0)
i18n (0.7.0)
jbuilder (2.4.1)
activesupport (>= 3.0.0, < 5.1)
multi_json (~> 1.2)
json (1.8.3)
listen (3.0.7)
rb-fsevent (>= 0.9.3)
rb-inotify (>= 0.9.7)
loofah (2.0.3)
nokogiri (>= 1.5.9)
mail (2.6.4)
mime-types (>= 1.16, < 4)
method_source (0.8.2)
mime-types (3.0)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0221)
mini_portile2 (2.0.0)
minitest (5.8.4)
multi_json (1.12.0)
mysql2 (0.4.4)
nio4r (1.2.1)
nokogiri (1.6.7.2)
mini_portile2 (~> 2.0.0.rc2)
puma (3.4.0)
rack (2.0.0.rc1)
json
rack-test (0.6.3)
rack (>= 1.0)
rails (5.0.0.rc1)
actioncable (= 5.0.0.rc1)
actionmailer (= 5.0.0.rc1)
actionpack (= 5.0.0.rc1)
actionview (= 5.0.0.rc1)
activejob (= 5.0.0.rc1)
activemodel (= 5.0.0.rc1)
activerecord (= 5.0.0.rc1)
activesupport (= 5.0.0.rc1)
bundler (>= 1.3.0, < 2.0)
railties (= 5.0.0.rc1)
sprockets-rails (>= 2.0.0)
rails-deprecated_sanitizer (1.0.3)
activesupport (>= 4.2.0.alpha)
rails-dom-testing (1.0.7)
activesupport (>= 4.2.0.beta, < 5.0)
nokogiri (~> 1.6.0)
rails-deprecated_sanitizer (>= 1.0.1)
rails-html-sanitizer (1.0.3)
loofah (~> 2.0)
railties (5.0.0.rc1)
actionpack (= 5.0.0.rc1)
activesupport (= 5.0.0.rc1)
method_source
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (11.1.2)
rb-fsevent (0.9.7)
rb-inotify (0.9.7)
ffi (>= 0.5.0)
spring (1.7.1)
spring-watcher-listen (2.0.0)
listen (>= 2.7, < 4.0)
spring (~> 1.2)
sprockets (3.6.0)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.0.4)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
thor (0.19.1)
thread_safe (0.3.5)
tzinfo (1.2.2)
thread_safe (~> 0.1)
websocket-driver (0.6.3)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.2)
PLATFORMS
ruby
DEPENDENCIES
byebug
jbuilder (~> 2.0)
listen (~> 3.0.5)
mysql2 (>= 0.3.18, < 0.5)
puma (~> 3.0)
rails (>= 5.0.0.racecar1, < 5.1)
spring
spring-watcher-listen (~> 2.0.0)
tzinfo-data
BUNDLED WITH
1.11.2

View File

@ -0,0 +1,25 @@
# Swagger for Rails 5
This is a project to provide Swagger support inside the [Sinatra](http://rubyonrails.org/) framework.
## Prerequisites
You need to install ruby >= 2.2.2 and run:
```
bundle install
```
## Getting started
This sample was generated with the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project.
```
bin/rake db:create
bin/rails s
```
To list all your routes, use:
```
bin/rake routes
```

View File

@ -0,0 +1,6 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require_relative 'config/application'
Rails.application.load_tasks

View File

@ -0,0 +1,5 @@
# Be sure to restart your server when you modify this file. Action Cable runs in a loop that does not support auto reloading.
module ApplicationCable
class Channel < ActionCable::Channel::Base
end
end

View File

@ -0,0 +1,5 @@
# Be sure to restart your server when you modify this file. Action Cable runs in a loop that does not support auto reloading.
module ApplicationCable
class Connection < ActionCable::Connection::Base
end
end

View File

@ -0,0 +1,2 @@
class ApplicationController < ActionController::API
end

View File

@ -0,0 +1,50 @@
class PetController < ApplicationController
def create
# Your code here
render json: {"message" => "yes, it worked"}
end
def destroy
# Your code here
render json: {"message" => "yes, it worked"}
end
def find_pets_by_status
# Your code here
render json: {"message" => "yes, it worked"}
end
def find_pets_by_tags
# Your code here
render json: {"message" => "yes, it worked"}
end
def show
# Your code here
render json: {"message" => "yes, it worked"}
end
def update_pet
# Your code here
render json: {"message" => "yes, it worked"}
end
def update_pet_with_form
# Your code here
render json: {"message" => "yes, it worked"}
end
def upload_file
# Your code here
render json: {"message" => "yes, it worked"}
end
end

View File

@ -0,0 +1,26 @@
class StoreController < ApplicationController
def delete_order
# Your code here
render json: {"message" => "yes, it worked"}
end
def get_inventory
# Your code here
render json: {"message" => "yes, it worked"}
end
def get_order_by_id
# Your code here
render json: {"message" => "yes, it worked"}
end
def place_order
# Your code here
render json: {"message" => "yes, it worked"}
end
end

View File

@ -0,0 +1,50 @@
class UserController < ApplicationController
def create
# Your code here
render json: {"message" => "yes, it worked"}
end
def create_users_with_array_input
# Your code here
render json: {"message" => "yes, it worked"}
end
def create_users_with_list_input
# Your code here
render json: {"message" => "yes, it worked"}
end
def destroy
# Your code here
render json: {"message" => "yes, it worked"}
end
def show
# Your code here
render json: {"message" => "yes, it worked"}
end
def login_user
# Your code here
render json: {"message" => "yes, it worked"}
end
def logout_user
# Your code here
render json: {"message" => "yes, it worked"}
end
def update
# Your code here
render json: {"message" => "yes, it worked"}
end
end

View File

@ -0,0 +1,2 @@
class ApplicationJob < ActiveJob::Base
end

View File

@ -0,0 +1,4 @@
class ApplicationMailer < ActionMailer::Base
default from: 'from@example.com'
layout 'mailer'
end

View File

@ -0,0 +1,3 @@
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end

View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
/* Email styles need to be inline */
</style>
</head>
<body>
<%= yield %>
</body>
</html>

View File

@ -0,0 +1 @@
<%= yield %>

View File

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

View File

@ -0,0 +1,4 @@
#!/usr/bin/env ruby
APP_PATH = File.expand_path('../config/application', __dir__)
require_relative '../config/boot'
require 'rails/commands'

View File

@ -0,0 +1,4 @@
#!/usr/bin/env ruby
require_relative '../config/boot'
require 'rake'
Rake.application.run

View File

@ -0,0 +1,34 @@
#!/usr/bin/env ruby
require 'pathname'
require 'fileutils'
include FileUtils
# path to your application root.
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==")
end
chdir APP_ROOT do
# This script is a starting point to setup your application.
# Add necessary setup steps to this file.
puts '== Installing dependencies =='
system! 'gem install bundler --conservative'
system('bundle check') || system!('bundle install')
# puts "\n== Copying sample files =="
# unless File.exist?('config/database.yml')
# cp 'config/database.yml.sample', 'config/database.yml'
# end
puts "\n== Preparing database =="
system! 'bin/rails db:setup'
puts "\n== Removing old logs and tempfiles =="
system! 'bin/rails log:clear tmp:clear'
puts "\n== Restarting application server =="
system! 'bin/rails restart'
end

View File

@ -0,0 +1,29 @@
#!/usr/bin/env ruby
require 'pathname'
require 'fileutils'
include FileUtils
# path to your application root.
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==")
end
chdir APP_ROOT do
# This script is a way to update your development environment automatically.
# Add necessary update steps to this file.
puts '== Installing dependencies =='
system! 'gem install bundler --conservative'
system('bundle check') || system!('bundle install')
puts "\n== Updating database =="
system! 'bin/rails db:migrate'
puts "\n== Removing old logs and tempfiles =="
system! 'bin/rails log:clear tmp:clear'
puts "\n== Restarting application server =="
system! 'bin/rails restart'
end

View File

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

View File

@ -0,0 +1,30 @@
require_relative 'boot'
require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "action_cable/engine"
# require "sprockets/railtie"
require "rails/test_unit/railtie"
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module ApiDemo
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Only loads a smaller set of middleware suitable for API only apps.
# Middleware like session, flash, cookies can be added back manually.
# Skip views, helpers and assets when generating a new resource.
config.api_only = true
end
end

View File

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

View File

@ -0,0 +1,10 @@
# Action Cable uses Redis by default to administer connections, channels, and sending/receiving messages over the WebSocket.
production:
adapter: redis
url: redis://localhost:6379/1
development:
adapter: async
test:
adapter: async

View File

@ -0,0 +1,47 @@
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports.
config.consider_all_requests_local = true
# Enable/disable caching. By default caching is disabled.
if Rails.root.join('tmp/caching-dev.txt').exist?
config.action_controller.perform_caching = true
config.cache_store = :memory_store
config.public_file_server.headers = {
'Cache-Control' => 'public, max-age=172800'
}
else
config.action_controller.perform_caching = false
config.cache_store = :null_store
end
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
config.action_mailer.perform_caching = false
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
# Use an evented file watcher to asynchronously detect changes in source code,
# routes, locales, etc. This feature depends on the listen gem.
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
end

View File

@ -0,0 +1,80 @@
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.cache_classes = true
# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both threaded web servers
# and those relying on copy on write to perform better.
# Rake tasks automatically ignore this option for performance.
config.eager_load = true
# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Disable serving static files from the `/public` folder by default since
# Apache or NGINX already handles this.
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.action_controller.asset_host = 'http://assets.example.com'
# Specifies the header that your server uses for sending files.
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
# Action Cable endpoint configuration
# config.action_cable.url = 'wss://example.com/cable'
# config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]
# Don't mount Action Cable in the main server process.
# config.action_cable.mount_path = nil
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true
# Use the lowest log level to ensure availability of diagnostic information
# when problems arise.
config.log_level = :debug
# Prepend all log lines with the following tags.
config.log_tags = [ :request_id ]
# Use a different cache store in production.
# config.cache_store = :mem_cache_store
# Use a real queuing backend for Active Job (and separate queues per environment)
# config.active_job.queue_adapter = :resque
# config.active_job.queue_name_prefix = "api_demo_#{Rails.env}"
config.action_mailer.perform_caching = false
# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation cannot be found).
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify
# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new
# Use a different logger for distributed setups.
# require 'syslog/logger'
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
if ENV["RAILS_LOG_TO_STDOUT"].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
end

View File

@ -0,0 +1,54 @@
# MySQL. Versions 5.0 and up are supported.
#
# Install the MySQL driver
# gem install mysql2
#
# Ensure the MySQL gem is defined in your Gemfile
# gem 'mysql2'
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.7/en/old-client.html
#
default: &default
adapter: mysql2
encoding: utf8
pool: 5
username: root
password:
socket: /tmp/mysql.sock
development:
<<: *default
database: api_demo_development
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: api_demo_test
# As with config/secrets.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is
# ever seen by anyone, they now have access to your database.
#
# Instead, provide the password as a unix environment variable when you boot
# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
# for a full rundown on how to provide these environment variables in a
# production deployment.
#
# On Heroku and other platform providers, you may have a full connection URL
# available as an environment variable. For example:
#
# DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase"
#
# You can use this database configuration with:
#
# production:
# url: <%= ENV['DATABASE_URL'] %>
#
production:
<<: *default
database: api_demo_production
username: api_demo
password: <%= ENV['API_DEMO_DATABASE_PASSWORD'] %>

View File

@ -0,0 +1,5 @@
# Load the Rails application.
require_relative 'application'
# Initialize the Rails application.
Rails.application.initialize!

View File

@ -0,0 +1,6 @@
# Be sure to restart your server when you modify this file.
# Require `belongs_to` associations by default. This is a new Rails 5.0
# default, so it is introduced as a configuration option to ensure that apps
# made on earlier versions of Rails are not affected when upgrading.
Rails.application.config.active_record.belongs_to_required_by_default = true

View File

@ -0,0 +1,6 @@
# Be sure to restart your server when you modify this file.
# ApplicationController.renderer.defaults.merge!(
# http_host: 'example.org',
# https: false
# )

View File

@ -0,0 +1,7 @@
# Be sure to restart your server when you modify this file.
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
# Rails.backtrace_cleaner.remove_silencers!

View File

@ -0,0 +1,6 @@
# Be sure to restart your server when you modify this file.
# Do not halt callback chains when a callback returns false. This is a new
# Rails 5.0 default, so it is introduced as a configuration option to ensure
# that apps made with earlier versions of Rails are not affected when upgrading.
ActiveSupport.halt_callback_chains_on_return_false = false

View File

@ -0,0 +1,16 @@
# Be sure to restart your server when you modify this file.
# Avoid CORS issues when API is called from the frontend app.
# Handle Cross-Origin Resource Sharing (CORS) in order to accept cross-origin AJAX requests.
# Read more: https://github.com/cyu/rack-cors
# Rails.application.config.middleware.insert_before 0, Rack::Cors do
# allow do
# origins 'example.com'
#
# resource '*',
# headers: :any,
# methods: [:get, :post, :put, :patch, :delete, :options, :head]
# end
# end

View File

@ -0,0 +1,4 @@
# Be sure to restart your server when you modify this file.
# Configure sensitive parameters which will be filtered from the log file.
Rails.application.config.filter_parameters += [:password]

View File

@ -0,0 +1,16 @@
# Be sure to restart your server when you modify this file.
# Add new inflection rules using the following format. Inflections
# are locale specific, and you may define rules for as many different
# locales as you wish. All of these examples are active by default:
# ActiveSupport::Inflector.inflections(:en) do |inflect|
# inflect.plural /^(ox)$/i, '\1en'
# inflect.singular /^(ox)en/i, '\1'
# inflect.irregular 'person', 'people'
# inflect.uncountable %w( fish sheep )
# end
# These inflection rules are supported but not enabled by default:
# ActiveSupport::Inflector.inflections(:en) do |inflect|
# inflect.acronym 'RESTful'
# end

View File

@ -0,0 +1,4 @@
# Be sure to restart your server when you modify this file.
# Add new mime types for use in respond_to blocks:
# Mime::Type.register "text/richtext", :rtf

View File

@ -0,0 +1,4 @@
# Be sure to restart your server when you modify this file.
# Configure SSL options to enable HSTS with subdomains.
Rails.application.config.ssl_options = { hsts: { subdomains: true } }

View File

@ -0,0 +1,10 @@
# Be sure to restart your server when you modify this file.
# Preserve the timezone of the receiver when calling to `to_time`.
# Ruby 2.4 will change the behavior of `to_time` to preserve the timezone
# when converting to an instance of `Time` instead of the previous behavior
# of converting to the local system timezone.
#
# Rails 5.0 introduced this config option so that apps made with earlier
# versions of Rails are not affected when upgrading.
ActiveSupport.to_time_preserves_timezone = true

View File

@ -0,0 +1,23 @@
# Files in the config/locales directory are used for internationalization
# and are automatically loaded by Rails. If you want to use locales other
# than English, add the necessary files in this directory.
#
# To use the locales, use `I18n.t`:
#
# I18n.t 'hello'
#
# In views, this is aliased to just `t`:
#
# <%= t('hello') %>
#
# To use a different locale, set it with `I18n.locale`:
#
# I18n.locale = :es
#
# This would use the information in config/locales/es.yml.
#
# To learn more, please read the Rails Internationalization guide
# available at http://guides.rubyonrails.org/i18n.html.
en:
hello: "Hello world"

View File

@ -0,0 +1,47 @@
# Puma can serve each request in a thread from an internal thread pool.
# The `threads` method setting takes two numbers a minimum and maximum.
# Any libraries that use thread pools should be configured to match
# the maximum value specified for Puma. Default is set to 5 threads for minimum
# and maximum, this matches the default thread size of Active Record.
#
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i
threads threads_count, threads_count
# Specifies the `port` that Puma will listen on to receive requests, default is 3000.
#
port ENV.fetch("PORT") { 3000 }
# Specifies the `environment` that Puma will run in.
#
environment ENV.fetch("RAILS_ENV") { "development" }
# Specifies the number of `workers` to boot in clustered mode.
# Workers are forked webserver processes. If using threads and workers together
# the concurrency of the application would be max `threads` * `workers`.
# Workers do not work on JRuby or Windows (both of which do not support
# processes).
#
# workers ENV.fetch("WEB_CONCURRENCY") { 2 }
# Use the `preload_app!` method when specifying a `workers` number.
# This directive tells Puma to first boot the application and load code
# before forking the application. This takes advantage of Copy On Write
# process behavior so workers use less memory. If you use this option
# you need to make sure to reconnect any threads in the `on_worker_boot`
# block.
#
# preload_app!
# The code in the `on_worker_boot` will be called if you are using
# clustered mode by specifying a number of `workers`. After each worker
# process is booted this block will be run, if you are using `preload_app!`
# option you will want to use this block to reconnect to any threads
# or connections that may have been created at application boot, Ruby
# cannot share connections between processes.
#
# on_worker_boot do
# ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
# end
# Allow puma to be restarted by `rails restart` command.
plugin :tmp_restart

View File

@ -0,0 +1,156 @@
Rails.application.routes.draw do
def add_swagger_route http_method, path, opts = {}
full_path = path.gsub(/{(.*?)}/, ':\1')
action =
(opts[:isRestfulIndex] && :index) ||
(opts[:isRestfulShow] && :show) ||
(opts[:isRestfulCreate] && :create) ||
(opts[:isRestfulUpdate] && :update) ||
(opts[:isRestfulDestroy] && :destroy) ||
opts[:nickname]
match full_path, to: "#{opts.fetch(:classVarName)}##{action}", via: http_method
end
add_swagger_route 'POST', '/v2/pet',
classVarName: 'pet', nickname: 'add_pet',
isRestfulIndex: false,
isRestfulCreate: true,
isRestfulUpdate: false,
isRestfulShow: false,
isRestfulDestroy: false
add_swagger_route 'DELETE', '/v2/pet/{petId}',
classVarName: 'pet', nickname: 'delete_pet',
isRestfulIndex: false,
isRestfulCreate: false,
isRestfulUpdate: false,
isRestfulShow: false,
isRestfulDestroy: true
add_swagger_route 'GET', '/v2/pet/findByStatus',
classVarName: 'pet', nickname: 'find_pets_by_status',
isRestfulIndex: false,
isRestfulCreate: false,
isRestfulUpdate: false,
isRestfulShow: false,
isRestfulDestroy: false
add_swagger_route 'GET', '/v2/pet/findByTags',
classVarName: 'pet', nickname: 'find_pets_by_tags',
isRestfulIndex: false,
isRestfulCreate: false,
isRestfulUpdate: false,
isRestfulShow: false,
isRestfulDestroy: false
add_swagger_route 'GET', '/v2/pet/{petId}',
classVarName: 'pet', nickname: 'get_pet_by_id',
isRestfulIndex: false,
isRestfulCreate: false,
isRestfulUpdate: false,
isRestfulShow: true,
isRestfulDestroy: false
add_swagger_route 'PUT', '/v2/pet',
classVarName: 'pet', nickname: 'update_pet',
isRestfulIndex: false,
isRestfulCreate: false,
isRestfulUpdate: false,
isRestfulShow: false,
isRestfulDestroy: false
add_swagger_route 'POST', '/v2/pet/{petId}',
classVarName: 'pet', nickname: 'update_pet_with_form',
isRestfulIndex: false,
isRestfulCreate: false,
isRestfulUpdate: false,
isRestfulShow: false,
isRestfulDestroy: false
add_swagger_route 'POST', '/v2/pet/{petId}/uploadImage',
classVarName: 'pet', nickname: 'upload_file',
isRestfulIndex: false,
isRestfulCreate: false,
isRestfulUpdate: false,
isRestfulShow: false,
isRestfulDestroy: false
add_swagger_route 'DELETE', '/v2/store/order/{orderId}',
classVarName: 'store', nickname: 'delete_order',
isRestfulIndex: false,
isRestfulCreate: false,
isRestfulUpdate: false,
isRestfulShow: false,
isRestfulDestroy: false
add_swagger_route 'GET', '/v2/store/inventory',
classVarName: 'store', nickname: 'get_inventory',
isRestfulIndex: false,
isRestfulCreate: false,
isRestfulUpdate: false,
isRestfulShow: false,
isRestfulDestroy: false
add_swagger_route 'GET', '/v2/store/order/{orderId}',
classVarName: 'store', nickname: 'get_order_by_id',
isRestfulIndex: false,
isRestfulCreate: false,
isRestfulUpdate: false,
isRestfulShow: false,
isRestfulDestroy: false
add_swagger_route 'POST', '/v2/store/order',
classVarName: 'store', nickname: 'place_order',
isRestfulIndex: false,
isRestfulCreate: false,
isRestfulUpdate: false,
isRestfulShow: false,
isRestfulDestroy: false
add_swagger_route 'POST', '/v2/user',
classVarName: 'user', nickname: 'create_user',
isRestfulIndex: false,
isRestfulCreate: true,
isRestfulUpdate: false,
isRestfulShow: false,
isRestfulDestroy: false
add_swagger_route 'POST', '/v2/user/createWithArray',
classVarName: 'user', nickname: 'create_users_with_array_input',
isRestfulIndex: false,
isRestfulCreate: false,
isRestfulUpdate: false,
isRestfulShow: false,
isRestfulDestroy: false
add_swagger_route 'POST', '/v2/user/createWithList',
classVarName: 'user', nickname: 'create_users_with_list_input',
isRestfulIndex: false,
isRestfulCreate: false,
isRestfulUpdate: false,
isRestfulShow: false,
isRestfulDestroy: false
add_swagger_route 'DELETE', '/v2/user/{username}',
classVarName: 'user', nickname: 'delete_user',
isRestfulIndex: false,
isRestfulCreate: false,
isRestfulUpdate: false,
isRestfulShow: false,
isRestfulDestroy: true
add_swagger_route 'GET', '/v2/user/{username}',
classVarName: 'user', nickname: 'get_user_by_name',
isRestfulIndex: false,
isRestfulCreate: false,
isRestfulUpdate: false,
isRestfulShow: true,
isRestfulDestroy: false
add_swagger_route 'GET', '/v2/user/login',
classVarName: 'user', nickname: 'login_user',
isRestfulIndex: false,
isRestfulCreate: false,
isRestfulUpdate: false,
isRestfulShow: false,
isRestfulDestroy: false
add_swagger_route 'GET', '/v2/user/logout',
classVarName: 'user', nickname: 'logout_user',
isRestfulIndex: false,
isRestfulCreate: false,
isRestfulUpdate: false,
isRestfulShow: false,
isRestfulDestroy: false
add_swagger_route 'PUT', '/v2/user/{username}',
classVarName: 'user', nickname: 'update_user',
isRestfulIndex: false,
isRestfulCreate: false,
isRestfulUpdate: true,
isRestfulShow: false,
isRestfulDestroy: false
end

View File

@ -0,0 +1,22 @@
# Be sure to restart your server when you modify this file.
# Your secret key is used for verifying the integrity of signed cookies.
# If you change this key, all old signed cookies will become invalid!
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
# You can use `rails secret` to generate a secure secret key.
# Make sure the secrets in this file are kept private
# if you're sharing your code publicly.
development:
secret_key_base: 2e13a003477a557ba3fcc6260c2ec69e411238b9b8b530c3c70e71f7cfc905b5f746f5c195a0282342a77ad6acd4e6ef8949106723200a99414fe83393d67344
test:
secret_key_base: fedf54236a94882c00e2fa0af308a4135f50941396437b9fbc38dd340c0a8bcf38cfcf6264cc2abc2af5bda26252293fe48e9a3e90fbfc4d25d6886d6d14b300
# Do not keep production secrets in the repository,
# instead read values from the environment.
production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>

View File

@ -0,0 +1,6 @@
%w(
.ruby-version
.rbenv-vars
tmp/restart.txt
tmp/caching-dev.txt
).each { |path| Spring.watch(path) }

View File

@ -0,0 +1,16 @@
# encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 0) do
end

View File

@ -0,0 +1,7 @@
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
#
# Examples:
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Character.create(name: 'Luke', movie: movies.first)

View File

View File

@ -0,0 +1,67 @@
<!DOCTYPE html>
<html>
<head>
<title>The page you were looking for doesn't exist (404)</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<style>
body {
background-color: #EFEFEF;
color: #2E2F30;
text-align: center;
font-family: arial, sans-serif;
margin: 0;
}
div.dialog {
width: 95%;
max-width: 33em;
margin: 4em auto 0;
}
div.dialog > div {
border: 1px solid #CCC;
border-right-color: #999;
border-left-color: #999;
border-bottom-color: #BBB;
border-top: #B00100 solid 4px;
border-top-left-radius: 9px;
border-top-right-radius: 9px;
background-color: white;
padding: 7px 12% 0;
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
}
h1 {
font-size: 100%;
color: #730E15;
line-height: 1.5em;
}
div.dialog > p {
margin: 0 0 1em;
padding: 1em;
background-color: #F7F7F7;
border: 1px solid #CCC;
border-right-color: #999;
border-left-color: #999;
border-bottom-color: #999;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
border-top-color: #DADADA;
color: #666;
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
}
</style>
</head>
<body>
<!-- This file lives in public/404.html -->
<div class="dialog">
<div>
<h1>The page you were looking for doesn't exist.</h1>
<p>You may have mistyped the address or the page may have moved.</p>
</div>
<p>If you are the application owner check the logs for more information.</p>
</div>
</body>
</html>

View File

@ -0,0 +1,67 @@
<!DOCTYPE html>
<html>
<head>
<title>The change you wanted was rejected (422)</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<style>
body {
background-color: #EFEFEF;
color: #2E2F30;
text-align: center;
font-family: arial, sans-serif;
margin: 0;
}
div.dialog {
width: 95%;
max-width: 33em;
margin: 4em auto 0;
}
div.dialog > div {
border: 1px solid #CCC;
border-right-color: #999;
border-left-color: #999;
border-bottom-color: #BBB;
border-top: #B00100 solid 4px;
border-top-left-radius: 9px;
border-top-right-radius: 9px;
background-color: white;
padding: 7px 12% 0;
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
}
h1 {
font-size: 100%;
color: #730E15;
line-height: 1.5em;
}
div.dialog > p {
margin: 0 0 1em;
padding: 1em;
background-color: #F7F7F7;
border: 1px solid #CCC;
border-right-color: #999;
border-left-color: #999;
border-bottom-color: #999;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
border-top-color: #DADADA;
color: #666;
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
}
</style>
</head>
<body>
<!-- This file lives in public/422.html -->
<div class="dialog">
<div>
<h1>The change you wanted was rejected.</h1>
<p>Maybe you tried to change something you didn't have access to.</p>
</div>
<p>If you are the application owner check the logs for more information.</p>
</div>
</body>
</html>

View File

@ -0,0 +1,66 @@
<!DOCTYPE html>
<html>
<head>
<title>We're sorry, but something went wrong (500)</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<style>
body {
background-color: #EFEFEF;
color: #2E2F30;
text-align: center;
font-family: arial, sans-serif;
margin: 0;
}
div.dialog {
width: 95%;
max-width: 33em;
margin: 4em auto 0;
}
div.dialog > div {
border: 1px solid #CCC;
border-right-color: #999;
border-left-color: #999;
border-bottom-color: #BBB;
border-top: #B00100 solid 4px;
border-top-left-radius: 9px;
border-top-right-radius: 9px;
background-color: white;
padding: 7px 12% 0;
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
}
h1 {
font-size: 100%;
color: #730E15;
line-height: 1.5em;
}
div.dialog > p {
margin: 0 0 1em;
padding: 1em;
background-color: #F7F7F7;
border: 1px solid #CCC;
border-right-color: #999;
border-left-color: #999;
border-bottom-color: #999;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
border-top-color: #DADADA;
color: #666;
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
}
</style>
</head>
<body>
<!-- This file lives in public/500.html -->
<div class="dialog">
<div>
<h1>We're sorry, but something went wrong.</h1>
</div>
<p>If you are the application owner check the logs for more information.</p>
</div>
</body>
</html>

View File

@ -0,0 +1,5 @@
# See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
#
# To ban all spiders from the entire site uncomment the next two lines:
# User-agent: *
# Disallow: /

View File

@ -0,0 +1,10 @@
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
fixtures :all
# Add more helper methods to be used by all tests here...
end

View File

View File