You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
5.5 KiB

10 months ago
6 months ago
10 months ago
6 months ago
10 months ago
6 months ago
10 months ago
10 months ago
6 months ago
10 months ago
6 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
  1. # ScoresController define Score and Grade interactions
  2. class ScoresController < ApplicationController
  3. include Pagy::Backend
  4. include AnsiColors
  5. before_action :set_score, only: %i[show edit update destroy]
  6. def grayshade(n)
  7. shade = eval("TEXT_GRAY_#{n}")
  8. shade += n.to_s
  9. end
  10. # GET /scores
  11. def index
  12. @pagy, @scores = pagy(Score.all)
  13. # logger.debug 'this is a debug message'
  14. # logger.info 'this is a super long message which should be wrapped. ' * 5
  15. shades = [800, 700, 600, 500, 400, 300, 200, 100].map { |n| grayshade(n) }.join(' ')
  16. logger.info(BG_BLACK + shades)
  17. logger.info(BG_GRAY + shades)
  18. logger.info(BG_WHITE + shades)
  19. logger.info(BG_BLACK + "this is #{BOLD}a message in bold#{CLEAR}, isnt'it?")
  20. logger.info(BG_GRAY + "this is #{BOLD}a message in bold#{CLEAR}, isnt'it?")
  21. logger.info(BG_WHITE + TEXT_GRAY_800 + "this is #{BOLD}a message in bold#{CLEAR}, isnt'it?")
  22. logger.info(BG_WHITE + TEXT_GRAY_600 + "this is #{BOLD}a message in bold#{CLEAR}, isnt'it?")
  23. logger.info(BG_WHITE + TEXT_GRAY_400 + "this is #{BOLD}a message in bold#{CLEAR}, isnt'it?")
  24. logger.info(BG_WHITE + TEXT_GRAY_300 + "this is #{BOLD}a message in bold#{CLEAR}, isnt'it?")
  25. logger.info(BG_WHITE + TEXT_GRAY_200 + "this is #{BOLD}a message in bold#{CLEAR}, isnt'it?")
  26. logger.info(BG_WHITE + TEXT_GRAY_100 + "this is #{BOLD}a message in bold#{CLEAR}, isnt'it?")
  27. # logger.info "these are gray shades : #{TEXT_GRAY_800}800#{TEXT_GRAY_600}600#{TEXT_GRAY_400}400#{TEXT_GRAY_200}200#{TEXT_GRAY_100}100 \x1b[38;5;7m7.0\x1b[38;5;15m15.0\x1b[38;5;232m232 \x1b[38;5;233m233 \x1b[38;5;234m234 \x1b[38;5;235m235 \x1b[38;5;236m236 \x1b[38;5;237m237 \x1b[38;5;238m \x1b[38;5;239m \x1b[38;5;240m \x1b[38;5;241m \x1b[38;5;242m \x1b[38;5;243m
  28. # \x1b[38;5;244m \x1b[38;5;245m245 \x1b[38;5;246m \x1b[38;5;247m \x1b[38;5;248m248 \x1b[38;5;249m \x1b[38;5;250m \x1b[38;5;251m \x1b[38;5;252m \x1b[38;5;253m253 \x1b[38;5;254m \x1b[38;5;255m255"
  29. # logger.info "these are gray shades : #{BG_BLACK}#{TEXT_GRAY_800}800#{TEXT_GRAY_600}600#{TEXT_GRAY_400}400#{TEXT_GRAY_200}200#{TEXT_GRAY_100}100 \x1b[38;5;7m7.0 \x1b[38;5;15m15.0 \x1b[38;5;232m232 \x1b[38;5;233m233 \x1b[38;5;234m234 \x1b[38;5;235m235 \x1b[38;5;236m236 \x1b[38;5;237m237 \x1b[38;5;238m \x1b[38;5;239m239 \x1b[38;5;240m \x1b[38;5;241m \x1b[38;5;242m242 \x1b[38;5;243m
  30. # \x1b[38;5;244m \x1b[38;5;245m245 \x1b[38;5;246m246 \x1b[38;5;247m \x1b[38;5;248m248 \x1b[38;5;249m249 \x1b[38;5;250m \x1b[38;5;251m \x1b[38;5;252m252 \x1b[38;5;253m253 \x1b[38;5;254m \x1b[38;5;255m255 "
  31. # logger.info "these are gray shades : #{BG_WHITE}#{TEXT_GRAY_800}800#{TEXT_GRAY_600}600#{TEXT_GRAY_400}400#{TEXT_GRAY_200}200#{TEXT_GRAY_100}100 \x1b[38;5;7m7.0\x1b[38;5;15m15.0\x1b[38;5;232m232 \x1b[38;5;233m233 \x1b[38;5;234m234 \x1b[38;5;235m235 \x1b[38;5;236m236 \x1b[38;5;237m237 \x1b[38;5;238m \x1b[38;5;239m \x1b[38;5;240m \x1b[38;5;241m \x1b[38;5;242m \x1b[38;5;243m
  32. # \x1b[38;5;244m \x1b[38;5;245m245 \x1b[38;5;246m \x1b[38;5;247m \x1b[38;5;248m248 \x1b[38;5;249m \x1b[38;5;250m \x1b[38;5;251m \x1b[38;5;252m \x1b[38;5;253m253 \x1b[38;5;254m \x1b[38;5;255m255"
  33. # logger.info "these are gray shades : #{BG_BLACK}#{TEXT_GRAY_800}800#{TEXT_GRAY_600}600#{TEXT_GRAY_400}400#{TEXT_GRAY_200}200#{TEXT_GRAY_100}100"
  34. # logger.info "these are gray shades : #{BG_WHITE}#{TEXT_GRAY_800}800#{TEXT_GRAY_600}600#{TEXT_GRAY_400}400#{TEXT_GRAY_200}200#{TEXT_GRAY_100}100"
  35. # logger.info "these are gray shades : #{BOLD}#{TEXT_GRAY_800}800#{TEXT_GRAY_600}600#{TEXT_GRAY_400}400#{TEXT_GRAY_200}200#{TEXT_GRAY_100}100"
  36. # logger.info "these are gray shades : #{BOLD}#{UNDERLINE}#{TEXT_GRAY_800}800#{TEXT_GRAY_600}600#{TEXT_GRAY_400}400#{TEXT_GRAY_200}200#{TEXT_GRAY_100}100"
  37. # logger.info "these are gray shades : #{UNDERLINE}#{TEXT_GRAY_800}800#{TEXT_GRAY_600}600#{TEXT_GRAY_400}400#{TEXT_GRAY_200}200#{TEXT_GRAY_100}100"
  38. # logger.info({ one: 1, two: 2 })
  39. # logger.info 'this is an information', { four: 4, five: 5 }
  40. # logger.debug BigDecimal('0.0003')
  41. # logger.warn 'scores are', @scores
  42. # logger.warn "this is a warning\n yop\n cool"
  43. # logger.error 'this is an error message'
  44. # logger.error "error message line #1\nerror message line #2\nerror message line #3\n\n"
  45. # logger.info 'end of normal message'
  46. # logger.debug @scores
  47. # sleep 0.5
  48. end
  49. # GET /scores/1
  50. def show; end
  51. # GET /scores/new
  52. def new
  53. @score = Score.new
  54. flash.now[:notice] = 'Unique name is mandatory!'
  55. flash.now[:alert] = 'Your book was not found'
  56. sleep 0.3
  57. end
  58. # GET /scores/1/edit
  59. def edit; end
  60. # POST /scores
  61. def create
  62. @score = Score.new(score_params)
  63. if @score.save
  64. redirect_to @score, notice: 'Score was successfully created.'
  65. else
  66. render :new, status: :unprocessable_entity
  67. end
  68. end
  69. # PATCH/PUT /scores/1
  70. def update
  71. if @score.update(score_params)
  72. redirect_to @score, notice: 'Score was successfully updated.', status: :see_other
  73. else
  74. render :edit, status: :unprocessable_entity
  75. end
  76. end
  77. # DELETE /scores/1
  78. def destroy
  79. do_an_exception
  80. @score.destroy!
  81. redirect_to scores_url, notice: 'Score was successfully destroyed.', status: :see_other
  82. end
  83. private
  84. def do_an_exception
  85. raise 'Unable to destroy this score' * 5
  86. end
  87. # Use callbacks to share common setup or constraints between actions.
  88. def set_score
  89. @score = Score.find(params[:id])
  90. @score.grade
  91. end
  92. # Only allow a list of trusted parameters through.
  93. def score_params
  94. params.require(:score).permit(:name, :grade)
  95. end
  96. end