Class: Spider::SpiderSetupWizard

Inherits:
Wizard show all
Defined in:
lib/spiderfw/setup/spider_setup_wizard.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Wizard

#add_key, #ask, #ask!, #ask?, #do_ask, #get_value, #implementation, #initialize, #set_value, #values, #wizard_instance

Constructor Details

This class inherits a constructor from Spider::Wizard

Instance Attribute Details

#first_runObject

Returns the value of attribute first_run.



185
186
187
# File 'lib/spiderfw/setup/spider_setup_wizard.rb', line 185

def first_run
  @first_run
end

Instance Method Details

#get_db_wizard(db_type) ⇒ Object



213
214
215
216
217
218
# File 'lib/spiderfw/setup/spider_setup_wizard.rb', line 213

def get_db_wizard(db_type)
    {
        'mysql' => MySQLSetupWizard,
        'oracle' => OracleSetupWizard
    }[db_type]
end

#runObject



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/spiderfw/setup/spider_setup_wizard.rb', line 187

def run

    if ask? _("Do you want to configure a database?"), :default => (@first_run ? true : nil)
        ask _("Which database do you want to configure?"), :db_label, :default => 'default'
        conf = Spider.conf.get("storages.#{@db_label}")
        url_db_type = nil
        if conf && conf["url"]    
            if conf["url"] =~ /db:(\w+):\/\//
                url_db_type = $1
            end
        end
        ask _("Database type: "), :db_type, :choices => ['mysql', 'oracle'], \
            :default => url_db_type
        break unless @db_type
        db = wizard_instance(get_db_wizard(@db_type))
        db.parse_url(conf["url"]) if conf && conf["url"] && @db_type == url_db_type
        db.run
        editor = Spider.config.get_editor
        editor.set('storages', @db_label, 'url', db.get_url)
        editor.save
        puts _("Configuration saved.")
    end
    
end