Class: Localeapp::CLI::Install::DefaultInstaller
- Inherits:
-
Object
- Object
- Localeapp::CLI::Install::DefaultInstaller
show all
- Defined in:
- lib/localeapp/cli/install.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of DefaultInstaller.
22
23
24
|
# File 'lib/localeapp/cli/install.rb', line 22
def initialize(output)
@output = output
end
|
Instance Attribute Details
#config_file_path ⇒ Object
Returns the value of attribute config_file_path.
20
21
22
|
# File 'lib/localeapp/cli/install.rb', line 20
def config_file_path
@config_file_path
end
|
#data_directory ⇒ Object
Returns the value of attribute data_directory.
20
21
22
|
# File 'lib/localeapp/cli/install.rb', line 20
def data_directory
@data_directory
end
|
#key ⇒ Object
Returns the value of attribute key.
20
21
22
|
# File 'lib/localeapp/cli/install.rb', line 20
def key
@key
end
|
#project_data ⇒ Object
Returns the value of attribute project_data.
20
21
22
|
# File 'lib/localeapp/cli/install.rb', line 20
def project_data
@project_data
end
|
Instance Method Details
#check_data_directory_exists ⇒ Object
94
95
96
97
98
|
# File 'lib/localeapp/cli/install.rb', line 94
def check_data_directory_exists
unless File.directory?(data_directory)
@output.puts "WARNING: please create the #{data_directory} directory. Your translation data will be stored there."
end
end
|
#check_default_locale ⇒ Object
64
65
66
67
68
69
70
|
# File 'lib/localeapp/cli/install.rb', line 64
def check_default_locale
localeapp_default_code = project_data['default_locale']['code']
@output.puts "Default Locale: #{localeapp_default_code} (#{project_data['default_locale']['name']})"
if I18n.default_locale.to_s != localeapp_default_code
@output.puts "WARNING: I18n.default_locale is #{I18n.default_locale}, change in config/environment.rb (Rails 2) or config/application.rb (Rails 3)"
end
end
|
#execute(key = nil) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/localeapp/cli/install.rb', line 26
def execute(key = nil)
self.key = key
if validate_key
check_default_locale
set_config_paths
@output.puts "Writing configuration file to #{config_file_path}"
write_config_file
check_data_directory_exists
true
else
false
end
end
|
41
42
43
44
|
# File 'lib/localeapp/cli/install.rb', line 41
def
@output.puts "Localeapp Install"
@output.puts ""
end
|
#set_config_paths ⇒ Object
72
73
74
75
|
# File 'lib/localeapp/cli/install.rb', line 72
def set_config_paths
@config_file_path = "config/initializers/localeapp.rb"
@data_directory = "config/locales"
end
|
#validate_key ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/localeapp/cli/install.rb', line 46
def validate_key
@output.puts "Checking API key: #{key}"
if key.nil?
@output.puts "ERROR: You must supply an API key"
return false
end
valid_key, @project_data = check_key(key)
if valid_key
@output.puts "Success!"
@output.puts "Project: #{project_data['name']}"
true
else
@output.puts "ERROR: Project not found"
false
end
end
|
#write_config_file ⇒ Object
77
78
79
80
|
# File 'lib/localeapp/cli/install.rb', line 77
def write_config_file
create_config_dir
write_rails_config
end
|
#write_rails_config ⇒ Object
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/localeapp/cli/install.rb', line 82
def write_rails_config
File.open(config_file_path, 'w+') do |file|
file.write <<-CONTENT
require 'localeapp/rails'
Localeapp.configure do |config|
config.api_key = '#{key}'
end
CONTENT
end
end
|