class Customer < ApplicationRecord
encrypts :phone_number
encrypts :external_token, deterministic: true
end
class Collection < ApplicationRecord
has_many :memberships
def self.visible_to(member)
collections = arel_table
memberships = Membership.arel_table
class UserRegistrationService
class Result
attr_reader :user, :errors
def initialize(success:, user: nil, errors: [])
@success = success
class ViewCounter
def bump(snip_id)
Redis.current.incr("snip:views:#{snip_id}")
end
end
class ReindexCheckpoint < ApplicationRecord
validates :name, presence: true, uniqueness: true
end
class Inventory::Reserve
class NotEnoughStock < StandardError; end
def initialize(sku:, quantity:)
@sku = sku
@quantity = Integer(quantity)
module ApiErrorHandler
extend ActiveSupport::Concern
included do
rescue_from StandardError, with: :handle_standard_error
rescue_from ActiveRecord::RecordNotFound, with: :handle_not_found
module Api
module V1
class PostsController < BaseController
def index
# Eager load author and recent comments with their authors
posts = Post.published
module ReadYourWrites
TTL = 10
def pin_primary!
session[:pin_primary_until] = Time.current.to_i + TTL
end
class NormalizeHeadlines
def call
Member.select(:id, :headline).find_each do |m|
normalized = m.headline.to_s.strip.gsub(/ +/, ' ')
next if normalized == m.headline
# Define refinements in a module
module StringExtensions
refine String do
def titleize
split.map(&:capitalize).join(' ')
end
module TagNormalization
extend ActiveSupport::Concern
included do
before_validation :normalize_tag_list
end