Class: Rfm::Resultset
- Includes:
- Config
- Defined in:
- lib/rfm/resultset.rb
Overview
The ResultSet object represents a set of records in FileMaker. It is, in every way, a real Ruby Array, so everything you expect to be able to do with an Array can be done with a ResultSet as well. In this case, the elements in the array are Record objects.
Here’s a typical example, displaying the results of a Find:
myServer = Rfm::Server.new(...)
results = myServer["Customers"]["Details"].find("First Name" => "Bill")
results.each {|record|
puts record["First Name"]
puts record["Last Name"]
puts record["Email Address"]
}
Attributes
The ResultSet object has these attributes:
-
field_meta is a hash with field names for keys and Field objects for values; it provides info about the fields in the ResultSet
-
portal_meta is a hash with table occurrence names for keys and arrays of Field objects for values; it provides metadata about the portals in the ResultSet and the Fields on those portals
Instance Attribute Summary collapse
-
#caller ⇒ Object
readonly
Returns the value of attribute caller.
-
#database ⇒ Object
(also: #db)
readonly
Returns the value of attribute database.
-
#datasource ⇒ Object
readonly
Returns the value of attribute datasource.
-
#date_format ⇒ Object
readonly
Returns the value of attribute date_format.
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
-
#field_meta ⇒ Object
readonly
Returns the value of attribute field_meta.
-
#foundset_count ⇒ Object
readonly
Returns the value of attribute foundset_count.
-
#include_portals ⇒ Object
readonly
Returns the value of attribute include_portals.
-
#layout ⇒ Object
readonly
Returns the value of attribute layout.
-
#portal_meta ⇒ Object
readonly
Returns the value of attribute portal_meta.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
-
#table ⇒ Object
readonly
Returns the value of attribute table.
-
#time_format ⇒ Object
readonly
Returns the value of attribute time_format.
-
#timestamp_format ⇒ Object
readonly
Returns the value of attribute timestamp_format.
-
#total_count ⇒ Object
readonly
Returns the value of attribute total_count.
Instance Method Summary collapse
- #field_names ⇒ Object
-
#initialize(*args) ⇒ Resultset
constructor
Initializes a new ResultSet object.
- #portal_names ⇒ Object
-
#state(*args) ⇒ Object
def self.load_data(file_or_string) self.new(file_or_string, nil) end.
Methods included from Config
#config, #config_clear, #get_config, #sanitize_config
Methods inherited from Array
#rfm_extend_member, #rfm_extend_members, #rfm_extract_options!
Constructor Details
#initialize(*args) ⇒ Resultset
Initializes a new ResultSet object. You will probably never do this your self (instead, use the Layout object to get various ResultSet obejects).
If you feel so inclined, though, pass a Server object, and some fmpxmlresult
compliant XML in a String.
Attributes
The ResultSet object includes several useful attributes:
-
fields is a hash (with field names for keys and Field objects for values). It includes an entry for every field in the ResultSet. Note: You don’t use Field objects to access data. If you’re after data, get a Record object (ResultSet is an array of records). Field objects tell you about the fields (their type, repetitions, and so forth) in case you find that information useful programmatically.
Note: keys in the
fields
hash are downcased for convenience (and [] automatically downcases on lookup, so it should be seamless). But if youeach
a field hash and need to know a field’s real name, with correct case, domyField.name
instead of relying on the key in the hash. -
portals is a hash (with table occurrence names for keys and Field objects for values). If your layout contains portals, you can find out what fields they contain here. Again, if it’s the data you’re after, you want to look at the Record object.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/rfm/resultset.rb', line 73 def initialize(*args) # xml_response, caller, portals #Was (server_obj, xml_response, layout_obj, portals=nil) = args. config :parent=>'caller' config sanitize_config(, {}, true) xml_response = args[0] || [:xml_response] doc = XmlParser.parse(xml_response, :namespace=>false, :parser=>(state[:parser] rescue nil)) error = doc.error check_for_errors(error, (server.state[:raise_on_401] rescue nil)) @doc = doc @caller = args[1] || [:caller] @layout = (@caller.class.ancestors.include? Rfm::Layout::LayoutModule) ? @caller : [:layout_object] @database = (@layout.database rescue nil) || (@caller.class == Rfm::Database ? @caller : [:database_object]) @server = (@database.server rescue nil) || (@caller.class == Rfm::Server ? @caller : [:server_object]) @field_meta ||= Rfm::CaseInsensitiveHash.new @portal_meta ||= Rfm::CaseInsensitiveHash.new @include_portals = args[2] || [:include_portals] @datasource = doc.datasource = doc. resultset = doc.resultset @date_format = doc.date_format @time_format = doc.time_format @timestamp_format = doc. @foundset_count = doc.foundset_count @total_count = doc.total_count @table = doc.table (layout.table = @table) if layout and layout.table_no_load.blank? parse_fields(doc) # This will always load portal meta, even if :include_portals was not specified. # See Record for control of portal data loading. parse_portals(doc) # These were added for loading resultset from file # Kind of a hack. This should ideally condense down to just another option on the main @layout = ... # unless @layout # @layout = @datasource['layout'] # @layout.instance_variable_set '@database', @datasource['database'] # @layout.instance_eval do # def database # @database # end # end # end return if doc.records.blank? Rfm::Record.build_records(doc.records, self, @field_meta, @layout) end |
Instance Attribute Details
#caller ⇒ Object (readonly)
Returns the value of attribute caller.
41 42 43 |
# File 'lib/rfm/resultset.rb', line 41 def caller @caller end |
#database ⇒ Object (readonly) Also known as: db
Returns the value of attribute database.
41 42 43 |
# File 'lib/rfm/resultset.rb', line 41 def database @database end |
#datasource ⇒ Object (readonly)
Returns the value of attribute datasource.
42 43 44 |
# File 'lib/rfm/resultset.rb', line 42 def datasource @datasource end |
#date_format ⇒ Object (readonly)
Returns the value of attribute date_format.
43 44 45 |
# File 'lib/rfm/resultset.rb', line 43 def date_format @date_format end |
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
41 42 43 |
# File 'lib/rfm/resultset.rb', line 41 def doc @doc end |
#field_meta ⇒ Object (readonly)
Returns the value of attribute field_meta.
42 43 44 |
# File 'lib/rfm/resultset.rb', line 42 def @field_meta end |
#foundset_count ⇒ Object (readonly)
Returns the value of attribute foundset_count.
44 45 46 |
# File 'lib/rfm/resultset.rb', line 44 def foundset_count @foundset_count end |
#include_portals ⇒ Object (readonly)
Returns the value of attribute include_portals.
42 43 44 |
# File 'lib/rfm/resultset.rb', line 42 def include_portals @include_portals end |
#layout ⇒ Object (readonly)
Returns the value of attribute layout.
41 42 43 |
# File 'lib/rfm/resultset.rb', line 41 def layout @layout end |
#portal_meta ⇒ Object (readonly)
Returns the value of attribute portal_meta.
42 43 44 |
# File 'lib/rfm/resultset.rb', line 42 def @portal_meta end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
41 42 43 |
# File 'lib/rfm/resultset.rb', line 41 def server @server end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
44 45 46 |
# File 'lib/rfm/resultset.rb', line 44 def table @table end |
#time_format ⇒ Object (readonly)
Returns the value of attribute time_format.
43 44 45 |
# File 'lib/rfm/resultset.rb', line 43 def time_format @time_format end |
#timestamp_format ⇒ Object (readonly)
Returns the value of attribute timestamp_format.
43 44 45 |
# File 'lib/rfm/resultset.rb', line 43 def @timestamp_format end |
#total_count ⇒ Object (readonly)
Returns the value of attribute total_count.
44 45 46 |
# File 'lib/rfm/resultset.rb', line 44 def total_count @total_count end |
Instance Method Details
#field_names ⇒ Object
140 141 142 |
# File 'lib/rfm/resultset.rb', line 140 def field_names .collect{|k,v| v.name} end |
#portal_names ⇒ Object
144 145 146 |
# File 'lib/rfm/resultset.rb', line 144 def portal_names .keys end |
#state(*args) ⇒ Object
def self.load_data(file_or_string)
self.new(file_or_string, nil)
end
136 137 138 |
# File 'lib/rfm/resultset.rb', line 136 def state(*args) get_config(*args) end |