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 | |
# = Yieldable | |
# | |
# This is meta-mixin, which makes your module, class or it's instance to respond | |
# to method +to_proc+, for example, to easily build instances during iteration: | |
# | |
# ["1", "2", "3"].map(&SomeObject) | |
# | |
# It is 2 different ways to use this module: +extend+ or +prepend+ it to your class. |
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 | |
# A tiny singleton to generate JSON templates. | |
# | |
# === Example: | |
# | |
# template = JSONWildcard["example" => Array.new(5, "%s")] | |
# # => {"example":[%1$s,%2$s,%3$s,%4$s,%5$s]} | |
# | |
# JSONWildcard.format(template, 1, 2, 3, 4, 5) |
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 "dry-initializer" | |
# Simply generates insert statement with optional overridings. | |
# === Usage: | |
# | |
# like = Like.last | |
# # => #<Like:0x00007f8a42b07858> { | |
# # :id => "f93c47dc-9e09-4bf4-bbcb-2ec2000a873f", |
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 | |
# Before (creates prepared statement for each varying size of given array): | |
# | |
# $ Post.where(id: [uuid1, uuid2]) | |
# => Post Load (0.6ms) SELECT "posts".* FROM "posts" WHERE "posts"."id" IN ($1, $2) [["id", "a830f21d-a27b-4bde-8c05-6e5dd088712e"], ["id","531ee026-d60d-4a59-a9a5-d44c44578a98}"]] | |
# | |
# After (the only one statement for varying size of given array): | |
# | |
# $ Post.where(id: [uuid1, uuid2]) |
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 MultikeyMap | |
include Enumerable | |
# Creates multikey map from a dict { value => alias | [aliases...] }, | |
# i.e. both key and values will be mapped to key. | |
# @param dict [Hash] | |
# @raise [TypeError] if input can't be coerced as hash | |
# @return [MultikeyMap] |
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
### Keybase proof | |
I hereby claim: | |
* I am estum on github. | |
* I am estum (https://keybase.io/estum) on keybase. | |
* I have a public key ASCBUSe8TPNeG3_gFmmy3hMi6Azmxilwu-gM4ftWje5ruAo | |
To claim this, I am signing this object: |
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 Shrine | |
protected :_store, :_delete | |
module Plugins | |
# Separate storages per versions | |
# | |
# Usage: | |
# |
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
-- +--------+-------+-------+ | |
-- | init | mod | exp | | |
-- |--------+-------+-------| | |
-- | 6 | -1 | 5 | | |
-- | 5 | 0 | 4 | | |
-- | 4 | 1 | 6 | | |
-- | 3 | 0 | 3 | | |
-- | 2 | -1 | 1 | | |
-- | 1 | 0 | 2 | | |
-- +--------+-------+-------+ |
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 Joint < String | |
_patterns = [[/LATERAL$/, 'ON true'], [/^(?:NATURAL|CROSS)/, '']].deep_freeze! | |
_exception = "expected one non-blank argument of `on' or `using' unless type matches one of: #{_patterns.map(&:first).inspect}" | |
FALLBACK_BOOL_EXP = -> (type) do | |
case type | |
when _patterns[0][0]; _patterns[0][1] | |
when _patterns[1][0]; _patterns[1][1] | |
else raise ArgumentError, _exception |