Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

nebulab/rails_console_toolkit

Repository files navigation

RailsConsoleToolkit πŸ”§πŸ§°

Configurable Rails Console Helpers

Find records faster, add custom helpers, improve your console life by 100%.

Build

Installation

Add this line to your application's Gemfile:

gem 'rails_console_toolkit'

And then generate the initializer:

$ bin/rails generate rails_console_toolkit:install

or write it manually:

# config/initializers/console.rb
RailsConsoleToolkit.configure do |config|
 # helper definitions go here...
 #
 # config.use_pack :aliases
 # config.use_pack :utils
 # config.use_pack :solidus if defined? Spree
end

Helper packs

Aliases

# config/initializers/console.rb
RailsConsoleToolkit.configure do |config|
 config.use_pack :aliases
end
> x # alias exit
> r # alias reload!

Utils

# config/initializers/console.rb
RailsConsoleToolkit.configure do |config|
 config.use_pack :utils
end
> benchmark("foo") { sleep 3 }
foo (3000.6ms)
=> 3
> bm # alias benchmark
# config/initializers/console.rb
RailsConsoleToolkit.configure do |config|
 config.use_pack :solidus
end
> load_factories # will load solidus factories, useful to create dummy data in development
> product(...) # => will look for Spree::Product records by :id, :slug, :name
> variant(...) # => will look for Spree::Variant records by :id, :sku
> taxon(...) # => will look for Spree::Taxon records by :id, :permalink
> order(...) # => will look for Spree::Order records by :id, :number
> user(...) # => will look for Spree::User records by :id, :email
> country(...) # => will look for Spree::Country records by :id, :iso, :iso3, :iso_name, :name

Custom Helpers

Generic helpers

# config/initializers/console.rb
RailsConsoleToolkit.configure do |config|
 config.helper :foo do
 :bar
 end
end
# bin/rails console
> foo # => :bar

Aliases

# config/initializers/console.rb
RailsConsoleToolkit.configure do |config|
 config.alias :r, :reload!
end
# bin/rails console
> r # The same as typing "reload!"

Model helpers

# config/initializers/console.rb
RailsConsoleToolkit.configure do |config|
 config.model_helper 'Spree::Product', as: :product, by: %i[name slug]
end
# bin/rails console
> product('black-tshirt') # => #<Spree::Product id: 123, name: "Black T-Shirt", slug: "black-tshirt", ...>
> product.slug # => "black-tshirt"
> product 456 # => #<Spree::Product id: 456, name: "Red T-Shirt", slug: "red-tshirt", ...>
> product.slug # => "red-tshirt"

Removing unwanted helpers

# config/initializers/console.rb
RailsConsoleToolkit.configure do |config|
 # Will define an alias :x for "exit"
 config.use_pack :aliases
 config.remove_helper :x
end
# bin/rails console
> x # NameError (undefined local variable or method \`x' for main:Object)

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/elia/rails_console_toolkit.

License

The gem is available as open source under the terms of the MIT License.

About

Nebulab

This project is funded and maintained by the Nebulab team.

We firmly believe in the power of open-source. Contact us if you like our work and you need help with your project design or development.

About

Configurable Rails Console Helpers

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /