Class: Bricolage::TableSpec

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema, name) ⇒ TableSpec

Returns a new instance of TableSpec.



323
324
325
326
# File 'lib/bricolage/sqlstatement.rb', line 323

def initialize(schema, name)
  @schema = schema
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



329
330
331
# File 'lib/bricolage/sqlstatement.rb', line 329

def name
  @name
end

#schemaObject (readonly)

Returns the value of attribute schema.



328
329
330
# File 'lib/bricolage/sqlstatement.rb', line 328

def schema
  @schema
end

Class Method Details

.parse(spec) ⇒ Object

“[SCHEMA.]TABLE” -> TableSpec(SCHEMA, TABLE)



304
305
306
# File 'lib/bricolage/sqlstatement.rb', line 304

def TableSpec.parse(spec)
  new(*split_name(spec))
end

.split_name(name_pair) ⇒ Object

“TABLE” -> [nil, “TABLE”] “SCHEMA.TABLE” -> [“SCHEMA”, “TABLE”]

Raises:



310
311
312
313
314
315
316
317
318
319
320
321
# File 'lib/bricolage/sqlstatement.rb', line 310

def TableSpec.split_name(name_pair)
  raise ParameterError, "table spec is empty" if name_pair.strip.empty?
  components = name_pair.split('.', 2)
  if components.size == 1
    return nil, components.first
  else
    s, t = components
    raise ParameterError, "schema name is blank" if not s or s.empty?
    raise ParameterError, "table name is blank" if not t or t.empty?
    return s, t
  end
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



339
340
341
342
# File 'lib/bricolage/sqlstatement.rb', line 339

def ==(other)
  return false unless other.kind_of?(TableSpec)
  @schema == other.schema and @name == other.name
end

#hashObject



346
347
348
# File 'lib/bricolage/sqlstatement.rb', line 346

def hash
  @schema.hash ^ @name.hash
end

#inspectObject



335
336
337
# File 'lib/bricolage/sqlstatement.rb', line 335

def inspect
  "\#<#{self.class} #{to_s}>"
end

#to_sObject



331
332
333
# File 'lib/bricolage/sqlstatement.rb', line 331

def to_s
  @schema ? "#{@schema}.#{@name}" : @name
end