Class: Bricolage::TableSpec
- Inherits:
-
Object
- Object
- Bricolage::TableSpec
- Defined in:
- lib/bricolage/sqlstatement.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Class Method Summary collapse
-
.parse(spec) ⇒ Object
“[SCHEMA.]TABLE” -> TableSpec(SCHEMA, TABLE).
-
.split_name(name_pair) ⇒ Object
“TABLE” -> [nil, “TABLE”] “SCHEMA.TABLE” -> [“SCHEMA”, “TABLE”].
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(schema, name) ⇒ TableSpec
constructor
A new instance of TableSpec.
- #inspect ⇒ Object
- #to_s ⇒ Object
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
#name ⇒ Object (readonly)
Returns the value of attribute name.
329 330 331 |
# File 'lib/bricolage/sqlstatement.rb', line 329 def name @name end |
#schema ⇒ Object (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”]
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 |
#hash ⇒ Object
346 347 348 |
# File 'lib/bricolage/sqlstatement.rb', line 346 def hash @schema.hash ^ @name.hash end |
#inspect ⇒ Object
335 336 337 |
# File 'lib/bricolage/sqlstatement.rb', line 335 def inspect "\#<#{self.class} #{to_s}>" end |
#to_s ⇒ Object
331 332 333 |
# File 'lib/bricolage/sqlstatement.rb', line 331 def to_s @schema ? "#{@schema}.#{@name}" : @name end |