Class: Sequel::Extension::PgComment::PrefixSqlGenerator

Inherits:
SqlGenerator
  • Object
show all
Defined in:
lib/sequel/extensions/pg_comment/sql_generator.rb

Overview

:nodoc: This is an annoying corner-case generator -- it doesn't handle any types by default, but it will handle any other type where the name of a table needs to be prefixed by a name. The only known use case for this at present is "implicit" (that is, automatically generated by the database) constraints and indexes that get prefixed by the table name, and which are generated at a time when the calling code doesn't know the name of the table that it is generating SQL for.

Constant Summary collapse

OBJECT_TYPES =

This class doesn't handle any object types directly, and must be instantiated directly when needed

%w{}

Instance Attribute Summary collapse

Attributes inherited from SqlGenerator

#comment, #object_name, #object_type

Instance Method Summary collapse

Methods inherited from SqlGenerator

create, handles?, #initialize

Constructor Details

This class inherits a constructor from Sequel::Extension::PgComment::SqlGenerator

Instance Attribute Details

#table_nameObject

The name of the table which should be prefixed to the object name that was specified when this instance was created.



233
234
235
# File 'lib/sequel/extensions/pg_comment/sql_generator.rb', line 233

def table_name
  @table_name
end

Instance Method Details

#generateObject

Generate super-dooper special SQL.

See Also:

  • Sequel::Extension::PgComment::PrefixSqlGenerator.{SqlGenerator{SqlGenerator#generate}


239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/sequel/extensions/pg_comment/sql_generator.rb', line 239

def generate
  if table_name.nil?
    raise ArgumentError,
          "Cannot generate SQL for #{object_type} #{object_name} " +
            "without a table_name"
  end

  prefixed_object_name = "#{table_name}#{object_name}"
  
  if Symbol === table_name || Symbol === object_name
    prefixed_object_name = prefixed_object_name.to_sym
  end

  g = SqlGenerator.create(object_type, prefixed_object_name, comment)
  g.table_name = table_name if g.respond_to? :table_name
  g.generate
end