Class: QuickBase::Objects::Table

Inherits:
Object
  • Object
show all
Defined in:
lib/QuickBaseObjects.rb

Overview

Definition of a Table built from the XML schema for the table.

Direct Known Subclasses

Application

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pnoun = nil) ⇒ Table

Returns a new instance of Table.



161
162
163
# File 'lib/QuickBaseObjects.rb', line 161

def initialize(pnoun=nil)
    @pnoun = pnoun || "Records"
end

Instance Attribute Details

#dbidObject (readonly)

Returns the value of attribute dbid.



160
161
162
# File 'lib/QuickBaseObjects.rb', line 160

def dbid
  @dbid
end

#descObject (readonly)

Returns the value of attribute desc.



160
161
162
# File 'lib/QuickBaseObjects.rb', line 160

def desc
  @desc
end

#fieldsObject (readonly)

Returns the value of attribute fields.



160
161
162
# File 'lib/QuickBaseObjects.rb', line 160

def fields
  @fields
end

#infoObject (readonly)

Returns the value of attribute info.



160
161
162
# File 'lib/QuickBaseObjects.rb', line 160

def info
  @info
end

#nameObject (readonly)

Returns the value of attribute name.



160
161
162
# File 'lib/QuickBaseObjects.rb', line 160

def name
  @name
end

#pnounObject (readonly)

Returns the value of attribute pnoun.



160
161
162
# File 'lib/QuickBaseObjects.rb', line 160

def pnoun
  @pnoun
end

#queriesObject (readonly)

Returns the value of attribute queries.



160
161
162
# File 'lib/QuickBaseObjects.rb', line 160

def queries
  @queries
end

#tablesObject (readonly)

Returns the value of attribute tables.



160
161
162
# File 'lib/QuickBaseObjects.rb', line 160

def tables
  @tables
end

Instance Method Details

#addField(field) ⇒ Object



219
220
221
222
223
224
# File 'lib/QuickBaseObjects.rb', line 219

def addField(field)
  raise "#{field} is not a Field object." if ! field.is_a?(Field)
  field.id = @qbc.addField(@dbid,field.name,field.type)
  @fields[field.id] = field
  addFieldMethods(field)
end

#addFieldMethods(field) ⇒ Object



216
217
218
# File 'lib/QuickBaseObjects.rb', line 216

def addFieldMethods(field)
   self.class.send(:define_method,"f#{field.name}") {@fields[field.id]}  
end

#addPageMethods(page) ⇒ Object



293
294
295
296
297
298
299
# File 'lib/QuickBaseObjects.rb', line 293

def addPageMethods(page)
  self.class.send(:define_method,"p#{page.name.strip.gsub(' ','_')}"){@pages[page.id]}
  self.class.send(:define_method,"p#{page.name.strip.gsub(' ','_')}="){|pagebody|
     @pages[page.id].content = pagebody.dup
     @qbc.addReplaceDBPage(@dbid, page.id, nil, nil, pagebody)
  }
end

#addTableMethods(table) ⇒ Object



264
265
266
# File 'lib/QuickBaseObjects.rb', line 264

def addTableMethods(table)
    self.class.send(:define_method,"t#{table.name.strip.gsub(' ','_')}"){@tables[table.dbid]}
end

#addUserMethods(user) ⇒ Object



320
321
322
# File 'lib/QuickBaseObjects.rb', line 320

def addUserMethods(user)
   self.class.send(:define_method,"u#{user.name.strip.gsub(' ','_')}"){@users[user.id]}
end

#addVariableMethods(variable) ⇒ Object



245
246
247
248
249
250
251
# File 'lib/QuickBaseObjects.rb', line 245

def addVariableMethods(variable)
  self.class.send(:define_method,"v#{variable.name}") {@variables[variable.name].value}       
  self.class.send(:define_method,"v#{variable.name}=") {|valueToAssign|
     @variables[variable.name].value = valueToAssign
     @qbc.setDBVar(@dbid,variable.name,valueToAssign)
  }
end

#build(qbc, appTable = false) ⇒ Object



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/QuickBaseObjects.rb', line 164

def build(qbc,appTable=false)
  @qbc = qbc
  @dbid = qbc.dbid.dup
  @name = qbc.dbname.dup if qbc.dbname
  buildInfo
  buildFields
  buildQueries
  if appTable
     buildAppInfo
     buildVariables
     buildPages
     buildRoles
     buildUsers
     buildTables
  end
  self
end

#buildAppInfoObject



192
193
194
195
# File 'lib/QuickBaseObjects.rb', line 192

def buildAppInfo      
    buildInfoField("requestTime",@qbc.requestTime)
    buildInfoField("requestNextAllowedTime",@qbc.requestNextAllowedTime)
end

#buildField(field_xml) ⇒ Object



210
211
212
213
214
215
# File 'lib/QuickBaseObjects.rb', line 210

def buildField(field_xml)
  field = Field.new
  field.build(field_xml,@qbc)
  @fields[field.id] = field
  addFieldMethods(field)
end

#buildFieldsObject



201
202
203
204
205
206
207
208
209
# File 'lib/QuickBaseObjects.rb', line 201

def buildFields
  @fields ||= Fields.new
  fieldsProc = proc { |element|
      if element.is_a?(REXML::Element) and element.name == "field"
         buildField(element)
      end
   }
  @qbc.processChildElements(@qbc.fields,false,fieldsProc)
end

#buildInfoObject



181
182
183
184
185
186
187
188
189
190
191
# File 'lib/QuickBaseObjects.rb', line 181

def buildInfo
  buildInfoField("lastRecModTime",@qbc.lastRecModTime)
  buildInfoField("lastModifiedTime",@qbc.lastModifiedTime)
  buildInfoField("createdTime",@qbc.createdTime)
  buildInfoField("lastAccessTime",@qbc.lastAccessTime)
  buildInfoField("numRecords",@qbc.numRecords)
  buildInfoField("mgrID",@qbc.mgrID)
  buildInfoField("mgrName",@qbc.mgrName)
  buildInfoField("dbname",@qbc.dbname)
  buildInfoField("version",@qbc.version)
end

#buildInfoField(key, value) ⇒ Object



196
197
198
199
200
# File 'lib/QuickBaseObjects.rb', line 196

def buildInfoField(key,value)
  @info ||= Info.new
  @info[key] = value
  self.class.send(:define_method,"i#{key}") {@info[key]}    
end

#buildPage(pageHash) ⇒ Object



287
288
289
290
291
292
# File 'lib/QuickBaseObjects.rb', line 287

def buildPage(pageHash)
  page = Page.new
  page.build(pageHash)
  @pages[page.id]=page
  addPageMethods(page)
end

#buildPagesObject



282
283
284
285
286
# File 'lib/QuickBaseObjects.rb', line 282

def buildPages
  @pages ||= Pages.new
  pageList = @qbc.getDBPagesAsArray(@dbid)
  pageList.each{|pageHash|buildPage(pageHash)}
end

#buildQueriesObject



267
268
269
270
271
272
273
274
275
# File 'lib/QuickBaseObjects.rb', line 267

def buildQueries
  @queries ||= Queries.new
  queriesProc = proc { |element|
      if element.is_a?(REXML::Element) and element.name == "query"
         buildQuery(element)
      end
   }
  @qbc.processChildElements(@qbc.queries,false,queriesProc)
end

#buildQuery(query_xml) ⇒ Object



276
277
278
279
280
281
# File 'lib/QuickBaseObjects.rb', line 276

def buildQuery(query_xml)
  query = Query.new
  query.build(query_xml,@qbc)
  @queries[query.id] = query
  self.class.send(:define_method,"q#{query.name.strip.gsub(' ','_')}"){@queries[query.id]}
end

#buildRole(role_xml) ⇒ Object



304
305
306
307
308
309
# File 'lib/QuickBaseObjects.rb', line 304

def buildRole(role_xml)
  role = Role.new
  role.build(role_xml,@qbc)
  @roles[role.id] = role
  self.class.send(:define_method,"r#{role.name.strip.gsub(' ','_')}"){@roles[role.id]}
end

#buildRolesObject



300
301
302
303
# File 'lib/QuickBaseObjects.rb', line 300

def buildRoles
  @roles ||= Roles.new
  @qbc.getRoleInfo( @dbid ) {|role|buildRole(role)}
end

#buildTable(dbid) ⇒ Object



256
257
258
259
260
261
262
263
# File 'lib/QuickBaseObjects.rb', line 256

def buildTable(dbid)
  table = Table.new
  @qbc.getDBInfo(dbid)
  @qbc.getSchema(dbid)
  table.build(@qbc)
  @tables[dbid] = table
  addTableMethods(table)
end

#buildTablesObject



252
253
254
255
# File 'lib/QuickBaseObjects.rb', line 252

def buildTables
  @tables ||= Tables.new
  @qbc.getTableIDs(@dbid).each { |chdbid| buildTable(chdbid) }
end

#buildUser(user_role_xml) ⇒ Object



314
315
316
317
318
319
# File 'lib/QuickBaseObjects.rb', line 314

def buildUser(user_role_xml)
  user = User.new
  user.build(user_role_xml,@qbc)
  @users[user.id] = user
  addUserMethods(user)
end

#buildUsersObject



310
311
312
313
# File 'lib/QuickBaseObjects.rb', line 310

def buildUsers
  @users ||= Users.new
  @qbc.userRoles(@dbid){|user_role_xml|buildUser(user_role_xml)}
end

#buildVariable(key, value) ⇒ Object



239
240
241
242
243
244
# File 'lib/QuickBaseObjects.rb', line 239

def buildVariable(key,value)
  variable = Variable.new
  variable.build(key,value)
  @variables[key] = variable
  addVariableMethods(variable)
end

#buildVariablesObject



235
236
237
238
# File 'lib/QuickBaseObjects.rb', line 235

def buildVariables
  @variables ||= Variables.new
  @qbc.getApplicationVariables.each{|key,value| buildVariable(key,value)}
end

#deleteField(field) ⇒ Object



225
226
227
228
229
230
# File 'lib/QuickBaseObjects.rb', line 225

def deleteField(field)
   raise "#{field} is not a Field object." if ! field.is_a?(Field)
   removeFieldMethods(field)
   @fields.delete(field.id)
   @qbc.deleteField(@dbid,field.id)
end

#removeFieldMethods(field) ⇒ Object



231
232
233
234
# File 'lib/QuickBaseObjects.rb', line 231

def removeFieldMethods(field)
   raise "#{field} is not a Field object." if ! field.is_a?(Field)
   self.class.send(:remove_method,"f#{field.name}")  
end

#runImport(importid) ⇒ Object



323
324
325
# File 'lib/QuickBaseObjects.rb', line 323

def runImport(importid)
  @qbc.runImport(@dbid,importid)
end