Module: Fontcustom::Utility
Defined Under Namespace
Modules: HashWithMethodAccess
Class Method Summary
collapse
-
.shell ⇒ Object
Hacks that allow Thor::Actions and Thor::Shell to be used in Fontcustom classes.
Instance Method Summary
collapse
Class Method Details
.shell ⇒ Object
Hacks that allow Thor::Actions and Thor::Shell to be used in Fontcustom classes.
18
19
20
|
# File 'lib/fontcustom/utility.rb', line 18
def self.shell
@shell || Thor::Shell::Color.new
end
|
Instance Method Details
#behavior ⇒ Object
26
27
28
|
# File 'lib/fontcustom/utility.rb', line 26
def behavior
:invoke
end
|
#destination_root ⇒ Object
34
35
36
37
|
# File 'lib/fontcustom/utility.rb', line 34
def destination_root
@destination_stack ||= [project_root]
@destination_stack.last
end
|
#line_break(n = 14) ⇒ Object
magic number for Thor say_status line breaks
105
106
107
|
# File 'lib/fontcustom/utility.rb', line 105
def line_break(n = 14)
"\n#{" " * n}"
end
|
#methodize_hash(hash) ⇒ Object
61
62
63
|
# File 'lib/fontcustom/utility.rb', line 61
def methodize_hash(hash)
hash.extend HashWithMethodAccess
end
|
#options ⇒ Object
109
110
111
112
113
114
115
|
# File 'lib/fontcustom/utility.rb', line 109
def options
if @data
@data[:options]
else
@options || @cli_options || @config_options || {}
end
end
|
#project_root ⇒ Object
69
70
71
72
73
74
75
|
# File 'lib/fontcustom/utility.rb', line 69
def project_root
if @manifest.is_a? String
File.dirname @manifest
else
File.dirname @manifest.manifest
end
end
|
#say_changed(status, changed) ⇒ Object
99
100
101
102
|
# File 'lib/fontcustom/utility.rb', line 99
def say_changed(status, changed)
return if options[:quiet] || ! options[:debug] && status == :delete
say_status status, changed.join(line_break)
end
|
#say_message(status, message, color = nil) ⇒ Object
93
94
95
96
97
|
# File 'lib/fontcustom/utility.rb', line 93
def say_message(status, message, color = nil)
return if options[:quiet] && status != :error && status != :debug
color = :red if [:error, :debug, :warn].include?(status)
say_status status, message, color
end
|
#say_status(*args) ⇒ Object
30
31
32
|
# File 'lib/fontcustom/utility.rb', line 30
def say_status(*args)
shell.say_status *args
end
|
#source_paths ⇒ Object
39
40
41
|
# File 'lib/fontcustom/utility.rb', line 39
def source_paths
@source_paths ||= [File.join(Fontcustom.gem_lib, "templates"), Dir.pwd]
end
|
#symbolize_hash(hash) ⇒ Object
57
58
59
|
# File 'lib/fontcustom/utility.rb', line 57
def symbolize_hash(hash)
hash.inject({}) { |memo, (k, v)| memo[k.to_sym] = v; memo }
end
|
#write_file(file, content = "", message = nil, message_body = nil) ⇒ Object
81
82
83
84
85
86
87
|
# File 'lib/fontcustom/utility.rb', line 81
def write_file(file, content = "", message = nil, message_body = nil)
File.open(file, "w") { |f| f.write(content) }
if message
body = message_body || file
say_message message, body
end
end
|