Class: AbtionScripts::Base

Inherits:
Object
  • Object
show all
Includes:
Colorize, FileUtils
Defined in:
lib/abtion_scripts/base.rb

Direct Known Subclasses

Begin, Doctor, Help, KillDbSessions, Promote, Pushit, Rspec, Test, TodayI, Update, Diff

Constant Summary

Constants included from Colorize

Colorize::COLOR_CODES

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Colorize

#colorize, included

Constructor Details

#initialize(*argv) ⇒ Base

Returns a new instance of Base.



11
12
13
# File 'lib/abtion_scripts/base.rb', line 11

def initialize(*argv)
  @argv = argv
end

Instance Attribute Details

#argvObject (readonly)

Returns the value of attribute argv.



9
10
11
# File 'lib/abtion_scripts/base.rb', line 9

def argv
  @argv
end

Class Method Details

.descriptionObject



65
66
67
# File 'lib/abtion_scripts/base.rb', line 65

def self.description
  ""
end

.helpObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# 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) ⇒ Object



24
25
26
# File 'lib/abtion_scripts/base.rb', line 24

def self.inherited(klass)
  AbtionScripts::Base.script_classes << klass
end

.load_scripts_deferredObject



36
37
38
39
40
41
# 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

.nameObject



15
16
17
18
19
20
21
22
# File 'lib/abtion_scripts/base.rb', line 15

def self.name
  self
    .to_s
    .split('::')
    .last
    .gsub(/[A-Z]/, "-\\0")
    .downcase[1..-1]
end

.run(*args) ⇒ Object



69
70
71
# File 'lib/abtion_scripts/base.rb', line 69

def self.run(*args)
  new(*args).run
end

.script_classesObject



28
29
30
# File 'lib/abtion_scripts/base.rb', line 28

def self.script_classes
  @script_classes ||= []
end

.script_namesObject



43
44
45
# File 'lib/abtion_scripts/base.rb', line 43

def self.script_names
  scripts.keys
end

.scriptsObject



32
33
34
# File 'lib/abtion_scripts/base.rb', line 32

def self.scripts
  @scripts ||= load_scripts_deferred
end

Instance Method Details

#app_namesObject



116
117
118
# File 'lib/abtion_scripts/base.rb', line 116

def app_names
  YAML.load_file('abtion.yml')['heroku_app_names']
end

#app_rootObject

path to your application root.



74
75
76
# File 'lib/abtion_scripts/base.rb', line 74

def app_root
  Pathname.new(Dir.pwd)
end

#bundler?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/abtion_scripts/base.rb', line 92

def bundler?
  File.exist?("Gemfile")
end

#ci?Boolean

Returns:

  • (Boolean)


100
101
102
103
104
# 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:) ⇒ Object



124
125
126
127
# 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) ⇒ Object



120
121
122
# File 'lib/abtion_scripts/base.rb', line 120

def heroku_app_name(remote)
  app_names[remote.to_s]
end

#rails?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/abtion_scripts/base.rb', line 88

def rails?
  File.exist?("config/application.rb")
end

#run_script(name, *args) ⇒ Object



78
79
80
81
82
83
84
85
86
# 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) ⇒ Object



111
112
113
114
# File 'lib/abtion_scripts/base.rb', line 111

def step(name)
  puts colorize(:info, "\n== #{name} ==")
  yield
end

#system!(*args) ⇒ Object



106
107
108
109
# 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?Boolean

Returns:

  • (Boolean)


96
97
98
# File 'lib/abtion_scripts/base.rb', line 96

def yarn?
  File.exist?("yarn.lock")
end