require "helpful_configuration" require 'rails_connector/cms_base_model' require "rails_connector/blob" module RailsConnector # @api public class Configuration # @api public DEFAULT_MODE = :live class << self # there are three available modes for the rails connector: # live (show released contents only), # preview (show edited contents) # editor (show edited contents and editor interface (e.g. edit markers)) # Default mode is live. # @api public attr_accessor :mode # default options for {SearchRequest} # @api public attr_writer :search_options # default options for {SearchRequest} # @api public def search_options @search_options || local_config_file["search"].symbolize_keys end # define a non-default blob cache dir. # +fiona connector+ only. has no effect when used with the +cloud connector+. # @api public attr_accessor :blob_cache_dir # @api public def mode=(new_mode) new_mode = new_mode.to_sym raise ArgumentError, "Unknown Mode #{new_mode}" unless [:editor, :preview, :live].include?(new_mode) @mode = new_mode end # there are three available modes for the rails connector: # live (show released contents only), # preview (show edited contents) # editor (show edited contents and editor interface (e.g. edit markers)) # Default mode is live. # @api public def mode @mode || DEFAULT_MODE end def editor_interface_enabled? mode == :editor end def use_edited_content? mode == :preview || mode == :editor end # Configures your CMS instance name. # # Example call as to be used in rails_connector.rb: # RailsConnector::Configuration.instance_name = 'internet' # @api public def instance_name=(name) RailsConnector::CmsBaseModel.instance_name = name if RailsConnector.platform_fiona? end def after_initialize enable_ses enable_authentication ::RailsConnector::BasicObj.configure_for_content( ::RailsConnector::Configuration.use_edited_content? ? :edited : :released ) end def to_prepare BasicObj.reset_reflections unless Rails.configuration.cache_classes after_initialize NamedLink.reset_cache BasicObj.reset_type_cache ::ApplicationController.__send__(:helper, :cms) end end def configure_cms_database RailsConnector::CmsBaseModel.configure_database(:cms) end attr_accessor :choose_homepage_callback # Configure a callback to be invoked when the rails connector delivers the homepage. # The given callback will receive the rack env # and must return an Obj to be used as the homepage. # If no callback is configured, Obj.homepage will be used as the default. # @api public def choose_homepage(&block) self.choose_homepage_callback = block end def cms_routes(*args) raise <<-EOS.gsub(/\s+/, ' ') Calling RailsConnector::Configuration.cms_routes is not needed anymore. Please remove it from config/routes.rb EOS end def use_x_sendfile=(value) raise 'Configuration.use_x_sendfile is now available as Rails configuration:'\ ' config.action_dispatch.x_sendfile_header = "X-Sendfile"' end def local_config_file @local_config_file ||= read_local_config_file end def local_config_file_name (Rails.root + "config/rails_connector.yml").expand_path end # for test purposes only def reset_local_config_file_cache @local_config_file = nil end protected def enable_authentication ::ApplicationController.__send__(:include, RailsConnector::Authenticable) end def read_local_config_file contents = YAML.load_file(local_config_file_name) if File.exists?(local_config_file_name) contents ||= {} config = HelpfulConfiguration.new( contents, local_config_file_name ) config.explain( "cms_database", "a hash of options, including type, that specify the database configuration" ) config.explain( "cms_blob_storage", "a hash of options, including type, that specify the cms blob storage configuration" ) config.explain( "cms_dict_storage", "a hash of options, including type, that specify the cms dict storage configuration" ) config.explain( "search", "a hash of options that specify access to the search server" ) config.explain( "cms_api", "a hash of options that specify access to the cms api" ) config.explain 'content_service', 'a hash of options that specify access to content service' config end def enable_ses require 'rails_connector/ses' RailsConnector::SES.enable end end end class ConfigurationError < StandardError end end