Skip to content

Instantly share code, notes, and snippets.

require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'trailblazer-operation'
end
# require "trailblazer-operation"
module Image
module Operation
@apotonick
apotonick / benchmark-merge.rb
Created November 9, 2022 16:21
Benchmarking merging keyword arguments
gem "benchmark-ips"
require 'benchmark/ips'
# This is all about merging {config} or not.
# Never merge. Fastest.
def container_fast(activity, bla: "default")
{
activity: activity,
bla: bla,
@apotonick
apotonick / raw_request_body.rb
Last active February 5, 2022 14:09
Setting the raw body of a POST or PATCH request in ActionDispatch::IntegrationTest (Rails 7)
# If you don't want to use :params because you want to post/patch a "real" document using the request body.
# test file:
patch "/api/v2/diagrams/1", headers: {"RAW_POST_DATA" => '{"my":"json doc"}'}, as: :json
# to read it in a controller action
def update
document = request.body.read
@apotonick
apotonick / Gemfile.rb
Created February 27, 2021 05:18
Test Ruby 3.0 support with TRB
gem "trailblazer-activity", github: "trailblazer/trailblazer-activity", branch: "ruby-3"
gem "trailblazer-activity-dsl-linear", github: "trailblazer/trailblazer-activity-dsl-linear", branch: "ruby-3"
gem "trailblazer-operation", github: "trailblazer/trailblazer-operation", branch: "ruby-3"
gem "trailblazer-macro", github: "trailblazer/trailblazer-macro", branch: "ruby-3"
gem "trailblazer-macro-contract", github: "trailblazer/trailblazer-macro-contract", branch: "ruby-3"
@apotonick
apotonick / gist:b5b40004e698f1ee8f77d8caebba2858
Last active March 7, 2018 15:08
The ever-growing list of bullshit in Rails

Generally speaking, Rails core resists to change its fundamentally flawed architecture. Instead of adding new abstractions, such as form objects, they basically add conditional :if everywhere as a work-around. This document discusses the solutions.

ApplicationRenderer.render

DoubleRenderError

Validation contexts

strong_parameters

@apotonick
apotonick / new.rb
Last active September 15, 2017 13:39
Death of Reform
gem "dry-validation"
require "dry-types"
module Types
include Dry::Types.module
end
require 'dry/logic'
require 'dry/logic/predicates'
@apotonick
apotonick / circuit.rb
Last active June 15, 2017 09:10
Circuit Ruby pre compiler
class KW
def self.call
#
# proc!
# or
# meth!
end
def self.meth!
end
end
{
"color_scheme": "Packages/Color Scheme - Default/IDLE.tmTheme",
"save_on_focus_lost": true,
"trim_trailing_white_space_on_save": true,
"tab_size": 2,
"ensure_newline_at_eof_on_save": true,
}
module PipeOperators
def <(*args)
A.new(self, "<")
end
def |(*args)
A.new(self)
end
@apotonick
apotonick / operation.rb
Last active November 1, 2016 21:45
Auto_inject for TRB2
my_container = Dry::Container.new
my_container.register(:user_repository, -> { Object })
AutoInject = Dry::AutoInject(my_container)
class Create < Trailblazer::Operation
include AutoInject[:user_repository]
end
Create.(params, {})