Module: Rfm::Layout::LayoutModule
- Included in:
- Rfm::Layout, SubLayout
- Defined in:
- lib/rfm/layout.rb
Overview
These methods are to be inclulded in Layout and SubLayout, so that they have their own discrete ‘self’ in the master class and the subclass. This means these methods will not get forwarded, and will talk to the correct variables & objects of the correct self. Do not get or set instance variables in Layout from other objects directly, always use getter & setter methods. This all means that any chain of methods that want to refer ultimately to Sublayout, must all be defined or included in Sublayout
Instance Method Summary collapse
-
#all(options = {}) ⇒ Object
Returns a ResultSet object containing _every record_ in the table associated with this layout.
-
#any(options = {}) ⇒ Object
Returns a ResultSet containing a single random record from the table associated with this layout.
-
#create(values, options = {}) ⇒ Object
Creates a new record in the table associated with this layout.
-
#delete(recid, options = {}) ⇒ Object
Deletes the record with the specified internal recid.
-
#edit(recid, values, options = {}) ⇒ Object
Updates the contents of the record whose internal
recid
is specified. -
#expand_repeats(hash) ⇒ Object
Intended to set each repeat individually but doesn’t work with FM.
-
#find(find_criteria, options = {}) ⇒ Object
If you pass anything other than a hash or an array as the first parameter, it is converted to a string and assumed to be FileMaker’s internal id for a record (the recid).
- #get_records(action, extra_params = {}, options = {}) ⇒ Object
-
#join_repeats(hash) ⇒ Object
Intended to brute-force repeat setting but doesn’t work with FM.
- #name ⇒ Object
- #params ⇒ Object
-
#query(query_hash, options = {}) ⇒ Object
Access to raw -findquery command.
- #state(*args) ⇒ Object
-
#view(options = {}) ⇒ Object
Retrieves metadata only, with an empty resultset.
Instance Method Details
#all(options = {}) ⇒ Object
Returns a ResultSet object containing _every record_ in the table associated with this layout.
178 179 180 |
# File 'lib/rfm/layout.rb', line 178 def all( = {}) get_records('-findall', {}, ) end |
#any(options = {}) ⇒ Object
Returns a ResultSet containing a single random record from the table associated with this layout.
183 184 185 |
# File 'lib/rfm/layout.rb', line 183 def any( = {}) get_records('-findany', {}, ) end |
#create(values, options = {}) ⇒ Object
Creates a new record in the table associated with this layout. Pass field data as a hash in the values
parameter. Returns the newly created record in a RecordSet. You can use the returned record to, ie, discover the values in auto-enter fields (like serial numbers).
For example:
result = myLayout.create({"First Name" => "Jerry", "Last Name" => "Robin"})
id = result[0]["ID"]
The above code adds a new record with first name Jerry and last name Robin. It then puts the value from the ID field (a serial number) into a ruby variable called id
.
246 247 248 |
# File 'lib/rfm/layout.rb', line 246 def create(values, = {}) get_records('-new', values, ) end |
#delete(recid, options = {}) ⇒ Object
Deletes the record with the specified internal recid. Returns a ResultSet with the deleted record.
For example:
recid = myLayout.find({"First Name" => "Bill"})[0].record_id
myLayout.delete(recid)
The above code finds every record with Bill in the First Name field, then deletes the first one.
258 259 260 261 |
# File 'lib/rfm/layout.rb', line 258 def delete(recid, = {}) get_records('-delete', {'-recid' => recid}, ) return nil end |
#edit(recid, values, options = {}) ⇒ Object
Updates the contents of the record whose internal recid
is specified. Send in a hash of new data in the values
parameter. Returns a RecordSet containing the modified record. For example:
recid = myLayout.find({"First Name" => "Bill"})[0].record_id
myLayout.edit(recid, {"First Name" => "Steve"})
The above code would find the first record with Bill in the First Name field and change the first name to Steve.
230 231 232 233 |
# File 'lib/rfm/layout.rb', line 230 def edit(recid, values, = {}) get_records('-edit', {'-recid' => recid}.merge(values), ) #get_records('-edit', {'-recid' => recid}.merge(expand_repeats(values)), options) # attempt to set repeating fields. end |
#expand_repeats(hash) ⇒ Object
Intended to set each repeat individually but doesn’t work with FM
293 294 295 296 297 298 299 300 301 |
# File 'lib/rfm/layout.rb', line 293 def (hash) hash.each do |key,val| if val.kind_of? Array val.each_with_index{|v, i| hash["#{key}(#{i+1})"] = v} hash.delete(key) end end hash end |
#find(find_criteria, options = {}) ⇒ Object
If you pass anything other than a hash or an array as the first parameter, it is converted to a string and assumed to be FileMaker’s internal id for a record (the recid).
myLayout.find 54321
211 212 213 214 215 |
# File 'lib/rfm/layout.rb', line 211 def find(find_criteria, = {}) #puts "layout.find-#{self.object_id}" .merge!({:field_mapping => field_mapping}) if field_mapping get_records(*Rfm::CompoundQuery.new(find_criteria, )) end |
#get_records(action, extra_params = {}, options = {}) ⇒ Object
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
# File 'lib/rfm/layout.rb', line 268 def get_records(action, extra_params = {}, = {}) # TODO: The grammar stuff here won't work properly until you handle config between # models/sublayouts/layout/server (Is this done now?). grammar_option = state()[:grammar] .merge!(:grammar=>grammar_option) if grammar_option #include_portals = options[:include_portals] ? options.delete(:include_portals) : nil include_portals = ![:ignore_portals] # Apply mapping from :field_mapping, to send correct params in URL. prms = params.merge(extra_params) map = field_mapping.invert # TODO: Make this part handle string AND symbol keys. #map.each{|k,v| prms[k]=prms.delete(v) if prms[v]} prms.dup.each_key{|k| prms[map[k.to_s]]=prms.delete(k) if map[k.to_s]} xml_response = server.connect(state[:account_name], state[:password], action, prms, ).body Rfm::Resultset.new(xml_response, self, include_portals) end |
#join_repeats(hash) ⇒ Object
Intended to brute-force repeat setting but doesn’t work with FM
304 305 306 307 308 309 310 311 |
# File 'lib/rfm/layout.rb', line 304 def join_repeats(hash) hash.each do |key,val| if val.kind_of? Array hash[key] = val.join('\x1D') end end hash end |
#name ⇒ Object
313 |
# File 'lib/rfm/layout.rb', line 313 def name; state[:layout].to_s; end |
#params ⇒ Object
287 288 289 |
# File 'lib/rfm/layout.rb', line 287 def params {"-db" => db.name, "-lay" => self.name} end |
#query(query_hash, options = {}) ⇒ Object
Access to raw -findquery command.
218 219 220 |
# File 'lib/rfm/layout.rb', line 218 def query(query_hash, = {}) get_records('-findquery', query_hash, ) end |
#state(*args) ⇒ Object
315 316 317 |
# File 'lib/rfm/layout.rb', line 315 def state(*args) get_config(*args) end |
#view(options = {}) ⇒ Object
Retrieves metadata only, with an empty resultset.
264 265 266 |
# File 'lib/rfm/layout.rb', line 264 def view( = {}) get_records('-view', {}, ) end |