Class: Railsthemes::Ensurer
- Inherits:
-
Object
- Object
- Railsthemes::Ensurer
show all
- Extended by:
- Logging
- Defined in:
- lib/railsthemes/ensurer.rb
Constant Summary
collapse
- @@already_checked =
false
Class Method Summary
collapse
Methods included from Logging
debug, logger, logger, logger=, verbose
Class Method Details
.ask_to_install_unsupported ⇒ Object
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/railsthemes/ensurer.rb', line 95
def self.ask_to_install_unsupported
logger.warn "WARNING\n"
if File.exists?('Gemfile.lock')
logger.warn <<-EOS
Your Gemfile.lock file indicates that you are using a version of Rails that
is not officially supported by RailsThemes.
EOS
else
logger.warn <<-EOS
We could not find a Gemfile.lock file in this directory. This could indicate
that you are not in a Rails application, or that you are not using Bundler
(which probably means that you are using a version of Rails that is not
officially supported by RailsThemes.)
EOS
end
logger.warn <<-EOS
While Rails applications that are less than version 3.1 are not officially
supported, you can try installing anyway, or can stop. If you cancel the
install before downloading, we can refund your purchase. If you install,
we cannot guarantee that RailsThemes will work for your app. You may have
to do some custom changes, which might be as easy as copying files,
but which may be more complicated.
EOS
unless Safe.yes? 'Do you still wish to install the theme? [y/N]'
Safe.log_and_abort 'Halting.'
end
end
|
.ensure_bundle_is_up_to_date ⇒ Object
125
126
127
128
129
130
131
132
133
134
135
136
|
# File 'lib/railsthemes/ensurer.rb', line 125
def self.ensure_bundle_is_up_to_date
logger.warn "Checking bundle..."
result = Safe.system_call('bundle check')
if result !~ /The Gemfile's dependencies are satisfied/
Safe.log_and_abort <<-EOS
Running `bundle check` resulted in the following issues:
#{result}
Please run `bundle` and try installing again.
EOS
end
logger.warn "Done checking bundle."
end
|
.ensure_clean_install_possible(options = {}) ⇒ Object
checks if we can cleanly install into the current working directory
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/railsthemes/ensurer.rb', line 8
def self.ensure_clean_install_possible options = {}
return if @@already_checked unless options[:force]
ensure_in_rails_root
ensure_bundle_is_up_to_date
ensure_railsthemes_is_not_in_gemfile
ensure_vcs_is_clean
ensure_rails_version_is_valid
ensure_installer_is_up_to_date(options[:server]) if options[:server]
@@already_checked = true
end
|
.ensure_in_rails_root ⇒ Object
19
20
21
22
23
|
# File 'lib/railsthemes/ensurer.rb', line 19
def self.ensure_in_rails_root
unless File.directory?('app') && File.directory?('public')
Safe.log_and_abort 'Must be in the Rails root directory to use this gem.'
end
end
|
.ensure_installer_is_up_to_date(server) ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/railsthemes/ensurer.rb', line 58
def self.ensure_installer_is_up_to_date server
logger.warn "Checking installer version..."
url = server + '/installer/version'
logger.debug "installer version url: #{url}"
begin
response = Utils.get_url url
rescue SocketError => e
logger.debug e.message
logger.debug e.backtrace * "\n"
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 * "\n"
end
if response && response.code.to_s == '200'
server_recommended_version_string = response.body
server_recommended_version = Gem::Version.new(server_recommended_version_string)
local_installer_version = Gem::Version.new(Railsthemes::VERSION)
if server_recommended_version > local_installer_version
Safe.log_and_abort <<-EOS
Your version is older than the recommended version.
Your version: #{Railsthemes::VERSION}
Recommended version: #{server_recommended_version_string}
EOS
else
logger.debug "server recommended version: #{server_recommended_version_string}"
end
else
logger.debug 'Got an error'
logger.debug response
Safe.log_and_abort 'There was an issue checking your installer version.'
end
logger.warn "Done checking installer version."
end
|
.ensure_rails_version_is_valid ⇒ Object
51
52
53
54
55
56
|
# File 'lib/railsthemes/ensurer.rb', line 51
def self.ensure_rails_version_is_valid
unless File.exists?('Gemfile.lock') &&
Gem::Version.new('3.1') <= Railsthemes::GemfileUtils.rails_version
ask_to_install_unsupported
end
end
|
.ensure_railsthemes_is_not_in_gemfile(gemfile_contents = nil) ⇒ Object
138
139
140
141
142
143
144
|
# File 'lib/railsthemes/ensurer.rb', line 138
def self.ensure_railsthemes_is_not_in_gemfile gemfile_contents = nil
gemfile_contents ||= Utils.read_file('Gemfile.lock')
specs = Utils.gemspecs(gemfile_contents)
if specs.any? { |x| x.name == 'railsthemes' }
Safe.log_and_abort "You should not install the railsthemes installer in your Gemfile.\nPlease remove and try again."
end
end
|
.ensure_vcs_is_clean ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/railsthemes/ensurer.rb', line 25
def self.ensure_vcs_is_clean
logger.warn "Checking version control..."
result = ''
variety = ''
if File.directory?('.git')
variety = 'Git'
result = Safe.system_call('git status -s')
elsif File.directory?('.hg')
variety = 'Mercurial'
result = Safe.system_call('hg status')
elsif File.directory?('.svn')
variety = 'Subversion'
result = Safe.system_call('svn status')
end
unless result.size == 0
Safe.log_and_abort <<-EOS
#{variety} reports that you have the following pending changes:
#{result}
Please roll back or commit the changes before proceeding to ensure that you can roll back after installing if you want.
EOS
end
logger.warn "Done checking version control."
end
|