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
class ApplicationRecord | |
# ... | |
scope :union, ->(*others) { from_unions(self, *others) } | |
def self.from_unions(*relations) | |
subquery = relations.map(&:arel).inject(:union) | |
unscoped.from subquery.as(table_name) | |
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
class ApplicationRecord < ActiveRecord::Base | |
self.abstract_class = true | |
scope :subquery_as, ->(name) { unscoped.from(arel.as(name)) } | |
scope :select_with, ->(*fields) { dup.select_with!(*fields) } | |
scope :select_with!, ->(*fields) { self.select_values |= fields.flatten | [table[Arel.star]]; self } | |
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
-a propshaft | |
--skip-jbuilder | |
--skip-helper | |
--skip-test | |
--template=https://gist.githubusercontent.com/RichOrElse/9fada3065b1e8d1a47b5e16aab482f09/raw/dfb8b7801fdee97037b4ff426e47f3e4af52ef4a/app_template.rb |
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 Runner | |
def initialize(**data) | |
end | |
def run(klass) | |
klass.new.process | |
end | |
def call | |
process |
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
class DelegateTo < BasicObject | |
include ::Kernel | |
def initialize(object) | |
@delegate_to = object | |
end | |
def inspect | |
"#{self.class.inspect}[#{@delegate_to}]" | |
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
img { | |
max-width: 100% | |
height: auto; | |
} |
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
gem 'vcr', '~> 6.0' | |
gem 'webmock', '~> 3.8', '>= 3.8.3' | |
gem 'webdrivers', '~> 4.0' |
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
class ApplicationRecord < ActiveRecord::Base | |
self.abstract_class = true | |
def self.inherited(child_class) | |
super | |
child_class.const_get('ActiveRecord_Relation').include(RelationMethods) | |
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
# turns methods into functions | |
class FunctionFor < Module | |
def initialize(*method_names) | |
@method_names = method_names.each { |named| override named } | |
end | |
def override(named) | |
define_method(named) do |*input, &block| | |
return function_for[named] if input.none? && block.nil? |
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 MigrationReversible | |
def remove_existing_index(table_name, column_names, **options) | |
index_name = options[:name] | |
exists = suppress_messages { index_exists?(table_name, column_names, name: index_name) } | |
reversible do |dir| | |
dir.up { remove_index(table_name, name: index_name) if exists } | |
dir.down do | |
if exists | |
say "existing index #{index_name.inspect} on table #{table_name.inspect}" |
NewerOlder