Class: Codelation::Cli
- Inherits:
-
Thor
- Object
- Thor
- Codelation::Cli
- Includes:
- Thor::Actions
- Defined in:
- lib/codelation/base.rb,
lib/codelation/version.rb,
lib/codelation/rails/new.rb,
lib/codelation/development.rb,
lib/codelation/development/atom.rb,
lib/codelation/development/ruby.rb,
lib/codelation/development/psequel.rb,
lib/codelation/development/postgres.rb,
lib/codelation/development/dot_files.rb,
lib/codelation/development/sequel_pro.rb,
lib/codelation/development/dependencies.rb,
lib/codelation/development/atom_packages.rb,
lib/codelation/development/install_methods.rb
Constant Summary collapse
- ATOM_APP_DOWNLOAD_URL =
"https://atom.io/download/mac".freeze
- RUBY_INSTALL_VERSION =
"0.6.0".freeze
- RUBY_INSTALL_URL =
"https://github.com/postmodern/ruby-install/archive/v#{RUBY_INSTALL_VERSION}.tar.gz".freeze
- RUBY_VERSION =
"2.3.0".freeze
- PSEQUEL_APP_DOWNLOAD_URL =
"http://www.psequel.com/download?version=latest".freeze
- POSTGRES_APP_DOWNLOAD_URL =
"https://github.com/PostgresApp/PostgresApp/releases/download/9.4.1.0/Postgres-9.4.1.0.zip".freeze
- SEQUEL_PRO_APP_DOWNLOAD_URL =
"http://codelation-cli.s3.amazonaws.com/sequel-pro-1.0.2.zip".freeze
Class Method Summary collapse
-
.source_root ⇒ Object
This is the directory where your templates should be placed.
Instance Method Summary collapse
- #development_install ⇒ Object
-
#help(method = nil) ⇒ Object
Add the ablitity to print help for commands like: ‘codelation help development:install` This would print help for the method: `development_install`.
-
#method_missing(method, *args, &block) ⇒ Object
Add the ablitity to run commands like: ‘codelation development:install` This would run the defined method: `development_install`.
- #rails_new ⇒ Object
- #update ⇒ Object
- #version ⇒ Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Add the ablitity to run commands like:
`codelation development:install`
This would run the defined method:
`development_install`
26 27 28 29 30 31 32 33 34 |
# File 'lib/codelation/base.rb', line 26 def method_missing(method, *args, &block) if method.to_s.split(":").length >= 2 self.send(method.to_s.gsub(":", "_"), *args) elsif method.to_s == "run" self.walk(*args) else super end end |
Class Method Details
.source_root ⇒ Object
This is the directory where your templates should be placed.
37 38 39 |
# File 'lib/codelation/base.rb', line 37 def self.source_root File.("../../../resources", __FILE__) end |
Instance Method Details
#development_install ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/codelation/development.rb', line 17 def development_install print_heading("Installing Dependencies") install_dependencies unless Dir.exist?("/Applications/Atom.app") print_heading("Installing Atom.app") install_atom end print_heading("Installing Atom Packages") install_atom_packages print_heading("Installing Dot Files") install_dot_files unless Dir.exist?("/Applications/Postgres.app") print_heading("Installing Postgres.app") install_postgres end unless Dir.exist?("/Applications/PSequel.app") print_heading("Installing PSequel.app") install_psequel end print_heading("Installing Ruby") install_ruby unless Dir.exist?("/Applications/Sequel Pro.app") print_heading("Installing Sequel Pro.app") install_sequel_pro end `source ~/.bash_profile` print_heading("Adding $PATH to Atom Init Script") add_atom_init_script end |
#help(method = nil) ⇒ Object
Add the ablitity to print help for commands like:
`codelation help development:install`
This would print help for the method:
`development_install`
13 14 15 16 17 18 19 20 |
# File 'lib/codelation/base.rb', line 13 def help(method = nil) if method.to_s.split(":").length >= 2 method = method.to_s.gsub(":", "_") elsif method.to_s == "run" method = "walk" end super end |
#rails_new ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/codelation/rails/new.rb', line 13 def rails_new github_url = ask("Enter the project's GitHub URL (or enter an app name):") return if github_url.blank? print_heading("Generating New Rails Application") app_name = github_url.split("/").last.gsub(".git", "") print_command("Cloning the Rails project template") run_command("git clone https://github.com/codelation/rails-project-template.git #{app_name}") print_command("Deleting the template's git history") FileUtils.rm_rf("./#{app_name}/.git") print_command("Configuring your application") replace_app_name(app_name) generate_secret_tokens(app_name) Dir.chdir(app_name) do print_command("Initializing git repository") run_command("git init") run_command("git remote add origin #{github_url}.git") run_command("git add .") run_command('git commit -m "Initial commit"') print_command("Installing dependencies") run_command("bundle install") return if no?("-----> Setup database? [y/N]") run_command("rake db:setup") end end |
#update ⇒ Object
10 11 12 13 14 |
# File 'lib/codelation/version.rb', line 10 def update command = "gem install codelation-cli" puts "Running #{command}..." exec(command) end |
#version ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/codelation/version.rb', line 17 def version gem_version = "v#{Codelation::VERSION}" # Grab the latest version of the RubyGem rubygems_json = open("https://rubygems.org/api/v1/gems/codelation-cli.json").read rubygems_version = "v#{JSON.parse(rubygems_json)['version'].strip}" = "" if gem_version != rubygems_version = " Run `codelation update` to install" end puts puts "Codelation CLI" puts " Installed: #{gem_version}" puts " Latest: #{rubygems_version}#{}" puts end |