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

extend Config

config :parent=>'@server'


35
36
37
38
39
40
# File 'lib/rfm/utilities/factory.rb', line 35

def initialize(server)
  extend Config
  config :parent=>'@server'
  @server = server
  @loaded = false
end

Instance Method Details

#[](*args) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rfm/utilities/factory.rb', line 42

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



54
55
56
57
58
59
60
61
62
# File 'lib/rfm/utilities/factory.rb', line 54

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



64
65
66
# File 'lib/rfm/utilities/factory.rb', line 64

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