class AbtionScripts::Base
Attributes
argv[R]
Public Class Methods
description()
click to toggle source
# File lib/abtion_scripts/base.rb, line 65 def self.description "" end
help()
click to toggle source
# File lib/abtion_scripts/base.rb, line 47 def self.help msg = <<-HELP Help has not been implemented for "#{name}". Please implement a help method like so: class #{self} < AbtionScripts::Base def self.help <<-EOF My awesome help message here. This will be so useful for people. EOF end end HELP puts msg end
inherited(klass)
click to toggle source
# File lib/abtion_scripts/base.rb, line 24 def self.inherited(klass) AbtionScripts::Base.script_classes << klass end
load_scripts_deferred()
click to toggle source
# File lib/abtion_scripts/base.rb, line 36 def self.load_scripts_deferred script_classes.reduce(Hash.new) do |result, klass| result[klass.name] = klass result end end
name()
click to toggle source
# File lib/abtion_scripts/base.rb, line 15 def self.name self .to_s .split('::') .last .gsub(/[A-Z]/, "-\\0") .downcase[1..-1] end
new(*argv)
click to toggle source
# File lib/abtion_scripts/base.rb, line 11 def initialize(*argv) @argv = argv end
run(*args)
click to toggle source
# File lib/abtion_scripts/base.rb, line 69 def self.run(*args) new(*args).run end
script_classes()
click to toggle source
# File lib/abtion_scripts/base.rb, line 28 def self.script_classes @script_classes ||= [] end
script_names()
click to toggle source
# File lib/abtion_scripts/base.rb, line 43 def self.script_names scripts.keys end
scripts()
click to toggle source
# File lib/abtion_scripts/base.rb, line 32 def self.scripts @scripts ||= load_scripts_deferred end
Public Instance Methods
app_names()
click to toggle source
# File lib/abtion_scripts/base.rb, line 116 def app_names YAML.load_file('abtion.yml')['heroku_app_names'] end
app_root()
click to toggle source
path to your application root.
# File lib/abtion_scripts/base.rb, line 74 def app_root Pathname.new(Dir.pwd) end
bundler?()
click to toggle source
# File lib/abtion_scripts/base.rb, line 92 def bundler? File.exist?("Gemfile") end
ci?()
click to toggle source
# File lib/abtion_scripts/base.rb, line 100 def ci? # Set by Circle automatically: # https://circleci.com/docs/1.0/environment-variables/#basics ENV.has_key?('CI') end
heroku(command, remote:)
click to toggle source
# File lib/abtion_scripts/base.rb, line 124 def heroku(command, remote:) validate_heroku_remote(remote) system! "heroku #{command} -r #{remote}" end
heroku_app_name(remote)
click to toggle source
# File lib/abtion_scripts/base.rb, line 120 def heroku_app_name(remote) app_names[remote.to_s] end
rails?()
click to toggle source
# File lib/abtion_scripts/base.rb, line 88 def rails? File.exist?("config/application.rb") end
run_script(name, *args)
click to toggle source
# File lib/abtion_scripts/base.rb, line 78 def run_script(name, *args) script = AbtionScripts::Base.scripts[name.to_s] if script.nil? raise "Could not find script with name #{name.inspect} to run" end script.run(*args) end
step(name) { || ... }
click to toggle source
# File lib/abtion_scripts/base.rb, line 111 def step(name) puts colorize(:info, "\n== #{name} ==") yield end
system!(*args)
click to toggle source
# File lib/abtion_scripts/base.rb, line 106 def system!(*args) puts colorize(:command, args.join(" ")) system(*args) || abort(colorize(:error, "\n== Command #{args} failed ==")) end
yarn?()
click to toggle source
# File lib/abtion_scripts/base.rb, line 96 def yarn? File.exist?("yarn.lock") end
Private Instance Methods
validate_heroku_remote(remote)
click to toggle source
# File lib/abtion_scripts/base.rb, line 131 def validate_heroku_remote(remote) raise "Missing remote" if remote.nil? raise "Unknown remote" unless %w[staging production].include?(remote.to_s) end