Module: CLIHelper
- Included in:
- ProjectUtility
- Defined in:
- lib/joe_utils/helpers/cli_helper.rb
Constant Summary collapse
- MESSAGES =
{ add_git: 'Adding to git...', commit_git: 'Commiting to git...', push_rubygems: 'Pushing to rubygems.org...', install_gem: 'Installing gem and jgem locally...', build_gem: 'Building gem...', build_gem_failed: 'The gem build failed. Please confirm the gem name and try again.', deploy_heroku: 'Deploying to heroku.', commit_github: 'Commiting to github.', commit_default_message: 'Commit by script', rake_test: 'Running tests...', }
Instance Method Summary collapse
-
#build_gem(gem_name, options = {}) ⇒ Boolean
Builds the named gem locally, in case of provided options pushes and installs the gem.
-
#commit_git(message) ⇒ Boolean
Commits to git.
- #commit_github ⇒ Boolean
- #deploy_heroku ⇒ Boolean
- #execute(message_key, command, no_success_pattern = nil) ⇒ Boolean
-
#install_gem(gem_built_name) ⇒ Boolean
Installs the named gem locally.
-
#install_jgem(gem_built_name) ⇒ Boolean
Installs the named jgem locally.
-
#push_rubygems(gem_built_name) ⇒ Boolean
Pushes the named gem to rubygems.org.
- #rake_test ⇒ Boolean
Instance Method Details
#build_gem(gem_name, options = {}) ⇒ Boolean
Builds the named gem locally, in case of provided options pushes and installs the gem
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/joe_utils/helpers/cli_helper.rb', line 27 def build_gem(gem_name, = {}) puts MESSAGES[:build_gem] success = true puts(gem_built_name = `gem build "#{gem_name}.gemspec"`) gem_built_name = gem_built_name.match(/File: /).post_match if gem_built_name && !gem_built_name.empty? success = push_rubygems(gem_built_name) if [:push] [:install] ? install_gem(gem_built_name) && install_jgem(gem_built_name) && success : success else puts MESSAGES[:build_gem_failed] end end |
#commit_git(message) ⇒ Boolean
Commits to git
18 19 20 21 |
# File 'lib/joe_utils/helpers/cli_helper.rb', line 18 def commit_git() execute(:add_git, 'git add -u') && execute(:commit_git, "git commit -m \"#{message || MESSAGES[:commit_default_message]}\"") end |
#commit_github ⇒ Boolean
62 63 64 |
# File 'lib/joe_utils/helpers/cli_helper.rb', line 62 def commit_github execute(:commit_github, 'git push origin master') end |
#deploy_heroku ⇒ Boolean
67 68 69 |
# File 'lib/joe_utils/helpers/cli_helper.rb', line 67 def deploy_heroku execute(:deploy_heroku, 'git push heroku master') end |
#execute(message_key, command, no_success_pattern = nil) ⇒ Boolean
79 80 81 82 83 |
# File 'lib/joe_utils/helpers/cli_helper.rb', line 79 def execute(, command, no_success_pattern = nil) puts MESSAGES[] if puts (result = `#{command}`) result !~ no_success_pattern || RegExpHelper::NO_SUCCESS end |
#install_gem(gem_built_name) ⇒ Boolean
Installs the named gem locally
50 51 52 |
# File 'lib/joe_utils/helpers/cli_helper.rb', line 50 def install_gem(gem_built_name) execute(:install_gem, "gem install #{gem_built_name}") end |
#install_jgem(gem_built_name) ⇒ Boolean
Installs the named jgem locally
57 58 59 |
# File 'lib/joe_utils/helpers/cli_helper.rb', line 57 def install_jgem(gem_built_name) execute(:install_jgem, "jgem install #{gem_built_name}") end |
#push_rubygems(gem_built_name) ⇒ Boolean
Pushes the named gem to rubygems.org
43 44 45 |
# File 'lib/joe_utils/helpers/cli_helper.rb', line 43 def push_rubygems(gem_built_name) execute(:push_rubygems, "gem push #{gem_built_name}") end |
#rake_test ⇒ Boolean
72 73 74 |
# File 'lib/joe_utils/helpers/cli_helper.rb', line 72 def rake_test execute(:rake_test, 'rake test') end |