Sha256: 75c330f512abdf277b929bc4129a64855c7b04778bc9941941ff7bb1697d2172

Contents?: true

Size: 1.4 KB

Versions: 6

Compression:

Stored size: 1.4 KB

Contents

module RailsConnector

  # This is the abstract class from which all CMS models derive.
  # The database connection is set to "infopark_rails_connector_${RAILS_ENV}" and the table prefix is
  # determined from the instance_name.
  #
  # [instance_name] the name of the CMS instance
  class CmsBaseModel < ActiveRecord::Base #:nodoc:
    @@instance_name = 'default'
    cattr_accessor :instance_name
    self.abstract_class = true

    def self.configure_database(db_connection_spec)
      establish_connection(db_connection_spec)
      Blob.initialize_blob_streaming_for(connection.adapter_name)
    end

    # Returns :table_name_with_underscore. All CMS models use this kind of primary key naming.
    def self.primary_key_prefix_type
      :table_name_with_underscore
    end

    # CmsBaseModel and all of its descendants are model classes that can access CMS contents.
    def self.cms_model?
      true
    end

    def readonly?
      true
    end

    class << self
      # The prefix of the table name is determined by using the instance name followed by an underscore.
      # Set the instance_name in your environment to the CMS instance name (defaults to 'default').
      #
      #   CmsBaseModel.instance_name = 'default'
      #
      # ActiveRecord::Base::primary_key_prefix_type has no effect here.
      def table_name_prefix
        @@instance_name.blank? ? '' : (@@instance_name + '_')
      end
    end
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
infopark_fiona_connector-6.8.0.210.ed204b0 lib/rails_connector/cms_base_model.rb
infopark_fiona_connector-6.8.0.110.6570b45 lib/rails_connector/cms_base_model.rb
infopark_fiona_connector-6.8.0.72.d18d096 lib/rails_connector/cms_base_model.rb
infopark_fiona_connector-6.8.0.23.da7f96b lib/rails_connector/cms_base_model.rb
infopark_fiona_connector-6.8.0.16.def5e85 lib/rails_connector/cms_base_model.rb
infopark_fiona_connector-6.8.0.beta.200.891.647580e lib/rails_connector/cms_base_model.rb