Class: Rfm::Database

Inherits:
Object show all
Includes:
Config
Defined in:
lib/rfm/database.rb

Overview

The Database object represents a single FileMaker Pro database. When you retrieve a Database object from a server, its account name and password are set to the account name and password you used when initializing the Server object. You can override this of course:

myDatabase = myServer["Customers"]
myDatabase. = "foo"
myDatabase.password = "bar"

Accessing Layouts

All interaction with FileMaker happens through a Layout object. You can get a Layout object from the Database object like this:

myLayout = myDatabase["Details"]

This code gets the Layout object representing the layout called Details in the database.

Note: RFM does not talk to the server when you retrieve a Layout object in this way. Instead, it simply assumes you know what you're talking about. If the layout you specify does not exist, you will get no error at this point. Instead, you'll get an error when you use the Layout object methods to talk to FileMaker. This makes debugging a little less convenient, but it would introduce too much overhead to hit the server at this point.

The Database object has a layout attribute that provides alternate access to Layout objects. It acts like a hash of Layout objects, one for each accessible layout in the database. So, for example, you can do this if you want to print out a list of all layouts:

myDatabase.layout.each {|layout|
  puts layout.name
}

The Database::layout attribute is actually a LayoutFactory object, although it subclasses hash, so it should work in all the ways you expect. Note, though, that it is completely empty until the first time you attempt to access its elements. At that (lazy) point, it hits FileMaker, loads in the list of layouts, and constructs a Layout object for each one. In other words, it incurrs no overhead until you use it.

Accessing Scripts

If for some reason you need to enumerate the scripts in a database, you can do so:

myDatabase.script.each {|script|
  puts script.name
}

The Database::script attribute is actually a ScriptFactory object, although it subclasses hash, so it should work in all the ways you expect. Note, though, that it is completely empty until the first time you attempt to access its elements. At that (lazy) point, it hits FileMaker, loads in the list of scripts, and constructs a Script object for each one. In other words, it incurrs no overhead until you use it.

Note: You don't need a Script object to run a script (see the Layout object instead).

Attributes

In addition to the layout attribute, Server has a few other useful attributes:

  • server is the Server object this database comes from

  • name is the name of this database

  • state is a hash of all server options used to initialize this server

Constant Summary

Constants included from Config

Config::CONFIG_DONT_STORE, Config::CONFIG_KEYS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Config

#config_clear, #get_config, #log, #state

Constructor Details

#initialize(*args) ⇒ Database

Initialize a database object. You never really need to do this. Instead, just do this:

myServer = Rfm::Server.new(...)
myDatabase = myServer["Customers"]

This sample code gets a database object representing the Customers database on the FileMaker server.


69
70
71
72
73
74
# File 'lib/rfm/database.rb', line 69

def initialize(*args) #name, server_obj, acnt=nil, pass=nil
			config(*args)
  raise Rfm::Error::RfmError.new(0, "New instance of Rfm::Database has no name. Attempted name '#{state[:database]}'.") if state[:database].to_s == ''
  @layouts = Rfm::Factory::LayoutFactory.new(server, self)
  @scripts = Rfm::Factory::ScriptFactory.new(server, self)
end

Instance Attribute Details

#layoutsObject (readonly) Also known as: layout

Returns the value of attribute layouts


77
78
79
# File 'lib/rfm/database.rb', line 77

def layouts
  @layouts
end

#scriptsObject (readonly) Also known as: script

Returns the value of attribute scripts


77
78
79
# File 'lib/rfm/database.rb', line 77

def scripts
  @scripts
end

Instance Method Details

#account_nameObject


85
# File 'lib/rfm/database.rb', line 85

def ; state[:account_name]; end

#account_name=(x) ⇒ Object


86
# File 'lib/rfm/database.rb', line 86

def (x); config :account_name=>x; end

#config(*args) ⇒ Object


90
91
92
93
94
95
# File 'lib/rfm/database.rb', line 90

def config(*args)
	super(:capture_strings_with=>[:database, :account_name, :password])
	super(*args) do |params|
		(self.server = params[:objects][0]) if params && params[:objects] && params[:objects][0] && params[:objects][0].is_a?(Rfm::Server)
	end
end

#nameObject


84
# File 'lib/rfm/database.rb', line 84

def name; state[:database].to_s; end

#passwordObject


87
# File 'lib/rfm/database.rb', line 87

def password; state[:password]; end

#password=(x) ⇒ Object


88
# File 'lib/rfm/database.rb', line 88

def password=(x); config :password=>x; end

#serverObject


98
99
100
# File 'lib/rfm/database.rb', line 98

def server
	server_orig || (self.server = Rfm::Server.new(state[:host], state[:account_name], state[:password], self))
end

#server_origObject


97
# File 'lib/rfm/database.rb', line 97

alias_method :server_orig, :server