mirror of
https://github.com/iritmaximus/brewery.git
synced 2026-10-12 19:13:49 +03:00
upto 3.2
This commit is contained in:
@@ -0,0 +1,153 @@
|
||||
# Relaxed.Ruby.Style
|
||||
## Version 2.5
|
||||
|
||||
Style/Alias:
|
||||
Enabled: false
|
||||
StyleGuide: https://relaxed.ruby.style/#stylealias
|
||||
|
||||
Style/AsciiComments:
|
||||
Enabled: false
|
||||
StyleGuide: https://relaxed.ruby.style/#styleasciicomments
|
||||
|
||||
Style/BeginBlock:
|
||||
Enabled: false
|
||||
StyleGuide: https://relaxed.ruby.style/#stylebeginblock
|
||||
|
||||
Style/BlockDelimiters:
|
||||
Enabled: false
|
||||
StyleGuide: https://relaxed.ruby.style/#styleblockdelimiters
|
||||
|
||||
Style/CommentAnnotation:
|
||||
Enabled: false
|
||||
StyleGuide: https://relaxed.ruby.style/#stylecommentannotation
|
||||
|
||||
Style/Documentation:
|
||||
Enabled: false
|
||||
StyleGuide: https://relaxed.ruby.style/#styledocumentation
|
||||
|
||||
Layout/DotPosition:
|
||||
Enabled: false
|
||||
StyleGuide: https://relaxed.ruby.style/#layoutdotposition
|
||||
|
||||
Style/DoubleNegation:
|
||||
Enabled: false
|
||||
StyleGuide: https://relaxed.ruby.style/#styledoublenegation
|
||||
|
||||
Style/EndBlock:
|
||||
Enabled: false
|
||||
StyleGuide: https://relaxed.ruby.style/#styleendblock
|
||||
|
||||
Style/FormatString:
|
||||
Enabled: false
|
||||
StyleGuide: https://relaxed.ruby.style/#styleformatstring
|
||||
|
||||
Style/IfUnlessModifier:
|
||||
Enabled: false
|
||||
StyleGuide: https://relaxed.ruby.style/#styleifunlessmodifier
|
||||
|
||||
Style/Lambda:
|
||||
Enabled: false
|
||||
StyleGuide: https://relaxed.ruby.style/#stylelambda
|
||||
|
||||
Style/ModuleFunction:
|
||||
Enabled: false
|
||||
StyleGuide: https://relaxed.ruby.style/#stylemodulefunction
|
||||
|
||||
Style/MultilineBlockChain:
|
||||
Enabled: false
|
||||
StyleGuide: https://relaxed.ruby.style/#stylemultilineblockchain
|
||||
|
||||
Style/NegatedIf:
|
||||
Enabled: false
|
||||
StyleGuide: https://relaxed.ruby.style/#stylenegatedif
|
||||
|
||||
Style/NegatedWhile:
|
||||
Enabled: false
|
||||
StyleGuide: https://relaxed.ruby.style/#stylenegatedwhile
|
||||
|
||||
Style/NumericPredicate:
|
||||
Enabled: false
|
||||
StyleGuide: https://relaxed.ruby.style/#stylenumericpredicate
|
||||
|
||||
Style/ParallelAssignment:
|
||||
Enabled: false
|
||||
StyleGuide: https://relaxed.ruby.style/#styleparallelassignment
|
||||
|
||||
Style/PercentLiteralDelimiters:
|
||||
Enabled: false
|
||||
StyleGuide: https://relaxed.ruby.style/#stylepercentliteraldelimiters
|
||||
|
||||
Style/PerlBackrefs:
|
||||
Enabled: false
|
||||
StyleGuide: https://relaxed.ruby.style/#styleperlbackrefs
|
||||
|
||||
Style/Semicolon:
|
||||
Enabled: false
|
||||
StyleGuide: https://relaxed.ruby.style/#stylesemicolon
|
||||
|
||||
Style/SignalException:
|
||||
Enabled: false
|
||||
StyleGuide: https://relaxed.ruby.style/#stylesignalexception
|
||||
|
||||
Style/SingleLineBlockParams:
|
||||
Enabled: false
|
||||
StyleGuide: https://relaxed.ruby.style/#stylesinglelineblockparams
|
||||
|
||||
Style/SingleLineMethods:
|
||||
Enabled: false
|
||||
StyleGuide: https://relaxed.ruby.style/#stylesinglelinemethods
|
||||
|
||||
Layout/SpaceBeforeBlockBraces:
|
||||
Enabled: false
|
||||
StyleGuide: https://relaxed.ruby.style/#layoutspacebeforeblockbraces
|
||||
|
||||
Layout/SpaceInsideParens:
|
||||
Enabled: false
|
||||
StyleGuide: https://relaxed.ruby.style/#layoutspaceinsideparens
|
||||
|
||||
Style/SpecialGlobalVars:
|
||||
Enabled: false
|
||||
StyleGuide: https://relaxed.ruby.style/#stylespecialglobalvars
|
||||
|
||||
Style/StringLiterals:
|
||||
Enabled: false
|
||||
StyleGuide: https://relaxed.ruby.style/#stylestringliterals
|
||||
|
||||
Style/TrailingCommaInArguments:
|
||||
Enabled: false
|
||||
StyleGuide: https://relaxed.ruby.style/#styletrailingcommainarguments
|
||||
|
||||
Style/TrailingCommaInArrayLiteral:
|
||||
Enabled: false
|
||||
StyleGuide: https://relaxed.ruby.style/#styletrailingcommainarrayliteral
|
||||
|
||||
Style/TrailingCommaInHashLiteral:
|
||||
Enabled: false
|
||||
StyleGuide: https://relaxed.ruby.style/#styletrailingcommainhashliteral
|
||||
|
||||
Style/SymbolArray:
|
||||
Enabled: false
|
||||
StyleGuide: http://relaxed.ruby.style/#stylesymbolarray
|
||||
|
||||
Style/WhileUntilModifier:
|
||||
Enabled: false
|
||||
StyleGuide: https://relaxed.ruby.style/#stylewhileuntilmodifier
|
||||
|
||||
Style/WordArray:
|
||||
Enabled: false
|
||||
StyleGuide: https://relaxed.ruby.style/#stylewordarray
|
||||
|
||||
Lint/AmbiguousRegexpLiteral:
|
||||
Enabled: false
|
||||
StyleGuide: https://relaxed.ruby.style/#lintambiguousregexpliteral
|
||||
|
||||
Lint/AssignmentInCondition:
|
||||
Enabled: false
|
||||
StyleGuide: https://relaxed.ruby.style/#lintassignmentincondition
|
||||
|
||||
Layout/LineLength:
|
||||
Enabled: false
|
||||
|
||||
Metrics:
|
||||
Enabled: false
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
inherit_from:
|
||||
- https://relaxed.ruby.style/rubocop.yml
|
||||
|
||||
AllCops:
|
||||
Exclude:
|
||||
- __test/**
|
||||
- test/**
|
||||
- test/channels/application_cable/** # for whatever reason this directory was not excluded even though two previous exclusion lines
|
||||
- bin/**
|
||||
- spec/**/*
|
||||
- config/**/*
|
||||
- db/**/*
|
||||
- Gemfile
|
||||
- "*.gemspec"
|
||||
- bundler/**/*
|
||||
- vendor/bundle/**/* # travis with --deployment
|
||||
TargetRubyVersion: 3.1.2
|
||||
NewCops: enable
|
||||
|
||||
Style/PercentLiteralDelimiters:
|
||||
PreferredDelimiters:
|
||||
default: ()
|
||||
'%i': '()'
|
||||
'%I': '()'
|
||||
'%r': '{}'
|
||||
'%w': '()'
|
||||
'%W': '()'
|
||||
|
||||
Style/FormatString:
|
||||
EnforcedStyle: percent
|
||||
|
||||
Style/FrozenStringLiteralComment:
|
||||
Enabled: false
|
||||
|
||||
Style/WordArray:
|
||||
Enabled: true
|
||||
MinSize: 3
|
||||
|
||||
Style/EmptyMethod:
|
||||
Enabled: false
|
||||
|
||||
Style/SymbolArray:
|
||||
Enabled: false
|
||||
|
||||
Gemspec/OrderedDependencies:
|
||||
Enabled: false
|
||||
|
||||
Style/PerlBackrefs:
|
||||
Enabled: true
|
||||
|
||||
Layout/SpaceInsideParens:
|
||||
Enabled: true
|
||||
|
||||
Style/SpecialGlobalVars:
|
||||
Enabled: true
|
||||
|
||||
Style/Alias:
|
||||
Enabled: true
|
||||
|
||||
Style/BeginBlock:
|
||||
Enabled: true
|
||||
|
||||
Style/OpenStructUse:
|
||||
Enabled: false
|
||||
|
||||
Naming/MethodParameterName:
|
||||
AllowedNames:
|
||||
- cn
|
||||
|
||||
Metrics/BlockLength:
|
||||
Enabled: false
|
||||
|
||||
Metrics/MethodLength:
|
||||
Enabled: true
|
||||
Max: 15
|
||||
@@ -1,5 +1,5 @@
|
||||
class BeersController < ApplicationController
|
||||
before_action :set_beer, only: %i[ show edit update destroy ]
|
||||
before_action :set_beer, only: %i[show edit update destroy]
|
||||
|
||||
# GET /beers or /beers.json
|
||||
def index
|
||||
@@ -62,13 +62,14 @@ class BeersController < ApplicationController
|
||||
end
|
||||
|
||||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_beer
|
||||
@beer = Beer.find(params[:id])
|
||||
end
|
||||
|
||||
# Only allow a list of trusted parameters through.
|
||||
def beer_params
|
||||
params.require(:beer).permit(:name, :style, :brewery_id)
|
||||
end
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_beer
|
||||
@beer = Beer.find(params[:id])
|
||||
end
|
||||
|
||||
# Only allow a list of trusted parameters through.
|
||||
def beer_params
|
||||
params.require(:beer).permit(:name, :style, :brewery_id)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class BreweriesController < ApplicationController
|
||||
before_action :set_brewery, only: %i[ show edit update destroy ]
|
||||
before_action :set_brewery, only: %i[show edit update destroy]
|
||||
before_action :authenticate, only: [:destroy]
|
||||
|
||||
# GET /breweries or /breweries.json
|
||||
@@ -59,21 +59,23 @@ class BreweriesController < ApplicationController
|
||||
end
|
||||
|
||||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_brewery
|
||||
@brewery = Brewery.find(params[:id])
|
||||
end
|
||||
|
||||
# Only allow a list of trusted parameters through.
|
||||
def brewery_params
|
||||
params.require(:brewery).permit(:name, :year)
|
||||
end
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_brewery
|
||||
@brewery = Brewery.find(params[:id])
|
||||
end
|
||||
|
||||
def authenticate
|
||||
admin_accounts = {"martti" => "anaatti", "moi"=> "hei"}
|
||||
authenticate_or_request_with_http_basic do |username, password|
|
||||
raise "Wrong username or password" unless admin_accounts.key? username and admin_accounts[username] == password
|
||||
return true
|
||||
end
|
||||
# Only allow a list of trusted parameters through.
|
||||
def brewery_params
|
||||
params.require(:brewery).permit(:name, :year)
|
||||
end
|
||||
|
||||
def authenticate
|
||||
admin_accounts = { "martti" => "anaatti", "moi" => "hei" }
|
||||
authenticate_or_request_with_http_basic do |username, password|
|
||||
raise "Wrong username or password" unless admin_accounts.key?(username) && admin_accounts[username] == password
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
+1
-1
@@ -5,6 +5,6 @@ class Beer < ApplicationRecord
|
||||
has_many :ratings, dependent: :destroy
|
||||
|
||||
def to_s
|
||||
"#{self.name}, #{(Brewery.find_by_id self.brewery_id).name}"
|
||||
"#{name}, #{(Brewery.find_by_id brewery_id).name}"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -12,6 +12,6 @@ class Brewery < ApplicationRecord
|
||||
|
||||
def restart
|
||||
self.year = 2023
|
||||
puts "changed year to #{2023}"
|
||||
puts "changed year to 2023"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,11 +5,11 @@ module RatingAverage
|
||||
total_score = 0
|
||||
count = 0
|
||||
|
||||
if defined? self.beers
|
||||
beers = self.beers
|
||||
else
|
||||
beers = self
|
||||
end
|
||||
beers = if defined? self.beers
|
||||
self.beers
|
||||
else
|
||||
self
|
||||
end
|
||||
|
||||
beers.each do |beer|
|
||||
count += beer.ratings.count
|
||||
@@ -18,24 +18,22 @@ module RatingAverage
|
||||
end
|
||||
end
|
||||
|
||||
if count == 0
|
||||
return 0
|
||||
end
|
||||
return 0 unless count != 0
|
||||
|
||||
return total_score / count
|
||||
total_score / count
|
||||
end
|
||||
|
||||
def count_ratings
|
||||
if defined? self.beers
|
||||
beers = self.beers
|
||||
else
|
||||
beers = self
|
||||
end
|
||||
beers = if defined? self.beers
|
||||
self.beers
|
||||
else
|
||||
self
|
||||
end
|
||||
|
||||
count = 0
|
||||
beers.each do |beer|
|
||||
count += beer.ratings.count
|
||||
end
|
||||
return count
|
||||
count
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user