Module: Scaffoldhub::Helper
Defined Under Namespace
Classes: ScaffoldParameterMissing
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.included(base) ⇒ Object
9
10
11
12
13
|
# File 'lib/scaffoldhub/helper.rb', line 9
def self.included(base)
base.class_eval do
source_root Dir.tmpdir
end
end
|
.scaffold_spec ⇒ Object
16
17
18
|
# File 'lib/scaffoldhub/helper.rb', line 16
def scaffold_spec
@scaffold_spec
end
|
.scaffold_spec=(scaffold) ⇒ Object
20
21
22
|
# File 'lib/scaffoldhub/helper.rb', line 20
def scaffold_spec=(scaffold)
@scaffold_spec = scaffold
end
|
Instance Method Details
#download_scaffold_spec! ⇒ Object
83
84
85
86
87
88
89
90
91
|
# File 'lib/scaffoldhub/helper.rb', line 83
def download_scaffold_spec!
scaffold_spec = ScaffoldSpec.new(scaffold_name, options[:local], status_proc)
scaffold_spec.download_and_parse!
if scaffold_spec.parameter_example && scaffold_parameter.nil?
say_status :error, parameter_missing_message(scaffold_spec.parameter_example), :red
raise ScaffoldParameterMissing
end
scaffold_spec
end
|
#each_gem ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/scaffoldhub/helper.rb', line 62
def each_gem
begin
if (gems = scaffold_spec.gems)
gems.each { |gem| yield gem }
end
rescue Errno::ENOENT => e
say_status :error, e.message, :red
raise e
rescue Scaffoldhub::NotFoundException => e
say_status :error, "HTTP 404 error - did you misspell \"#{scaffold_name}\"?", :red
raise e
rescue Scaffoldhub::NetworkErrorException => e
say_status :error, "HTTP error connecting to #{e.message}", :red
raise e
end
end
|
#each_template_file(type) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/scaffoldhub/helper.rb', line 25
def each_template_file(type)
begin
scaffold_spec.select_files(type).each do |template_file|
yield template_file.download!
template_file.close
end
rescue Errno::ENOENT => e
say_status :error, e.message, :red
raise e
rescue Scaffoldhub::NotFoundException => e
say_status :error, "HTTP 404 error - did you misspell \"#{scaffold_name}\"?", :red
raise e
rescue Scaffoldhub::NetworkErrorException => e
say_status :error, "HTTP error connecting to #{e.message}", :red
raise e
end
end
|
#find_template_file(type) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/scaffoldhub/helper.rb', line 43
def find_template_file(type)
begin
template_file = scaffold_spec.find_file(type)
if template_file
yield template_file.download!
template_file.close
end
rescue Errno::ENOENT => e
say_status :error, e.message, :red
raise e
rescue Scaffoldhub::NotFoundException => e
say_status :error, "HTTP 404 error - did you misspell \"#{scaffold_name}\"?", :red
raise e
rescue Scaffoldhub::NetworkErrorException => e
say_status :error, "HTTP error connecting to #{e.message}", :red
raise e
end
end
|
#post_install_message ⇒ Object
107
108
109
110
|
# File 'lib/scaffoldhub/helper.rb', line 107
def post_install_message
message = scaffold_spec.post_install_message
replace_name_tokens(message) if message
end
|
#replace_name_tokens(dest) ⇒ Object
101
102
103
104
105
|
# File 'lib/scaffoldhub/helper.rb', line 101
def replace_name_tokens(dest)
result = dest.gsub(/PLURAL_NAME/, file_name.pluralize).gsub(/NAME/, file_name)
result.gsub!(/SCAFFOLD_PARAMETER/, scaffold_parameter) unless scaffold_parameter.nil?
result
end
|
#scaffold_name ⇒ Object
93
94
95
|
# File 'lib/scaffoldhub/helper.rb', line 93
def scaffold_name
parse_scaffold_option(0)
end
|
#scaffold_parameter ⇒ Object
97
98
99
|
# File 'lib/scaffoldhub/helper.rb', line 97
def scaffold_parameter
parse_scaffold_option(1)
end
|
#scaffold_spec ⇒ Object
79
80
81
|
# File 'lib/scaffoldhub/helper.rb', line 79
def scaffold_spec
Helper.scaffold_spec ||= download_scaffold_spec!
end
|
#status_proc ⇒ Object
112
113
114
|
# File 'lib/scaffoldhub/helper.rb', line 112
def status_proc
@status_proc ||= lambda { |url| say_status :download, url }
end
|