kvokka / pp_sql

Rails ActiveRecord SQL queries log beautifier
MIT License
265 stars 9 forks source link

Why is rails required? #12

Closed voltechs closed 5 years ago

voltechs commented 5 years ago

In my opinion, rails should not be a required dependency. Two approaches one could take for this.

  1. Move that to a developmental dependency, and simply place a conditional require in your entrypoint file (pp_sql.rb) like:
    # This is a common practice among gems that support `rails` "injection"
    require 'pp_sql/railtie.rb' if defined?(Rails::Railtie)
  2. Create another (very simple) gem (which can exist in the same repo if desired, with a pp_sql-rails.gemspec) called pp_sql-rails, which has a dependency on pp_sql and rails, and this is where you'd put the railtie injection bit.

That way, folks who don't need all of rails (many gems just require active_record, for example), and have the benefit of pretty printing sql, without the weight of rails! This also opens up pp_sql for inclusion in other frameworks, such as Sinatra, or Hanami!

Thanks for your work on pp_sql. I'm grateful someone has made this contribution.

kvokka commented 5 years ago

Thank you for the idea!

The answer for the question is very simple- I did not need to use it with out Rails and nobody asked about it before.

The gem is too small and it have too limited extension options, so doing second gem will be too much for this case (it add more hassle than gain). But the option 1 looks good.

Of course ActiveRecord should be a dependency, but not the entire Rails.

Feel free to add a PR or I'll take a look on this or next weekend.

kvokka commented 5 years ago

@voltechs I released version 1.0.0 of this gem, which does not require Rails.

voltechs commented 5 years ago

@kvokka awesome. I'm a little swamped with work and other obligations at the moment, but I will try to make a PR if I can.