Sha256: 7d212aad931e14552f4fb33408674a72c219206c5bcb0efad9fc7f73929bf2a0

Contents?: true

Size: 1.08 KB

Versions: 153

Compression:

Stored size: 1.08 KB

Contents

# frozen-string-literal: true

module Sequel
  module Plugins
    # The singular_table_names plugin changes the default
    # table names for subclasses to not assume a plural version.
    # By default, Sequel assumes table names for models use
    # the plural versions.
    #
    # Note that this plugin only affects subclasses of the
    # class it is loaded into, it does not affect the
    # current class.  So it only makes sense to load this
    # into Sequel::Model itself, or a subclass of Sequel::Model
    # that is created via Class.new.
    #
    # Usage:
    #
    #   # Don't assume pluralized table names
    #   Sequel::Model.plugin :singular_table_names
    module SingularTableNames
      module ClassMethods
        # Returns the implicit table name for the model class, which is the demodulized,
        # underscored, name of the class.
        #
        #   Artist.implicit_table_name # => :artist
        #   Foo::ArtistAlias.implicit_table_name # => :artist_alias
        def implicit_table_name
          underscore(demodulize(name)).to_sym
        end
      end
    end
  end
end

Version data entries

153 entries across 134 versions & 2 rubygems

Version Path
sequel-5.86.0 lib/sequel/plugins/singular_table_names.rb
sequel-5.85.0 lib/sequel/plugins/singular_table_names.rb
sequel-5.84.0 lib/sequel/plugins/singular_table_names.rb
sequel-5.83.1 lib/sequel/plugins/singular_table_names.rb
sequel-5.83.0 lib/sequel/plugins/singular_table_names.rb
sequel-5.82.0 lib/sequel/plugins/singular_table_names.rb
sequel-5.81.0 lib/sequel/plugins/singular_table_names.rb
sequel-5.80.0 lib/sequel/plugins/singular_table_names.rb
sequel-5.79.0 lib/sequel/plugins/singular_table_names.rb
sequel-5.78.0 lib/sequel/plugins/singular_table_names.rb
sequel-5.77.0 lib/sequel/plugins/singular_table_names.rb
sequel-5.76.0 lib/sequel/plugins/singular_table_names.rb
sequel-5.75.0 lib/sequel/plugins/singular_table_names.rb
sequel-5.74.0 lib/sequel/plugins/singular_table_names.rb
sequel-5.73.0 lib/sequel/plugins/singular_table_names.rb
sequel-5.72.0 lib/sequel/plugins/singular_table_names.rb
sequel-5.71.0 lib/sequel/plugins/singular_table_names.rb
sequel-5.70.0 lib/sequel/plugins/singular_table_names.rb
sequel-5.69.0 lib/sequel/plugins/singular_table_names.rb
sequel-5.68.0 lib/sequel/plugins/singular_table_names.rb