Class: Table
- Inherits:
-
Object
- Object
- Table
- Defined in:
- lib/tasks/db.rb
Instance Attribute Summary collapse
-
#columns ⇒ Object
Returns the value of attribute columns.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#opts ⇒ Object
Returns the value of attribute opts.
-
#perms_for_user ⇒ Object
Returns the value of attribute perms_for_user.
Instance Method Summary collapse
- #grant(*args, to: nil) ⇒ Object
-
#initialize ⇒ Table
constructor
A new instance of Table.
- #method_missing(method_sym, *arguments, &block) ⇒ Object
- #revoke(*args, from: nil) ⇒ Object
Constructor Details
#initialize ⇒ Table
Returns a new instance of Table.
310 311 312 |
# File 'lib/tasks/db.rb', line 310 def initialize() @columns = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_sym, *arguments, &block) ⇒ Object
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 |
# File 'lib/tasks/db.rb', line 330 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
#columns ⇒ Object
Returns the value of attribute columns.
308 309 310 |
# File 'lib/tasks/db.rb', line 308 def columns @columns end |
#id ⇒ Object
Returns the value of attribute id.
308 309 310 |
# File 'lib/tasks/db.rb', line 308 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
308 309 310 |
# File 'lib/tasks/db.rb', line 308 def name @name end |
#opts ⇒ Object
Returns the value of attribute opts.
308 309 310 |
# File 'lib/tasks/db.rb', line 308 def opts @opts end |
#perms_for_user ⇒ Object
Returns the value of attribute perms_for_user.
308 309 310 |
# File 'lib/tasks/db.rb', line 308 def perms_for_user @perms_for_user end |
Instance Method Details
#grant(*args, to: nil) ⇒ Object
314 315 316 317 318 319 320 |
# File 'lib/tasks/db.rb', line 314 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
322 323 324 325 326 327 328 |
# File 'lib/tasks/db.rb', line 322 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 |