Class: Dogids::Cli

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/dogids/ssh.rb,
lib/dogids/base.rb,
lib/dogids/deploy.rb,
lib/dogids/version.rb,
lib/dogids/deploy/web.rb,
lib/dogids/deploy/worker.rb,
lib/dogids/ssh/production.rb,
lib/dogids/ssh/development.rb

Class Method Summary collapse

Instance Method Summary collapse

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:

`dogids development:install`

This would run the defined method:

`development_install`


26
27
28
29
30
31
32
33
34
# File 'lib/dogids/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_rootObject

This is the directory where your templates should be placed.



37
38
39
# File 'lib/dogids/base.rb', line 37

def self.source_root
  File.expand_path("../../../resources", __FILE__)
end

Instance Method Details

#deploy(app_name = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/dogids/deploy.rb', line 8

def deploy(app_name = nil)
  deploy_command = "deploy_#{app_name}"
  return self.send(deploy_command) if self.respond_to?(deploy_command)

  puts "Deployment Commands:"
  puts "  dogids deploy web    # Deploy the dogids.com storefront"
  puts "  dogids deploy worker # Deploy the dogids-backgrounder app"
  puts " "
end

#help(method = nil) ⇒ Object

Add the ablitity to print help for commands like:

`dogids help development:install`

This would print help for the method:

`development_install`

Parameters:

  • method (String) (defaults to: nil)


13
14
15
16
17
18
19
20
# File 'lib/dogids/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

#ssh(vm_name = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/dogids/ssh.rb', line 8

def ssh(vm_name = nil)
  if vm_name
    ssh_development(vm_name)
  else
    puts "Development SSH Commands:"
    puts "  dogids ssh dev               # SSH into local development VM"
    puts " "
    puts "Production SSH Commands:"
    puts "  dogids ssh:production db     # SSH into production MySQL/Redis VM"
    puts "  dogids ssh:production web    # SSH into production Apache/PHP VM"
    puts "  dogids ssh:production worker # SSH into production Ruby/Sidekiq VM"
    puts " "
  end
end

#updateObject



10
11
12
13
14
# File 'lib/dogids/version.rb', line 10

def update
  command = "gem install dogids-cli"
  puts "Running #{command}..."
  exec(command)
end

#versionObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/dogids/version.rb', line 17

def version
  gem_version = "v#{Dogids::VERSION}"

  # Grab the latest version of the RubyGem
  rubygems_json = open("https://rubygems.org/api/v1/gems/dogids-cli.json").read
  rubygems_version = "v#{JSON.parse(rubygems_json)['version'].strip}"

  upgrade_message = ""
  if gem_version != rubygems_version
    upgrade_message = " Run `dogids update` to install"
  end

  puts
  puts "Dogids CLI"
  puts "  Installed: #{gem_version}"
  puts "  Latest:    #{rubygems_version}#{upgrade_message}"
  puts
end