Class: PrestaShopAutomationTool::ConfigurationParser
- Inherits:
-
Object
- Object
- PrestaShopAutomationTool::ConfigurationParser
- Defined in:
- lib/prestashop-automation-tool.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #ask_user_for_missing_info(options = {}) ⇒ Object
- #autocomplete_config ⇒ Object
-
#initialize(root) ⇒ ConfigurationParser
constructor
A new instance of ConfigurationParser.
- #parse ⇒ Object
Constructor Details
#initialize(root) ⇒ ConfigurationParser
Returns a new instance of ConfigurationParser.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/prestashop-automation-tool.rb', line 10 def initialize root @root = File.realpath(root) vhosts = ApacheVhostsParser.parseDirectory if url = vhosts.urlFor(@root) fou = "http://#{url}/" else fou = "http://localhost/#{File.basename(@root)}/" end @config_fields = { database_user: '', database_password: '', database_name: '', database_prefix: 'ps_', database_host: 'localhost', version: '', front_office_url: fou, back_office_url: nil, installer_url: nil, admin_email: '[email protected]', admin_password: '123456789', default_customer_email: '[email protected]', default_customer_password: '123456789' } @config = {} end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
8 9 10 |
# File 'lib/prestashop-automation-tool.rb', line 8 def config @config end |
Instance Method Details
#ask_user_for_missing_info(options = {}) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/prestashop-automation-tool.rb', line 71 def ask_user_for_missing_info ={} @config_fields.each_pair do |key, default_value| unless @config[key] if default_value default = default_value != '' ? " (default: \"#{default_value.to_s})\"" : '' unless [:accept_defaults] print "#{key.to_s.split('_').map(&:capitalize).join ' '}#{default}? " value = $stdin.gets.strip value = default_value if value == "" @config[key] = value else @config[key] = default_value end end end end end |
#autocomplete_config ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/prestashop-automation-tool.rb', line 89 def autocomplete_config if m = @config[:database_host].match(/^(.*?)\:(.*?)$/) @config[:database_host] = m[1] @config[:database_port] = m[2] end if @admin_folder @config[:back_office_url] = URI.join(@config[:front_office_url], @admin_folder).to_s end if @installer_folder @config[:installer_url] = URI.join(@config[:front_office_url], @installer_folder).to_s end end |
#parse ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/prestashop-automation-tool.rb', line 39 def parse if File.exists? path=File.join(@root, 'config', 'settings.inc.php') config = Hash[File.read(path).scan(/\bdefine\s*\(\s*'(.*?)'\s*,\s*'(.*?)'\s*\)\s*;/)] mapping = { database_user: '_DB_USER_', database_password: '_DB_PASSWD_', database_name: '_DB_NAME_', database_prefix: '_DB_PREFIX_', database_host: '_DB_SERVER_', version: '_PS_VERSION_' } @config_fields.each_pair do |key, default_value| if (value = config[mapping[key]].to_s.strip) != '' @config[key] = value end end end Dir.entries('.').each do |entry| unless entry =~ /^\./ if File.directory? entry if File.exists? File.join(entry, 'ajax-tab.php') @admin_folder = entry elsif File.exists? File.join(entry, 'index_cli.php') @installer_folder = entry end end end end end |