DEV Community

Evgeny Zhdanov
Evgeny Zhdanov

Posted on

lazy_names gem, ease console operations

Hello guys!

I just wrote a gem which can help with console routine.

A little bit of history, I caught myself mostly redefining constants to shorter versions but by hand, because I needed from time to time models, or some services, or operations and all of them were hidden by some modules (and that's ok you must put your code in namespace modules).

But I was asking myself do I really needed to type something like App::SomeEntity::Services::ServiceNamespace::ServiceAction.new.perform or even bigger.

Before I was just assigning it to shorter version on my pry console load, but that again led to same actions every pry console load. So I decided to wrap it in gem. So you have configuration where you put your map real constant => easy/lazy name.

So I looking for some feedback/critique. Maybe it was already implemented by someone and you could point me. I was using it only localhost for some period of time and finally decided to put in github and rubygems, maybe some of you were struggling same issues in your ruby console

Also I inspired by some ideas given to me by other devs, like auto-redefining const on some reducer, so for example

# the default one
def shortener(klass_name)
  klass_name.to_s.gsub('::', '')
    .split(/[a-z]/).select { |lt| !lt.empty? }.join
end

shortener(MyClass)
# => MC
shortener(MyModule::MyClass)
# => MMMC
shortener(MyModule::MyModelsNamespace::Module)
# => MMNM
Enter fullscreen mode Exit fullscreen mode

The main usage for the gem I see as Hexagonal Architecture, where you code highly decoupled by the modules.

What do you think about the gem, share thoughts with me! :)

Top comments (0)