Module: Ladder::Config

Extended by:
Config, Mongoid::Config::Options
Included in:
Config
Defined in:
lib/ladder/config.rb

Constant Summary collapse

LOCK =
Mutex.new

Instance Method Summary collapse

Instance Method Details

#load_configuration(settings) ⇒ Object

From a hash of settings, load all the configuration.

Examples:

Load the configuration.

config.load_configuration(settings)

Parameters:

  • settings (Hash)

    The configuration settings.

Since:

  • 3.1.0



51
52
53
54
# File 'lib/ladder/config.rb', line 51

def load_configuration(settings)
  configuration = settings.with_indifferent_access
  self.options = configuration[:options]
end

#modelsArray<Class>

Get all the models in the application - this is everything that includes Ladder::Resource or Ladder::File.

Examples:

Get all the models.

config.models

Returns:

  • (Array<Class>)

    All the models in the application.

Since:

  • 3.1.0



25
26
27
# File 'lib/ladder/config.rb', line 25

def models
  @models ||= []
end

#options=(options) ⇒ Object

Set the configuration options. Will validate each one individually.

Examples:

Set the options.

config.options = { raise_not_found_error: true }

Parameters:

  • options (Hash)

    The configuration options.

Since:

  • 3.0.0



64
65
66
67
68
69
70
71
# File 'lib/ladder/config.rb', line 64

def options=(options)
  if options
    options.each_pair do |option, value|
      ::Mongoid::Config::Validators::Option.validate(option)
      send("#{option}=", value)
    end
  end
end

#register_model(klass) ⇒ Object

Register a model in the application with Ladder.

Examples:

Register a model.

config.register_model(Band)

Parameters:

  • klass (Class)

    The model to register.

Since:

  • 3.1.0



37
38
39
40
41
# File 'lib/ladder/config.rb', line 37

def register_model(klass)
  LOCK.synchronize do
    models.push(klass) unless models.include?(klass)
  end
end