Created
September 30, 2015 18:02
-
-
Save allolex/8b813111daa99d0cce2d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| # | |
| # Checks to see if the wirble gem is installed and | |
| # installs it for you if it is not already installed. | |
| def gem_list | |
| @gem_list ||= `gem list` | |
| end | |
| def gem_name_re | |
| /\A[^\w_-]+\z/ | |
| end | |
| def validate(name) | |
| if gem_name_re === name | |
| raise "Did you use the correct gem name?" | |
| end | |
| end | |
| def check_install(gem_name) | |
| validate(gem_name) | |
| unless /#{gem_name}/ === gem_list | |
| if exec "gem install #{gem_name}" | |
| @gem_list << gem_name | |
| end | |
| end | |
| end | |
| check_install("wirble") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment