Skip to content

Instantly share code, notes, and snippets.

View palkan's full-sized avatar

Vladimir Dementyev palkan

View GitHub Profile
@palkan
palkan / patch.rb
Created February 28, 2019 23:49
rspec-rails vs. Rails 6.0.0.beta2
# frozen_string_literal: true
# PR: https://github.com/rspec/rspec-rails/pull/2095
RSpec::Rails::ViewRendering::EmptyTemplateHandler.singleton_class.prepend(Module.new do
def call(template, _source)
super(template)
end
end)
@palkan
palkan / slim_faker.rb
Created February 19, 2019 17:21
Slim Faker
# frozen_string_literal: true
# Faker load tons of useless locales by default
# (see https://github.com/stympy/faker/tree/master/lib/locales)
#
# And it's impossible to configure it(
# (see https://github.com/stympy/faker/blob/v1.9.3/lib/faker.rb#L14-L15)
#
# First, ensure i18n is loaded
@palkan
palkan / anycable_0.6.0.md
Last active November 21, 2018 23:00
AnyCable 0.6.0 releases
@palkan
palkan / doc.md
Created August 17, 2018 22:22
[draft] Pundit to Action Policy

From Pundit to ActionPolicy:

  • Remove include Pundit from ApplicationController
  • Add alias authorize authorize!
  • Add authorize :current_user, as: :user
  • Add include ActionPolicy::Policy::Core to ApplicationPolicy
  • Update ApplicationPolicy#initialize:
def initialize(target, user:)
@palkan
palkan / action_policy__i18n.rb
Last active November 2, 2018 16:22
ActionPolicy i18n basics
# See issue: https://github.com/palkan/action_policy/issues/15
module ActionPolicy
module I18n
class << self
def full_message(policy_class, rule)
# generate candidates
candidates = [:"#{policy_class.identifier}.#{rule}"]
# add global fallbacks
@palkan
palkan / 01_rack_rewrite_config.rb
Created November 7, 2017 09:19
RackRewriteConfig
class RackRewriteConfig
class << self
# Configure named rewrite rule
def configure(name, &block)
raise ArgumentError, "Block is required" unless block_given?
rules[name] = block
end
# Apply named rule to the target
def apply(target, name, *args)
@palkan
palkan / keybase.md
Created July 4, 2017 13:04
keybase.md

Keybase proof

I hereby claim:

  • I am palkan on github.
  • I am palkan (https://keybase.io/palkan) on keybase.
  • I have a public key ASD9_7Qr5xvMYx75u8VApLRsuCjYGR87WquHVLTtuUahwAo

To claim this, I am signing this object:

@palkan
palkan / 01_readme.md
Last active January 15, 2024 10:32
Docker Dev
@palkan
palkan / sti_update.rb
Last active June 1, 2017 10:18
STI update
module StiUpdate
def as(type)
if self.type == type
self
else
klass = type.camelize.constantize
if klass.nil?
self
else
became = self.becomes!(klass)
@palkan
palkan / any_fixture.rb
Created March 28, 2017 21:49
AnyFixture: make DB fixtures from blocks
module AnyFixture
INSERT_RXP = /^INSERT INTO ([\S]+)/
class Cache
attr_reader :store
delegate :clear, to: :store
def initialize
@store = {}