Rails is not ruby

I had written earlier how learning the language before the framework is more important. It is important to know which parts is part of the language, and which comes from the framework. This becomes more important when there are defacto web frameworks (rails in ruby, django in python, phoenix in elixir.. maybe more) For a newcomer who is learning both the language and framework together (or back to back, or worse learning the language via the framework tutorials :shudders: )

Continue Reading »

Pass request specific context to Sidekiq

In a multi-tenant rails application, usually we extract the tenant, before we process it further. Sometimes, the process requires us to process the data in background (via Sidekiq) and because the background job also needs to query the DB, it also needs to set tenant. Turns out, we can pass “some” data from the controller to the sidekiq job via ActiveSupport::CurrentAttributes While, sidekiq may need to set the tenant again (for more DB queries) but one can save at least one query (to find out the account itself)

Continue Reading »

→ Bullet train: Rails based framework

I came across this from (now defunct) rails app site. They seem to provide a lot of stuff in their open source version.

Seems like a good framework to get started on the side project or MVP

Other paid features are worth paying when your app starts making money.

I need to spend more time on digging deeper, and actually trying it out.

Rails Runner

Some days ago, I came across a requirement where I needed to run some rails code at the end of deployment. We use the Capistrano tool for the deployment, and it has great support for hooks like after 'deploy:published', 'some_task' Most of the examples show some system commands, since Capistrano is a deployment tool, and isn’t running rails. But I didn’t know that, being new to rails ecosystem. So at first, at just called a background job that needed to talk to third party system and get some data, once the rails server is up.

Continue Reading »

Bang Methods in Ruby (and Rails)

Today I learned about Bang methods in Ruby. Methods ending with ! are potentially dangerous, because they update the object they operate on. ➜ irb --sample-book-mode >> name = "sample_string" => "sample_string" >> name.reverse => "gnirts_elpmas" >> name => "sample_string" >> name.reverse! => "gnirts_elpmas" >> name => "gnirts_elpmas" As we can see above, reverse! modified name itself. Most times (?) we don’t want that. But sometimes we do. Knowing that !

Continue Reading »

First Ruby MR

I just looked at the last post here. It was in late Feb 2022 I just realized that I have not posted anything in entire of March 2022 The reason for this microblog was to make it low-friction so that it does not go the way of my other blogs with month(s) long and sometime year long silence. But then why didn’t I post anything here for a month ?

Continue Reading »

Read The Docs Carefully

Continuing with my Ruby language learning journey, I wanted to use it for more than Hello world. So I decided to try python’s request equivalent. Since I didn’t know where to begin, I just searched for requests on RubyGems Turns out Gem by the exact name exists and with description Because Requests for Python is awesome 🤗 But it isn’t updated in close to 5 years now. I also wanted to use something native (i.

Continue Reading »

Ruby Debugger

While there are multiple ways to use Ruby debugger, for my first Ruby script (?) I found starting the script via rdbg to be the easiest. Like rdbg myscript.rb Debugger has all the basic command I have used elsewhere. n for next pp for pretty print q for quit For subsequent times, using require 'debug' followed by binding.break may be better. This README has all the details.

Bundler

If I were to explain bundler to pythonista (like myself) I would say Bundler in Ruby land is like poetry in python land, except it does not create sandbox environment To explain it a little more. It tracks dependencies in a Gemfile (and Gemfile.lock) which then goes in your repo. Other engineers sharing your code would then run bundle install, and they get exact same Gems (including versions) on their machines.

Continue Reading »

Where Are My (Ruby) Gems ?

As I mentioned earlier, I’m trying Lunar nvim starter kit. Latest version of nvim comes with LSP support, and while learning a new language LSP could be really helpful (I think) I had heard of solargraph. Running :LspInstall in nvim gave me option of sorbet as well. But I decided to stick with solargraph. nvim was successful in installing solargraph, or so it told me. But it did not work. LspInfo told me that it did not find solargraph Just to be sure I gem install solargraph from the terminal, before I tried to install LSP from nvim again

Continue Reading »