This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The idea here is to make all the methods below accessible through the module | |
# itself and through the classes including the module, but having the methods | |
# publicly available both as instance and as class methods. | |
module A | |
def self.abc = 123 | |
def self.xyz = 456 | |
def self.append_features(klass) | |
methods_being_added = singleton_methods - [:append_features] | |
delegation_setter = ->(mod, methods) { delegate *methods, to: mod } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Graphql | |
class Utils | |
CONTEXT_CLASS = GraphQL::Query::Context | |
FIELD_CLASS = GraphQL::Language::Nodes::Field | |
FRAGMENT_CLASS = GraphQL::Language::Nodes::FragmentSpread | |
# Given a GraphQL context (literally, the +context+ method from inside any GraphQL field | |
# method), this method will return all the fields requested in the operation request. | |
# So, considering the following query example: | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
module Importer | |
module Preloadable | |
extend ActiveSupport::Concern | |
included do | |
delegate :preloader_settings, to: :class | |
delegate :preloaded_records_manager, to: :import_service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module StringUtils | |
CONTAINS_HTML_TAG_REGEX = /<[a-z][a-z0-9-]*?[^>]*?>/im | |
SELF_CLOSING_TAGS = %w[br hr img wbr].freeze | |
SPACE_REGEX = /^(?:\R|\s)$/m | |
module_function | |
# This method aims to convert HTML based strings into human friendly plain | |
# text strings, where paragraphs represented by <p> tag wrapped text chunks | |
# are replaced by their contents succeeded by two line break characters |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
class ApplicationController < ActionController::Base | |
helper_method :is_happy? | |
private | |
def is_happy? = true | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module RakeableMigrations | |
class Base < ActiveRecord::Migration[6.1] | |
class << self | |
def migration_version = @migration_version | |
def set_migration_version(version) = @migration_version = version.to_s | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ============================================================================== | |
# On development's rails console (BSD based OS - MacOS): | |
# ------------------------------------------------------------------------------ | |
a = %Q|SELECT * FROM json_to_recordset('[{"a":1,"b":"foo"},{"a":"2","b":"bar"},{"a":"3","b":"FOO"},{"a":"4","b":"BOring"}]') AS x(a INT, b TEXT) ORDER BY b;| | |
ActiveRecord::Base.connection.execute(a).to_a | |
# [ | |
# [0] { | |
# "a" => 4, | |
# "b" => "BOring" | |
# }, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app/models/branch_action_node.rb:class BranchActionNode < ActionNode | |
app/models/built_custom_document.rb:class BuiltCustomDocument < CustomDocument | |
app/models/call_rail_call.rb:class CallRailCall < Call | |
app/models/custom_booking.rb:class CustomBooking < CustomForm | |
app/models/custom_booking_action_node.rb:class CustomBookingActionNode < CustomFormActionNode | |
app/models/custom_document_separator_block.rb:class CustomDocumentSeparatorBlock < CustomDocumentBlock | |
app/models/custom_field/client.rb:class CustomField::Client < CustomField | |
app/models/email.rb:class Email < ContactInformation | |
app/models/event_automation.rb:class EventAutomation < Automation | |
app/models/event_automation_target.rb:class EventAutomationTarget < AutomationList |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sentry_extensions/toggler' | |
require 'sentry_extensions/configuration' | |
Sentry.init do |config| | |
config.dsn = ENV['SENTRY_API_KEY'] | |
config.excluded_exceptions = config.excluded_exceptions - ['ActiveRecord::RecordNotFound'] | |
# This allows us to skip an error to be sent to Sentry, which is useful for | |
# when we're already manually sending the error to Sentry and then re-raising | |
# the error. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Kernel | |
def log2(*args) | |
$log_counter ||= 1 | |
options = args.size > 1 && Hash === args.last ? args.pop : {} | |
stack_lines = options[:stack_lines] || 1 | |
call_lines = caller(1, stack_lines) | |
stack_line_stripper = lambda do |line| | |
stack_line = line[/^.+\/gems\/(.+)$/, 1] | |
stack_line || line.delete_prefix("#{Rails.root}/") |
NewerOlder