Class: CitizenCodeScripts::Base
- Inherits:
-
Object
- Object
- CitizenCodeScripts::Base
show all
- Includes:
- Colorize, FileUtils
- Defined in:
- lib/citizen_code_scripts/base.rb
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
#argv ⇒ Object
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
.description ⇒ Object
65
66
67
|
# File 'lib/citizen_code_scripts/base.rb', line 65
def self.description
""
end
|
.help ⇒ Object
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
.load_scripts_deferred ⇒ Object
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
|
.name ⇒ Object
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_classes ⇒ Object
28
29
30
|
# File 'lib/citizen_code_scripts/base.rb', line 28
def self.script_classes
@script_classes ||= []
end
|
.script_names ⇒ Object
43
44
45
|
# File 'lib/citizen_code_scripts/base.rb', line 43
def self.script_names
scripts.keys
end
|
.scripts ⇒ Object
32
33
34
|
# File 'lib/citizen_code_scripts/base.rb', line 32
def self.scripts
@scripts ||= load_scripts_deferred
end
|
Instance Method Details
#app_names ⇒ Object
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_root ⇒ Object
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_name ⇒ Object
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
|