Ease your console typing with redefining constants by shorter version
MIT License
LazyNames helps programmer to type faster very-long class names, constants by defining them on a shorter version. If you are lazy like me typing many times a day in console long constants then this gem will ease your development process.
Consider this example from pry terminal session.
group :development do
gem 'lazy_names'
end
~/.pryrc
or per project myproject/.pryrc
if defined?(LazyNames)
Pry.config.hooks.add_hook(:when_started, :lazy_names) do
LazyNames.load_definitions!
end
end
~/.irbrc
or per project myproject/.irbrc
if defined?(LazyNames)
LazyNames.load_definitions!
end
bundle
cp .lazy_names.tt.yml ~/.lazy_names.yml
$ bundle exec rails c # or bin/console
# your shorter version of constants are available now, enjoy!
Take a look onto lazy_names.tt.yml
it has very basic template for you to start.
---
my_awesome_project:
definitions:
'Models::Users::CreditCard': 'MUCC'
my_awesome_project
should be you project/folder name
So consider this example:
$ pwd
/Users/name/my_awesome_project
The last folder name of you ruby project must match the same one in your configuration.
After definitions sections you can actually redefine your long constants.
So in this example Models::Users::CreditCard
is your real project constant and
MUCC
will be your short variant of it, so you can access Models::Users::CreditCard
from MUCC
. MUCC
and any other right hand side can be any value, you define the best-suitable names.
You can define as many constants as you want. The same rule applies for projects. Your config can have multiple constant definitions per namespace.
---
my_awesome_project:
definitions:
'Models::Users::CreditCard': 'MUCC'
my_another_project:
definitions:
'OtherLongConst': 'Short'
In the meantime you can put your .lazy_names.yml
config directly to project folder, it will be looked up firstly from project.
Just do not forget to put in your .gitignore
. I believe every developer defines shorter versions of constants by his own opinion.
echo '.lazy_names.yml' >> .gitignore
If project folder doesn't contain any .lazy_names.yml
, it will fallback to home directory.
Configuration per project a bit different: you don't need to specify global scope my_awesome_project
, you can skip forward to definitions
---
definitions:
'Models::Users::CreditCard: 'MUCC'
Example config can be found in .lazy_names.tt.project.yml
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
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
.
Bug reports and pull requests are welcome on GitHub at https://github.com/zhisme/lazy_names.
The gem is available as open source under the terms of the MIT License.