Lumos
☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢ ☢ ☢ ☢ ☢ ☢ Objects wrapping library ☢ ☢ ☢ ☢ ☢ ☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢
Have you ever tried to highlight your Ruby objects from your controllers/models/whatever in the Rails log? I bet you have ). I usually do something like that p "###"; p %w(foo bar baz ); p "###"
and in general it works fine, until you have to repeat this construction again and again, with different objects, in different places. I have a good news – lumos
helps to easily wrap any object to ascii-style markup and make it perceptible amongst ususal Rails log mess.
Installation
Add this line to your application's Gemfile:
gem 'lumos'
And call inside your controller/model/whatever
class My::MoviesController < ApplicationController
def checked
lumos params
@movie = Movie.find(params[:movie_id])
current_user.send(params[:scope]) << @movie
#redirect_to root_path
end
end
Usage
Depend on passed parameters, lumos
can act as a divider or as a wrapper.
Divider
For example, simple call of lumos
without params will print a ###
message in your log. Of course you're able to change a divider sign (lumos :>, "☭"
will print a ☭☭☭
message) and number of repetitions – lumos :>, "☢", 10
.
lumos
print "###"
lumos :>, "☭"
print "☭☭☭"
lumos :>, "☢", 10
print "☢☢☢☢☢☢☢☢☢☢"
Wrapper
But main reason of lumos
existence is necessity of objects highlighting besides ambient noise. So, initial array might be highlighted with lumos %w(foo bar baz)
that will give us such output:
######################### # # # ["foo", "bar", "baz"] # # # #########################
Wrapping method also takes few options such as:
position:
:surround
(by default), :top
, :bottom
, :left
, :right
, :horizontal
, :vertical
domains = {ru: "Russia", th: "Thailand", "com.au" => "Australia", ph: "Philippines", la: "Laos"}
lumos domains, {position: :horizontal}
###################################################################### {:ru=>"Russia", :th=>"Thailand", "com.au"=>"Australia", :ph=>"Philippi nes", :la=>"Laos"} ######################################################################
delimiter:
lumos domains, position: :horizontal, delimiter: "❤★"
{:ru=>"Russia", :th=>"Thailand", "com.au"=>"Australia", :ph=>"Philippi nes", :la=>"Laos"} ❤★❤★❤★❤★❤★❤★❤★❤★❤★❤★❤★❤★❤★❤★❤★❤★❤★❤★❤★❤★❤★❤★❤★❤★❤★❤★❤★❤★❤★❤★❤★❤★❤★❤★❤★
And as you know – everything is better with emoji, so lumos supports emoji delimiters as well!
lumos "Coffee smells like freshly ground heaven", delimiter: ":coffee:", position: :bottom
Coffee smells like freshly ground heaven
☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕
padding:
lumos domains, delimiter: "❄", padding: 2
❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄ ❄ ❄ ❄ ❄ ❄ ❄ ❄ {:ru=>"Russia", :th=>"Thailand", "com.au"=>"Australia", :ph=>"Philippi ❄ ❄ nes", :la=>"Laos"} ❄ ❄ ❄ ❄ ❄ ❄ ❄ ❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄❄
length:
lumos domains, position: :horizontal, delimiter: "->", length: 140
->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->-> {:ru=>"Russia", :th=>"Thailand", "com.au"=>"Australia", :ph=>"Philippines", :la=>"Laos"} ->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->
Default options
You are able to specify one or few settings described above as a part of global default options.
If you're using Rails, you can define a Hash with default options in config/application.rb
or in any of the config/environments/*.rb
files on config.lumos_defaults. An example:
module YourApp
class Application < Rails::Application
# Other code...
config.lumos_defaults = {position: :bottom, delimiter: ":poop:"}
end
end
Another option is to directly modify the Lumos::Wrapper.default_options
Hash - this method works for non-Rails applications or is an option if you prefer to place the Lumos default settings in an initializer.
Lumos::Wrapper.default_options[:padding] = 5
Lumos::Wrapper.default_options[:length] = 140
Lumos::Wrapper.default_options[:delimiter] = ":alien:"