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
# lib/sidekiq/middleware/server/retry_jobs_without_exception.rb | |
module Sidekiq | |
RetryWithoutException = Class.new(StandardError) | |
module Middleware | |
module Server | |
class RetryJobsWithoutException < RetryJobs | |
def call(worker, msg, queue) | |
begin |
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 SomeModel < ApplicationRecord | |
after_initialize do | |
if new_record? | |
{some_attribute: 'default value'}.each do |attribute, value| | |
public_send("#{attribute}=", value) unless public_send(attribute) | |
end | |
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
# frozen_string_literal: true | |
require "action_dispatch/testing/request_encoder" | |
module ActionDispatch | |
# Integration test methods such as ActionDispatch::Integration::Session#get | |
# and ActionDispatch::Integration::Session#post return objects of class | |
# TestResponse, which represent the HTTP response results of the requested | |
# controller actions. | |
# |
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 BaseAuditsController < ApplicationController | |
def self.inherited(other) | |
other.class_eval do | |
resource_name = controller_path.split('/').first.singularize | |
define_method("set_#{resource_name}") do | |
resource = organization.public_send(resource_name.pluralize).find(params["#{resource_name}_id"]) | |
instance_variable_set("@#{resource_name}", resource) | |
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
Listen.to('app/controllers') do |modified, added, removed| | |
puts "modified absolute path: #{modified}" | |
puts "added absolute path: #{added}" | |
puts "removed absolute path: #{removed}" | |
end.start |
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
'foo' + 42 # => TypeError: no implicit conversion of Integer into String | |
class Integer | |
def to_str | |
to_s | |
end | |
end | |
'foo' + 42 # => 'foo42' |
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 A | |
def self.foo | |
end | |
end | |
class B < A | |
end | |
mock_a = MiniTest::Mock.new | |
mock_b = MiniTest::Mock.new |
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 Foo < ApplicationRecord | |
def array | |
self[:array] ? LimitedArray.new(self[:array]) : self[:array] | |
end | |
def array=(value) | |
self[:array] = value ? LimitedArray.new(value.dup).to_a : value | |
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
json.sessions do | |
@session_groups.each_value do |sessions| | |
sessions.each do |session| | |
json.child! { json.call(session, :id) } | |
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
class NotStartingWithRailsConstraint | |
def matches?(request) | |
!request.path.starts_with?('/rails') | |
end | |
end |