Class: Scrivito::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/scrivito/configuration.rb

Constant Summary collapse

DEFAULT_CA_FILE =

Default path of a CA certification file in PEM format.

File.expand_path('../../../config/ca-bundle.crt', __FILE__)

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.api_key=(value) ⇒ Object

Sets the API key. This configuration key must be provided.



147
148
149
# File 'lib/scrivito/configuration.rb', line 147

def api_key=(value)
  @api_key = value
end

.ca_fileString

Gets the path of a CA certification file in PEM format.

Returns:

  • (String)


165
166
167
# File 'lib/scrivito/configuration.rb', line 165

def ca_file
  @ca_file
end

.endpoint=(value) ⇒ Object

Sets the API endpoint URL. This configuration key is optional. Default is ‘api.scrivito.com’. If no schema is provided HTTPS is assumed.



157
158
159
# File 'lib/scrivito/configuration.rb', line 157

def endpoint=(value)
  @endpoint = value
end

.ui_localeObject

Configures the in-place UI to use a locale different from the one used by the rest of the application.

Examples:

# The application will use +:de+ as locale.
I18n.locale = :de

Scrivito.configure do |config|
   # But the in-place UI will nevertheless use +:en+.
   config.ui_locale = :en
end


226
227
228
# File 'lib/scrivito/configuration.rb', line 226

def ui_locale
  @ui_locale
end

Class Method Details

.cache_path=(path) ⇒ Object

Set the path for the filesystem cache.

Scrivito makes heavy use of filesystem caching. Use this method to configure the directory that should be used to store cached data. By default, RAILS_ROOT/tmp/scrivito_cache will be used.

Examples:

Configure Scrivito to store its cache under /tmp/my_cache.


Scrivito.configure do |config|
  config.cache_path = '/tmp/my_cache'
end

Parameters:

  • path (String)

    Path to directory that should be used to store cached data.



101
102
103
# File 'lib/scrivito/configuration.rb', line 101

def cache_path=(path)
  CmsDataCache.cache_path = path
end

.choose_homepage(&block) ⇒ Object

Configure a callback to be invoked when the Scrivito SDK 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.



235
236
237
# File 'lib/scrivito/configuration.rb', line 235

def choose_homepage(&block)
  self.choose_homepage_callback = block
end

.editing_auth(&block) {|env| ... } ⇒ Object

Configures a callback to be invoked when the SDK determines whether current visitor is permitted to edit content.

If the callback is missing in the development or test environment, then the SDK will assume, that the current visitor is User.system_user, who can always create workspaces, can always read, write, publish, delete and invite to any workspace.

If the callback is missing in any other environment (for example in production or staging), then the SDK will assume, that the current visitor is not permitted to edit content.

Examples:

Scrivito::Configuration.editing_auth do |env|
  if user_id = env['USER_ID']
    Scrivito::User.define(user_id)
  end
end

Parameters:

  • block (Proc)

    proc for detemining if the current visitor is permitted to edit content

Yield Parameters:

  • env (Hash)

    rack env

Yield Returns:

  • (Scrivito::User)

    if the current visitor is permitted to edit content

  • (false, nil)

    if the current visitor is not permitted to edit content



44
45
46
47
48
49
50
# File 'lib/scrivito/configuration.rb', line 44

def editing_auth(&block)
  if block.respond_to?(:arity) && block.arity == 1
    @editing_auth_callback = block
  else
    raise ArgumentError, 'editing_auth should have only one attribute!'
  end
end

.find_user(&find_user_proc) {|user_id| ... } ⇒ Object

Note:

This configuration key is optional. If it is not configured the in-place GUI would behave normally, but would not be able to find any users.

Configures how to find users for the in-place GUI.

Examples:

Return a “dummy” User

Scrivito.configure do |config|
  config.find_user do |user_id|
    Scrivito::User.define(user_id)
  end
end

Find the user with a custom user model and convert it to a User

Scrivito.configure do |config|
  config.find_user do |user_id|
    my_user = MyUserModel.find(user_id)
    if my_user
      my_user.to_scrivito_user
    end
  end
end

Parameters:

  • find_user_proc (Proc)

    proc for finding a user by the user id

Yield Parameters:

  • user_id (String)

    id of the user

Yield Returns:

  • (Scrivito::User)

    if the user with the given user id was found

  • (NilClass)

    if the user with the given user id was not found

Raises:



80
81
82
# File 'lib/scrivito/configuration.rb', line 80

def find_user(&find_user_proc)
  self.find_user_proc = find_user_proc
end

.second_level_cache=(cache_store) ⇒ Object

Sets the second level cache.

If it is set, then Scrivito will additionaly store its cache in both: the filesystem cache and the second level cache. Also Scrivito will search in the second level cache if searching in the filesystem cache returns no results. If the second level cache returns results, then the results will be store in the filesystem cache.

By default it is not set.

@example Use Memcached as the second level cache (https://rubygems.org/gems/dalli)

 Scrivito.configure do |config|
   config.second_level_cache = ActiveSupport::Cache::DalliStore.new("localhost", "server-downstairs.localnetwork:8229")
 end

Parameters:

  • cache_store (ActiveSupport::Cache::Store)

    cache store to be used as the second level cache



126
127
128
# File 'lib/scrivito/configuration.rb', line 126

def second_level_cache=(cache_store)
  CmsDataCache.second_level_cache = cache_store
end

.tenant=(tenant_name) ⇒ Object

Sets the tenant name. This configuration key must be provided.



136
137
138
139
# File 'lib/scrivito/configuration.rb', line 136

def tenant=(tenant_name)
  @endpoint_uri = nil
  @tenant = tenant_name
end