module ApplicationCable
class Connection < ActionCable::Connection::Base
identified_by :current_user
def connect
self.current_user = find_verified_user
class Problem
DEFAULT_TYPE = "https://api.example.com/problems/about:blank".freeze
attr_reader :type, :title, :status, :detail, :instance, :extensions
def initialize(status:, title:, detail: nil, type: nil, instance: nil, extensions: {})
require "loofah"
class HtmlSanitizer
ALLOWED_TAGS = %w[p br a strong em ul ol li blockquote code pre h2 h3].freeze
ALLOWED_ATTRS = %w[href title].freeze
SAFE_SCHEMES = %w[http https mailto].freeze
class DiscountCode < ApplicationRecord
has_many :redemptions, dependent: :destroy
enum discount_type: { percentage: 0, fixed: 1 }
validates :code, presence: true, uniqueness: { case_sensitive: false }
class ExternalApiClient
def fetch_user_data(user_id)
ActiveSupport::Notifications.instrument(
'api.external_service',
service: 'user_service',
operation: 'fetch_user',
class ActivityPanelController < ApplicationController
def show
@project = Project.find(params[:project_id])
@events = @project.events.order(created_at: :desc).limit(50)
latest = @events.maximum(:updated_at)
class UserNotificationJob < ApplicationJob
queue_as :default
# Retry up to 5 times with exponential backoff
retry_on StandardError, wait: :exponentially_longer, attempts: 5
class DashboardWidget < ApplicationRecord
broadcasts_refreshes
end
module Webhooks
class StripeController < ApplicationController
skip_before_action :verify_authenticity_token
def create
payload = request.body.read
module Retryable
module_function
def with_retries(tries: 3, base: 0.3, cap: 5.0, on: [StandardError])
attempt = 0
begin
production:
primary:
adapter: postgresql
database: app_production
username: app
password: <%= ENV["PRIMARY_DB_PASSWORD"] %>
class ProjectPresenter
def initialize(project, include_tasks: true)
@project = project
@include_tasks = include_tasks
end