Class: Wizard::Formula
- Inherits:
-
Object
show all
- Includes:
- Helpers
- Defined in:
- lib/wizard/formula.rb,
lib/wizard/spells/make_dir.rb,
lib/wizard/spells/make_file.rb,
lib/wizard/spells/update_file.rb
Constant Summary
collapse
- COLORIZERS =
{
:success => :green,
:error => :red,
}
Constants included
from Helpers
Helpers::COLORS
Class Method Summary
collapse
Instance Method Summary
collapse
-
#append_to_file(filename, content, options = {}) ⇒ Object
(also: #append, #append_to)
-
#make_dir(dirname, options = {}) ⇒ Object
(also: #dir, #directory, #mkdir, #create_dir)
-
#make_file(filename, content = nil, options = {}) ⇒ Object
(also: #file, #mkfile, #create_file)
-
#prepend_to_file(filename, content, options = {}) ⇒ Object
(also: #prepend, #prepend_to)
-
#render(spell) ⇒ Object
-
#replace_in_file(filename, content, replace, options = {}) ⇒ Object
(also: #replace, #replace_content)
-
#update_file(filename, content = nil, options = {}) ⇒ Object
(also: #update)
Methods included from Helpers
#adjust, #colorize, #console_width, #print, #say, #say!
Class Method Details
.colorizers ⇒ Object
11
12
13
|
# File 'lib/wizard/formula.rb', line 11
def self.colorizers
COLORIZERS
end
|
Instance Method Details
#append_to_file(filename, content, options = {}) ⇒ Object
Also known as:
append, append_to
17
18
19
|
# File 'lib/wizard/spells/update_file.rb', line 17
def append_to_file(filename, content, options={})
update_file(filename, content, options.merge(:before => :EOF))
end
|
#make_dir(dirname, options = {}) ⇒ Object
Also known as:
dir, directory, mkdir, create_dir
10
11
12
13
14
|
# File 'lib/wizard/spells/make_dir.rb', line 10
def make_dir(dirname, options={})
spell = Spells::MakeDir.new(dirname, options)
spell.perform
render(spell)
end
|
#make_file(filename, content = nil, options = {}) ⇒ Object
Also known as:
file, mkfile, create_file
13
14
15
16
17
|
# File 'lib/wizard/spells/make_file.rb', line 13
def make_file(filename, content=nil, options={})
spell = Spells::MakeFile.new(filename, content, options)
spell.perform
render(spell)
end
|
#prepend_to_file(filename, content, options = {}) ⇒ Object
Also known as:
prepend, prepend_to
23
24
25
|
# File 'lib/wizard/spells/update_file.rb', line 23
def prepend_to_file(filename, content, options={})
update_file(filename, content, options.merge(:after => :BOF))
end
|
#render(spell) ⇒ Object
15
16
17
18
19
20
|
# File 'lib/wizard/formula.rb', line 15
def render(spell)
line = " "
line += a(spell.to_s, console_width-spell.status.to_s.size-3) + " "
line += c(spell.status.to_s, self.class.colorizers[spell.status], true)
say! line
end
|
#replace_in_file(filename, content, replace, options = {}) ⇒ Object
Also known as:
replace, replace_content
29
30
31
|
# File 'lib/wizard/spells/update_file.rb', line 29
def replace_in_file(filename, content, replace, options={})
update_file(filename, content, options.merge(:replace => replace))
end
|
#update_file(filename, content = nil, options = {}) ⇒ Object
Also known as:
update
10
11
12
13
14
|
# File 'lib/wizard/spells/update_file.rb', line 10
def update_file(filename, content=nil, options={})
spell = Spells::UpdateFile.new(filename, content, options)
spell.perform
render(spell)
end
|