Class: Memoria::Configuration

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

Overview

Stores the configuration of the gem.

Constant Summary collapse

VALID_SNAPSHOT_RECORD_MODES =

The only allowed snapshot record modes.

%i[all new_episodes none].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Creates an instance of the configuration.

Examples:

configuration = Memoria::Configuration.new


33
34
35
36
# File 'lib/memoria/configuration.rb', line 33

def initialize
  self.snapshot_extension = 'snap'
  self.snapshot_record_mode = :new_episodes
end

Instance Attribute Details

#snapshot_directoryString

Returns Directory where the snapshots will be saved.

Returns:

  • (String)

    Directory where the snapshots will be saved



12
13
14
# File 'lib/memoria/configuration.rb', line 12

def snapshot_directory
  @snapshot_directory
end

#snapshot_extensionString

Returns File extension of new snapshots.

Returns:

  • (String)

    File extension of new snapshots.



22
23
24
# File 'lib/memoria/configuration.rb', line 22

def snapshot_extension
  @snapshot_extension
end

#snapshot_record_modeString

Returns The way the snapshots are recorded.

Returns:

  • (String)

    The way the snapshots are recorded.



17
18
19
# File 'lib/memoria/configuration.rb', line 17

def snapshot_record_mode
  @snapshot_record_mode
end

Instance Method Details

#add_setting(name, &block) ⇒ Symbol

Adds a new setting with the given name.

Examples:

Configuring a setting directly.

configuration = Memoria::Configuration
configuration.add_setting(:now) do
  Time.now
end

Configuring a setting through Memoria’s DSL.

Memoria.configure do |config|
  config.add_setting(:now) do
    Time.now
  end
end

Parameters:

  • name (Symbol)

    The name of the setting.

  • block (Symbol)

    The block to be executed when the setting is called.

Returns:

  • (Symbol)

    The name of the setting

Raises:



89
90
91
92
# File 'lib/memoria/configuration.rb', line 89

def add_setting(name, &block)
  validate_setting_existence(name)
  define_singleton_method(name, block)
end