Class: Rfm::Database
- Includes:
- Config
- Defined in:
- lib/rfm/database.rb,
lib/rfm/base.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.account_name = "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
Instance Attribute Summary collapse
-
#layouts ⇒ Object
(also: #layout)
readonly
Returns the value of attribute layouts.
-
#scripts ⇒ Object
(also: #script)
readonly
Returns the value of attribute scripts.
Instance Method Summary collapse
- #account_name ⇒ Object
- #account_name=(x) ⇒ Object
-
#initialize(*args) ⇒ Database
constructor
Initialize a database object.
- #name ⇒ Object
- #password ⇒ Object
- #password=(x) ⇒ Object
- #state(*args) ⇒ Object
Methods included from Config
#config, #config_clear, #get_config, #sanitize_config
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 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/rfm/database.rb', line 69 def initialize(*args) #name, server_obj, acnt=nil, pass=nil = get_config(*args) .instance_variable_set :@server, ([:objects].delete_at(0) || [:server_object]) = get_config() config sanitize_config(, {}, true) config :parent=> 'server' config :database=> [:strings].delete_at(0) || [:database] config :account_name=> [:strings].delete_at(0) || [:account_name] config :password=> [:strings].delete_at(0) || [:password] 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
#layouts ⇒ Object (readonly) Also known as: layout
Returns the value of attribute layouts.
87 88 89 |
# File 'lib/rfm/database.rb', line 87 def layouts @layouts end |
#scripts ⇒ Object (readonly) Also known as: script
Returns the value of attribute scripts.
87 88 89 |
# File 'lib/rfm/database.rb', line 87 def scripts @scripts end |
Instance Method Details
#account_name ⇒ Object
95 |
# File 'lib/rfm/database.rb', line 95 def account_name; state[:account_name]; end |
#account_name=(x) ⇒ Object
96 |
# File 'lib/rfm/database.rb', line 96 def account_name=(x); config :account_name=>x; end |
#name ⇒ Object
94 |
# File 'lib/rfm/database.rb', line 94 def name; state[:database].to_s; end |
#password ⇒ Object
97 |
# File 'lib/rfm/database.rb', line 97 def password; state[:password]; end |
#password=(x) ⇒ Object
98 |
# File 'lib/rfm/database.rb', line 98 def password=(x); config :password=>x; end |
#state(*args) ⇒ Object
100 101 102 |
# File 'lib/rfm/database.rb', line 100 def state(*args) get_config(*args) end |