Skip to content

Commit

Permalink
rubocop string freeze
Browse files Browse the repository at this point in the history
  • Loading branch information
jupcan committed May 17, 2021
1 parent 70290d6 commit ef98710
Show file tree
Hide file tree
Showing 66 changed files with 164 additions and 40 deletions.
2 changes: 2 additions & 0 deletions Gemfile
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

Expand Down
2 changes: 2 additions & 0 deletions Rakefile
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# 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.

Expand Down
2 changes: 2 additions & 0 deletions app/channels/application_cable/channel.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ApplicationCable
class Channel < ActionCable::Channel::Base
end
Expand Down
2 changes: 2 additions & 0 deletions app/channels/application_cable/connection.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ApplicationCable
class Connection < ActionCable::Connection::Base
end
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/application_controller.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class ApplicationController < ActionController::API
rescue_from ActiveRecord::RecordInvalid, with: :render_unprocessable_entity_response
rescue_from ActiveRecord::RecordNotFound, with: :render_not_found_response
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/categories_controller.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class CategoriesController < ApplicationController
# GET /categories
def index
Expand All @@ -16,7 +18,7 @@ def category_products_mean
@categories.each do |category|
category_interests = category.products.map(&:interests).flatten.map(&:score)
unless category_interests.empty?
average_score = category_interests.sum.to_f / category_interests.count.to_f
average_score = category_interests.sum.to_f / category_interests.count
category.update(score: average_score.round(2))
end
end
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/interests_controller.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class InterestsController < ApplicationController
# POST /interests
def create
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/products_controller.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class ProductsController < ApplicationController
# GET /products
def index
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/users_controller.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class UsersController < ApplicationController
# POST /users
def create
Expand Down
2 changes: 2 additions & 0 deletions app/jobs/application_job.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class ApplicationJob < ActiveJob::Base
# Automatically retry jobs that encountered a deadlock
# retry_on ActiveRecord::Deadlocked
Expand Down
2 changes: 2 additions & 0 deletions app/mailers/application_mailer.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class ApplicationMailer < ActionMailer::Base
default from: 'from@example.com'
layout 'mailer'
Expand Down
2 changes: 2 additions & 0 deletions app/models/application_record.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true

Expand Down
2 changes: 2 additions & 0 deletions app/models/category.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class Category < ApplicationRecord
include OrderScoreConcern
has_many :products
Expand Down
2 changes: 2 additions & 0 deletions app/models/concerns/order_score_concern.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module OrderScoreConcern
extend ActiveSupport::Concern

Expand Down
2 changes: 2 additions & 0 deletions app/models/interest.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class Interest < ApplicationRecord
belongs_to :user
belongs_to :product
Expand Down
2 changes: 2 additions & 0 deletions app/models/product.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class Product < ApplicationRecord
include OrderScoreConcern
after_initialize :generate_uuid
Expand Down
2 changes: 2 additions & 0 deletions app/models/user.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class User < ApplicationRecord
after_initialize :generate_uuid
has_many :interests
Expand Down
2 changes: 2 additions & 0 deletions app/serializers/category_serializer.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class CategorySerializer < ActiveModel::Serializer
attributes :category, :score
end
2 changes: 2 additions & 0 deletions app/serializers/interest_serializer.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class InterestSerializer < ActiveModel::Serializer
attributes :user_id, :product_id, :score
end
2 changes: 2 additions & 0 deletions app/serializers/product_serializer.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class ProductSerializer < ActiveModel::Serializer
attributes :id, :name, :category

Expand Down
2 changes: 2 additions & 0 deletions app/serializers/score_product_serializer.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class ScoreProductSerializer < ActiveModel::Serializer
attributes :product, :score

Expand Down
2 changes: 2 additions & 0 deletions app/serializers/user_serializer.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class UserSerializer < ActiveModel::Serializer
attributes :id, :name, :email
end
2 changes: 1 addition & 1 deletion bin/bundle
Expand Up @@ -14,7 +14,7 @@ m = Module.new do
module_function

def invoked_as_script?
File.expand_path($0) == File.expand_path(__FILE__)
File.expand_path($PROGRAM_NAME) == File.expand_path(__FILE__)
end

def env_var_version
Expand Down
2 changes: 2 additions & 0 deletions bin/rails
@@ -1,4 +1,6 @@
#!/usr/bin/env ruby.exe
# frozen_string_literal: true

APP_PATH = File.expand_path('../config/application', __dir__)
require_relative '../config/boot'
require 'rails/commands'
2 changes: 2 additions & 0 deletions bin/rake
@@ -1,4 +1,6 @@
#!/usr/bin/env ruby.exe
# frozen_string_literal: true

require_relative '../config/boot'
require 'rake'
Rake.application.run
2 changes: 2 additions & 0 deletions bin/setup
@@ -1,4 +1,6 @@
#!/usr/bin/env ruby.exe
# frozen_string_literal: true

require 'fileutils'

# path to your application root.
Expand Down
2 changes: 2 additions & 0 deletions config.ru
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# This file is used by Rack-based servers to start the application.

require_relative 'config/environment'
Expand Down
2 changes: 2 additions & 0 deletions config/application.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative 'boot'

require 'rails'
Expand Down
2 changes: 2 additions & 0 deletions config/boot.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)

require 'bundler/setup' # Set up gems listed in the Gemfile.
Expand Down
2 changes: 2 additions & 0 deletions config/environment.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Load the Rails application.
require_relative 'application'

Expand Down
2 changes: 2 additions & 0 deletions config/environments/development.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'active_support/core_ext/integer/time'

Rails.application.configure do
Expand Down
4 changes: 3 additions & 1 deletion config/environments/production.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'active_support/core_ext/integer/time'

Rails.application.configure do
Expand Down Expand Up @@ -82,7 +84,7 @@
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')

if ENV['RAILS_LOG_TO_STDOUT'].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger = ActiveSupport::Logger.new($stdout)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
Expand Down
2 changes: 2 additions & 0 deletions config/environments/test.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'active_support/core_ext/integer/time'

# The test environment is used exclusively to run your application's
Expand Down
1 change: 1 addition & 0 deletions config/initializers/application_controller_renderer.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
# Be sure to restart your server when you modify this file.

# ActiveSupport::Reloader.to_prepare do
Expand Down
2 changes: 2 additions & 0 deletions config/initializers/backtrace_silencers.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# 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.
Expand Down
1 change: 1 addition & 0 deletions config/initializers/cors.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
# Be sure to restart your server when you modify this file.

# Avoid CORS issues when API is called from the frontend app.
Expand Down
2 changes: 2 additions & 0 deletions config/initializers/filter_parameter_logging.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Be sure to restart your server when you modify this file.

# Configure sensitive parameters which will be filtered from the log file.
Expand Down
1 change: 1 addition & 0 deletions config/initializers/inflections.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
# Be sure to restart your server when you modify this file.

# Add new inflection rules using the following format. Inflections
Expand Down
1 change: 1 addition & 0 deletions config/initializers/mime_types.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
# Be sure to restart your server when you modify this file.

# Add new mime types for use in respond_to blocks:
Expand Down
2 changes: 2 additions & 0 deletions config/initializers/rswag-ui.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

Rswag::Ui.configure do |c|
# List the Swagger endpoints that you want to be documented through the swagger-ui
# The first parameter is the path (absolute or relative to the UI host) to the corresponding
Expand Down
4 changes: 3 additions & 1 deletion config/initializers/rswag_api.rb
@@ -1,9 +1,11 @@
# frozen_string_literal: true

Rswag::Api.configure do |c|
# Specify a root folder where Swagger JSON files are located
# This is used by the Swagger middleware to serve requests for API descriptions
# NOTE: If you're using rswag-specs to generate Swagger, you'll need to ensure
# that it's configured to generate files in the same folder
c.swagger_root = Rails.root.to_s + '/swagger'
c.swagger_root = "#{Rails.root}/swagger"

# Inject a lamda function to alter the returned Swagger prior to serialization
# The function will have access to the rack env for the current request
Expand Down
2 changes: 2 additions & 0 deletions config/initializers/wrap_parameters.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Be sure to restart your server when you modify this file.

# This file contains settings for ActionController::ParamsWrapper which
Expand Down
10 changes: 6 additions & 4 deletions config/puma.rb
@@ -1,10 +1,12 @@
# frozen_string_literal: true

# 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.
#
max_threads_count = ENV.fetch('RAILS_MAX_THREADS') { 5 }
max_threads_count = ENV.fetch('RAILS_MAX_THREADS', 5)
min_threads_count = ENV.fetch('RAILS_MIN_THREADS') { max_threads_count }
threads min_threads_count, max_threads_count

Expand All @@ -15,14 +17,14 @@

# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
#
port ENV.fetch('PORT') { 3000 }
port ENV.fetch('PORT', 3000)

# Specifies the `environment` that Puma will run in.
#
environment ENV.fetch('RAILS_ENV') { 'development' }
environment ENV.fetch('RAILS_ENV', 'development')

# Specifies the `pidfile` that Puma will use.
pidfile ENV.fetch('PIDFILE') { 'tmp/pids/server.pid' }
pidfile ENV.fetch('PIDFILE', 'tmp/pids/server.pid')

# Specifies the number of `workers` to boot in clustered mode.
# Workers are forked web server processes. If using threads and workers together
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

Rails.application.routes.draw do
mount Rswag::Ui::Engine => '/'
mount Rswag::Api::Engine => '/api-docs'
Expand Down
2 changes: 2 additions & 0 deletions db/migrate/20210511011258_create_categories.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class CreateCategories < ActiveRecord::Migration[6.1]
def change
create_table :categories do |t|
Expand Down
2 changes: 2 additions & 0 deletions db/migrate/20210511011503_create_products.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class CreateProducts < ActiveRecord::Migration[6.1]
def change
create_table :products, id: false do |t|
Expand Down
2 changes: 2 additions & 0 deletions db/migrate/20210511143408_create_users.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class CreateUsers < ActiveRecord::Migration[6.1]
def change
create_table :users, id: false do |t|
Expand Down
2 changes: 2 additions & 0 deletions db/migrate/20210511144143_create_interests.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class CreateInterests < ActiveRecord::Migration[6.1]
def change
create_table :interests do |t|
Expand Down
2 changes: 2 additions & 0 deletions db/migrate/20210512135343_add_score_to_products.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class AddScoreToProducts < ActiveRecord::Migration[6.1]
def change
add_column :products, :score, :float
Expand Down
2 changes: 2 additions & 0 deletions db/migrate/20210516230744_change_score_type_in_interests.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class ChangeScoreTypeInInterests < ActiveRecord::Migration[6.1]
def change
change_column :interests, :score, :float
Expand Down
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class AddScoreDefaultValueInCategories < ActiveRecord::Migration[6.1]
def change
change_column_default :categories, :score, 0.0
Expand Down
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class AddScoreDefaultValueInProducts < ActiveRecord::Migration[6.1]
def change
change_column_default :products, :score, 0.0
Expand Down

0 comments on commit ef98710

Please sign in to comment.