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

#_create_accessor, #_merge_object!, #rfm_filter, #rfm_only, #to_cih

Constructor Details

#initialize(server) ⇒ DbFactory

Returns a new instance of DbFactory.



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

def initialize(server)
	  	extend Config
	  	config :parent=>'@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 = get_config(*args)
	name = options[:strings].delete_at(0) || options[:database]
	#account_name = options[:strings].delete_at(0) || options[:account_name]
	#password = options[:strings].delete_at(0) || options[:password]
  super(name) || (self[name] = Rfm::Database.new(@server, *args))  #(name, account_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
# File 'lib/rfm/utilities/factory.rb', line 58

def all
  if !@loaded
					c = Connection.new('-dbnames', {}, {:grammar=>'FMPXMLRESULT'}, @server)
					c.parse('fmpxml_minimal.yml', {})['data'].each{|k,v| (self[k] = Rfm::Database.new(v['text'], @server)) if k.to_s != '' && v['text']}
					#r = c.parse('fmpxml_minimal.yml', {})
    @loaded = true
  end
  self
end

#namesObject



68
69
70
# File 'lib/rfm/utilities/factory.rb', line 68

def names
	self.values.collect{|v| v.name}
end