Ruby

Building a Ractor based logger that will work with non-Ractor compatible code

Recently Mike Perham shared a tweet with this comment and a code sample on the Ruby 3.0 Ractors. If this code doesn’t work, how could Rails ever work? Ractor seems fundamentally incompatible with many heavily-used Rails APIs. require ‘logger’ class Rails def self.logger @logger ||= Logger.new(STDOUT) end end Ractor.new do Rails.logger.info “Hello” end.take During the …

Building a Ractor based logger that will work with non-Ractor compatible code Read More »

Karafka framework 1.4.0 Release Notes (Ruby + Kafka)

This release mostly solves problems related to message deserialization and normalizes some of the naming conventions to ease during the upgrade to the upcoming 2.0 version. Note: This release is the last release with ruby-kafka under the hood. We’ve already started the process of moving to rdkafka-ruby. Note: If you are using Sidekiq-Backend plugin, please …

Karafka framework 1.4.0 Release Notes (Ruby + Kafka) Read More »

The hidden cost of the Ruby 2.7 dot-colon method reference usage 1

The hidden cost of the Ruby 2.7 dot-colon method reference usage

Note: This case is valid also for the “old” #method method usage. The reason why I mention that in the “dot-colon” context, is the fact that due to the syntax sugar addition, this style of coding will surely be used more intensely. Note: This feature has been reverted. See details here: bugs.ruby-lang.org/issues/16275. Note: Benchmarks and …

The hidden cost of the Ruby 2.7 dot-colon method reference usage Read More »

NameError: undefined method ‘parse’ for class ‘NilClass’ when doing Time.zone.parse

If you get following error when trying to parse time: Time.zone.parse(‘2019-01-01 11:11:11′) Traceback (most recent call last): 16: from /bundler/friendly_errors.rb:124:in `with_friendly_errors’ 15: from /bundle:30:in `block in ‘ 14: from /bundler/cli.rb:18:in `start’ 13: from /bundler/vendor/thor/lib/thor/base.rb:466:in `start’ 12: from /bundler/cli.rb:27:in `dispatch’ 11: from /bundler/vendor/thor/lib/thor.rb:387:in `dispatch’ 10: from /bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command’ 9: from /bundler/vendor/thor/lib/thor/command.rb:27:in `run’ 8: from /bundler/cli.rb:465:in `exec’ …

NameError: undefined method ‘parse’ for class ‘NilClass’ when doing Time.zone.parse Read More »

Karafka framework 1.3.0 Release Notes (Ruby + Kafka)

Note: These release notes cover only the major changes. To learn about various bug fixes and changes, please refer to the change logs or check out the list of commits in the main Karafka repository on GitHub. TL;DR If you would prefer to see the changes in the code, here’s the upgrade PR from the …

Karafka framework 1.3.0 Release Notes (Ruby + Kafka) Read More »

How to take over a Ruby gem and what to do with it / RubyKaigi 2019 presentation

Using Ruby gems is safe, right? We’re a nice community of friendly beings that act towards the same goal: making Ruby better. But is that true? Can we just blindly use libraries, without making sure, that they are what they are supposed to be? Learn how you can take over a gem, what you can …

How to take over a Ruby gem and what to do with it / RubyKaigi 2019 presentation Read More »

Ruby on Rails HTTP Basic authentication with JSON failure message

A short snippet on how to make Ruby on Rails authenticate_or_request_with_http_basic respond with a JSON valid message upon failure. class ApplicationController < ActionController::API include( ActionController::HttpAuthentication::Basic::ControllerMethods ) before_action :http_authenticate! def http_authenticate! authenticate_or_request_with_http_basic do |key, secret| return if Resource.find_by( key: key, secret: secret ) end render( json: 'Invalid credentials'.to_json, status: 401 ) end end Cover photo by …

Ruby on Rails HTTP Basic authentication with JSON failure message Read More »

Exploring a critical Net::Protocol issue in Ruby 2.6.0p0 and how it can lead to a security problem

TL;DR This bug has been fixed in 2.6.1. Please upgrade and all should be good. If you do any HTTP communication (HTTP requests, Elasticsearch, etc) do not upgrade to 2.6.0p0 or apply the patch below as soon as possible. Ruby is eating up characters when pushed over HTTP Ruby 2.6.0 has been released not long …

Exploring a critical Net::Protocol issue in Ruby 2.6.0p0 and how it can lead to a security problem Read More »

Simplifying internal validations using Dry-Validation

When building APIs for other developers, it’s often important to draw the line between other programmers input data and the internal world of your library. This process is called data validation and you’re probably familiar with this name. What you may not know, is the fact that it can be achieved in many ways. One …

Simplifying internal validations using Dry-Validation Read More »