Class: Railsthemes::Installer
- Inherits:
-
Object
- Object
- Railsthemes::Installer
show all
- Includes:
- Logging
- Defined in:
- lib/railsthemes/installer.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Logging
debug, logger, #logger, logger=, verbose
Constructor Details
#initialize(options = {}) ⇒ Installer
Returns a new instance of Installer.
5
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/railsthemes/installer.rb', line 5
def initialize options = {}
@installed_email = false
@doc_popup = !options[:no_doc_popup]
server = 'http://staging.railsthemes.com' if options[:staging]
server = options[:server] if options[:server]
server ||= 'https://railsthemes.com'
server = nil if options[:file]
@server = server
Railsthemes::Logging.verbose if options[:verbose]
Railsthemes::Logging.debug if options[:debugging]
end
|
Instance Attribute Details
Returns the value of attribute doc_popup.
19
20
21
|
# File 'lib/railsthemes/installer.rb', line 19
def
@doc_popup
end
|
#server ⇒ Object
Returns the value of attribute server.
19
20
21
|
# File 'lib/railsthemes/installer.rb', line 19
def server
@server
end
|
Instance Method Details
#download_from_url(url, download_to) ⇒ Object
119
120
121
122
123
124
125
126
127
|
# File 'lib/railsthemes/installer.rb', line 119
def download_from_url url, download_to
if url
logger.warn "Downloading theme..."
config = Utils.get_primary_configuration
archive = File.join(download_to, "rt-archive.tar.gz")
Utils.download :url => url, :save_to => archive
logger.warn "Done downloading theme."
end
end
|
#email_installer ⇒ Object
31
32
33
|
# File 'lib/railsthemes/installer.rb', line 31
def email_installer
@email_installer ||= EmailInstaller.new
end
|
#get_download_url(code) ⇒ Object
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
# File 'lib/railsthemes/installer.rb', line 95
def get_download_url code
config = Utils.get_primary_configuration
server_request_url = "#{@server}/download?code=#{code}&config=#{config * ','}&v=2"
response = nil
begin
response = Utils.get_url server_request_url
rescue SocketError => e
Safe.log_and_abort 'We could not reach the RailsThemes server to download the theme. Please check your internet connection and try again.'
rescue Exception => e
logger.debug e.message
logger.debug e.backtrace
end
if response
if response.code.to_s == '200'
response.body
else
logger.debug "download_url response code: #{response[:code]}"
nil
end
end
end
|
#install_from_archive(filepath) ⇒ Object
68
69
70
71
72
73
|
# File 'lib/railsthemes/installer.rb', line 68
def install_from_archive filepath
Railsthemes::Utils.with_tempdir do |tempdir|
Utils.unarchive filepath, tempdir
install_from_file_system tempdir
end
end
|
#install_from_code(code) ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/railsthemes/installer.rb', line 75
def install_from_code code
Ensurer.ensure_clean_install_possible :server => @server
logger.warn "Figuring out what to download..."
send_gemfile code
download_url = get_download_url code
if download_url
logger.debug "download_url: #{download_url}"
Utils.with_tempdir do |tempdir|
download_from_url download_url, tempdir
install_from_file_system File.join(tempdir, 'rt-archive')
end
else
Safe.log_and_abort "We didn't recognize the code you gave to download the theme (#{code}).\n" +
"It should look something like [email protected]:ABCDEF."
end
end
|
#install_from_file_system(filepath) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/railsthemes/installer.rb', line 45
def install_from_file_system filepath
Ensurer.ensure_clean_install_possible :server => false
filepath = filepath.gsub(/\\/, '/')
filepath += '.tar.gz' if Utils.archive?(filepath + '.tar.gz')
if Utils.archive?(filepath)
install_from_archive filepath
elsif File.directory?(filepath)
theme_installer.install_from_file_system filepath
@installed_email = email_installer.install_from_file_system filepath
logger.warn 'Bundling to install new gems...'
Safe.system_call 'bundle'
logger.warn 'Done bundling.'
print_post_installation_instructions
if @doc_popup
else
Safe.log_and_abort "Could not find the file you need: #{filepath}"
end
end
|
35
36
37
38
39
40
41
42
43
|
# File 'lib/railsthemes/installer.rb', line 35
def
latest_installed_dir = Dir.glob("doc/railsthemes_*").max_by {|f| File.mtime(f)}
if latest_installed_dir
Dir[File.join(latest_installed_dir, '*.html')].each do |document|
logger.debug("document: #{document}")
Launchy.open(document) if document
end
end
end
|
#print_post_installation_instructions ⇒ Object
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
# File 'lib/railsthemes/installer.rb', line 142
def print_post_installation_instructions
logger.warn <<-EOS
Yay! Your theme is installed!
Documentation and help
======================
Theme documentation is located in the doc folder.
There are some help articles for your perusal at http://support.railsthemes.com.
What now?
EOS
with_number "Start or restart your development server."
with_number("Check out the local theme samples at: http://localhost:3000/railsthemes")
with_number("Ensure your new application layout file contains everything that you wanted",
"from the old one.")
with_number("For instructions on how to send RailsThemes-styled emails in your app,",
"check out the documentation in the docs folder.") if @installed_email
with_number "Let us know how it went: @railsthemes or [email protected]."
end
|
#send_gemfile(code) ⇒ Object
129
130
131
132
133
134
135
136
137
138
139
140
|
# File 'lib/railsthemes/installer.rb', line 129
def send_gemfile code
return nil unless File.exists?('Gemfile.lock')
begin
RestClient.post("#{@server}/gemfiles/parse",
:code => code, :gemfile_lock => File.new('Gemfile.lock', 'rb'))
rescue SocketError => e
Safe.log_and_abort 'We could not reach the RailsThemes server to start your download. Please check your internet connection and try again.'
rescue Exception => e
logger.info e.message
logger.info e.backtrace
end
end
|
#theme_installer ⇒ Object
can probably just make static
27
28
29
|
# File 'lib/railsthemes/installer.rb', line 27
def theme_installer
@theme_installer ||= ThemeInstaller.new
end
|
#with_number(*lines) ⇒ Object
167
168
169
170
171
172
173
|
# File 'lib/railsthemes/installer.rb', line 167
def with_number *lines
@number ||= 0
logger.warn "#{@number += 1}) #{lines[0]}"
lines[1..-1].each do |line|
logger.warn " #{line}"
end
end
|