Sha256: acd78c9a8eb65593c32c6a19af2158f731640f50afe75ebdcf475f1d7c34243f

Contents?: true

Size: 1.39 KB

Versions: 29

Compression:

Stored size: 1.39 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
    @@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

29 entries across 29 versions & 1 rubygems

Version Path
infopark_fiona_connector-7.0.0 lib/rails_connector/cms_base_model.rb
infopark_fiona_connector-6.10.0.beta1 lib/rails_connector/cms_base_model.rb
infopark_fiona_connector-6.9.4 lib/rails_connector/cms_base_model.rb
infopark_fiona_connector-6.9.3.1.36404185 lib/rails_connector/cms_base_model.rb
infopark_fiona_connector-6.9.2.1.125136549 lib/rails_connector/cms_base_model.rb
infopark_fiona_connector-6.9.1.3.22208381 lib/rails_connector/cms_base_model.rb
infopark_fiona_connector-6.9.0.3.197272233 lib/rails_connector/cms_base_model.rb
infopark_fiona_connector-6.8.3.174.51542603 lib/rails_connector/cms_base_model.rb
infopark_fiona_connector-6.8.3.115.227021242 lib/rails_connector/cms_base_model.rb
infopark_fiona_connector-6.8.3.73.75172665 lib/rails_connector/cms_base_model.rb
infopark_fiona_connector-6.8.3.2.153416031 lib/rails_connector/cms_base_model.rb
infopark_fiona_connector-6.8.3.67.110847540 lib/rails_connector/cms_base_model.rb
infopark_fiona_connector-6.8.3.1.23895778 lib/rails_connector/cms_base_model.rb
infopark_fiona_connector-6.8.2.36.82613853 lib/rails_connector/cms_base_model.rb
infopark_fiona_connector-6.8.2.7.128454143 lib/rails_connector/cms_base_model.rb
infopark_fiona_connector-6.8.1.26.236500544 lib/rails_connector/cms_base_model.rb
infopark_fiona_connector-6.8.1 lib/rails_connector/cms_base_model.rb
infopark_fiona_connector-6.8.0.539.93842523 lib/rails_connector/cms_base_model.rb
infopark_fiona_connector-6.8.0.529.114081979 lib/rails_connector/cms_base_model.rb
infopark_fiona_connector-6.8.0.518.30999728 lib/rails_connector/cms_base_model.rb