Class: Rfm::Factory::DbFactory

Inherits:
CaseInsensitiveHash show all
Defined in:
lib/rfm/utilities/factory.rb

Overview

:nodoc: all

Instance Method Summary collapse

Methods inherited from CaseInsensitiveHash

#[]=

Methods inherited from Hash

#rfm_filter, #rfm_only, #to_cih

Constructor Details

#initialize(server) ⇒ DbFactory

Returns a new instance of DbFactory.



41
42
43
44
# File 'lib/rfm/utilities/factory.rb', line 41

def initialize(server)
  @server = server
  @loaded = false
end

Instance Method Details

#[](*args) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/rfm/utilities/factory.rb', line 46

def [](*args)
	# was: (dbname, acnt=nil, pass=nil)
	options = Factory.get_config(*args)
	name = options[:strings].delete_at(0) || options[:database]
	 = options[:strings].delete_at(0) || options[:account_name]
	password = options[:strings].delete_at(0) || options[:password]
  super(name) or (self[name] = Rfm::Database.new(name, , password, @server))
  # This part reconfigures the named database, if you pass it new config in the [] method.
				#   super(name).config({:account_name=>account_name, :password=>password}.merge(options)) if (account_name or password or options)
				#   super(name)
end

#allObject



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/rfm/utilities/factory.rb', line 58

def all
  if !@loaded
  	xml = @server.connect(@server.state[:account_name], @server.state[:password], '-dbnames', {}).body
    Rfm::Resultset.new(xml, :server_object => @server).each {|record|
      name = record['DATABASE_NAME']
      self[name] = Rfm::Database.new(name, @server) if self.keys.find{|k| k.to_s.downcase == name.to_s.downcase} == nil
    }
    @loaded = true
  end
  self
end

#namesObject



70
71
72
# File 'lib/rfm/utilities/factory.rb', line 70

def names
	keys
end