Class: CitizenCodeScripts::Base

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

Direct Known Subclasses

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

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/citizen_code_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/citizen_code_scripts/base.rb', line 9

def argv
  @argv
end

Class Method Details

.descriptionObject



65
66
67
# File 'lib/citizen_code_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/citizen_code_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} < CitizenCodeScripts::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/citizen_code_scripts/base.rb', line 24

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

.load_scripts_deferredObject



36
37
38
39
40
41
# File 'lib/citizen_code_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/citizen_code_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/citizen_code_scripts/base.rb', line 69

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

.script_classesObject



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

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

.script_namesObject



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

def self.script_names
  scripts.keys
end

.scriptsObject



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

def self.scripts
  @scripts ||= load_scripts_deferred
end

Instance Method Details

#app_namesObject



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

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

#app_rootObject

path to your application root.



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

def app_root
  Pathname.new(Dir.pwd)
end

#staging_app_nameObject



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

def staging_app_name
  app_names['staging']
end

#step(name) ⇒ Object



83
84
85
86
# File 'lib/citizen_code_scripts/base.rb', line 83

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

#system!(*args) ⇒ Object



78
79
80
81
# File 'lib/citizen_code_scripts/base.rb', line 78

def system!(*args)
  puts colorize(:command, args.join(" "))
  system(*args) || abort(colorize(:error, "\n== Command #{args} failed =="))
end