Sha256: 3d07cd0270fc19de4da526666ab8489e25ac61acf93cfeaa2fb23e4f56ea218a
Contents?: true
Size: 1.94 KB
Versions: 6
Compression:
Stored size: 1.94 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 # FIXME: Find a more stable solution for this # # Since ActiveRecord 4.2 finding Objs by name is no longer consistent when # switching between edited and released content at runtime. As long as we # find a better solution this mitigates the behaviour. def self.find_by(arg, *args) where(arg, *args).take end def readonly? true end def attribute_for_inspect(attr_name) value = read_attribute(attr_name) if value.is_a?(RailsConnector::LinkList) value.destination_objects.map(&:to_s) else super end 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