Class: Table

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTable

Returns a new instance of Table.



342
343
344
# File 'lib/tasks/db.rb', line 342

def initialize()
  @columns = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_sym, *arguments, &block) ⇒ Object



362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
# File 'lib/tasks/db.rb', line 362

def method_missing(method_sym, *arguments, &block)
  c = Column.new
  c.type = method_sym.to_s
  c.name = arguments[0]
  c.opts = arguments[1]
  if c.opts
    c.opts[:default] = normalize_default(c.opts[:default]) if c.opts[:default].present?
    c.default = c.opts[:default]
    c.null = c.opts[:null]
    aka = c.opts[:aka]
    if !aka.nil?
      if aka.respond_to?('each')
        c.akas = aka
      else
        c.akas = [aka]
      end
    end
    fk = c.opts.delete(:fk)
    if fk.present?
      if fk.respond_to?('each')
        add_foreign_key self.name, fk[0], column: c.name, primary_key: fk[1]
      else
        add_foreign_key self.name, fk, column: c.name
      end
    end
  else
    c.opts = {}
  end
  @columns.append c
end

Instance Attribute Details

#columnsObject

Returns the value of attribute columns.



340
341
342
# File 'lib/tasks/db.rb', line 340

def columns
  @columns
end

#idObject

Returns the value of attribute id.



340
341
342
# File 'lib/tasks/db.rb', line 340

def id
  @id
end

#nameObject

Returns the value of attribute name.



340
341
342
# File 'lib/tasks/db.rb', line 340

def name
  @name
end

#optsObject

Returns the value of attribute opts.



340
341
342
# File 'lib/tasks/db.rb', line 340

def opts
  @opts
end

#perms_for_userObject

Returns the value of attribute perms_for_user.



340
341
342
# File 'lib/tasks/db.rb', line 340

def perms_for_user
  @perms_for_user
end

Instance Method Details

#grant(*args, to: nil) ⇒ Object



346
347
348
349
350
351
352
# File 'lib/tasks/db.rb', line 346

def grant *args, to: nil
  to = $db_username if to.nil?
  $check_perms_for.add(to)
  args.each do |arg|
    @perms_for_user[to] |= check_perm(arg)
  end
end

#revoke(*args, from: nil) ⇒ Object



354
355
356
357
358
359
360
# File 'lib/tasks/db.rb', line 354

def revoke *args, from: nil
  from = $db_username if from.nil?
  $check_perms_for.add(from)
  args.each do |arg|
    @perms_for_user[from] -= check_perm(arg)
  end
end