| Class | Rfm::Server |
| In: |
lib/rfm_command.rb
|
| Parent: | Object |
This class represents a single FileMaker server. It is initialized with basic connection information, including the hostname, port number, and default database account name and password.
Note: The host and port number refer to the FileMaker Web Publishing Engine, which must be installed and configured in order to use RFM. It may not actually be running on the same server computer as FileMaker Server itself. See your FileMaker Server or FileMaker Server Advanced documentation for information about configuring a Web Publishing Engine.
Typically, you access a Database object from the Server like this:
myDatabase = myServer["Customers"]
This code gets the Database object representing the Customers object.
Note: RFM does not talk to the server when you retrieve a database object in this way. Instead, it simply assumes you know what you’re talking about. If the database 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 you get from this database. This makes debugging a little less convenient, but it would introduce too much overhead to hit the server at this point.
The Server object has a db attribute that provides alternate access to Database objects. It acts like a hash of Database objects, one for each accessible database on the server. So, for example, you can do this if you want to print out a list of all databses on the server:
myServer.db.each {|database|
puts database.name
}
The Server::db attribute is actually a DbFactory 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 databases, and constructs a Database object for each one. In other words, it incurrs no overhead until you use it.
In addition to the db attribute, Server has a few other useful attributes:
| db | [R] | |
| host_name | [R] | |
| port | [R] | |
| scheme | [R] | |
| state | [R] |
To create a Server obejct, you typically need at least a host name:
myServer = Rfm::Server.new({:host => 'my.host.com'})
Several other options are supported:
Access the database object representing a database on the server. For example:
myServer['Customers']
would return a Database object representing the Customers database on the server.
Note: RFM never talks to the server until you perform an action. The database object returned is created on the fly and assumed to refer to a valid database, but you will get no error at this point if the database you access doesn’t exist. Instead, you’ll receive an error when you actually try to perform some action on a layout from this database.
Performs a raw FileMaker action. You will generally not call this method directly, but it is exposed in case you need to do something "under the hood."
The action parameter is any valid FileMaker web url action. For example, +-find+, +-finadny+ etc.
The args parameter is a hash of arguments to be included in the action url. It will be serialized and url-encoded appropriately.
The options parameter is a hash of RFM-specific options, which correspond to the more esoteric FileMaker URL parameters. They are exposed separately because they can also be passed into various methods on the Layout object, which is a much more typical way of sending an action to FileMaker.
This method returns the Net::HTTP response object representing the response from FileMaker.
For example, if you wanted to send a raw command to FileMaker to find the first 20 people in the "Customers" database whose first name is "Bill" you might do this:
response = myServer.do_action(
'-find',
{
"-db" => "Customers",
"-lay" => "Details",
"First Name" => "Bill"
},
{ :max_records => 20 }
)