Class: Lotus::Model::Config::Adapter

Inherits:
Object
  • Object
show all
Defined in:
lib/lotus/model/config/adapter.rb

Overview

Configuration for the adapter

Lotus::Model has its own global configuration that can be manipulated via ‘Lotus::Model.configure`.

New adapter configuration can be registered via ‘Lotus::Model.adapter`.

By convention, Lotus inflects type to find the adapter class For example, if type is :sql, derived class will be ‘Lotus::Model::Adapters::SqlAdapter`

Examples:

require 'lotus/model'

Lotus::Model.configure do
  adapter type: :sql, uri: 'postgres://localhost/database'
end

Lotus::Model.configuration.adapter_config
# => Lotus::Model::Config::Adapter(type: :sql, uri: 'postgres://localhost/database')

See Also:

  • Lotus::Model.adapter

Since:

  • 0.2.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ Lotus::Model::Config::Adapter

Initialize an adapter configuration instance

Parameters:

  • options (Hash)

    configuration options

Options Hash (**options):

  • :type (Symbol)

    adapter type name

  • :uri (String)

    adapter URI

Since:

  • 0.2.0



68
69
70
71
72
73
74
75
76
# File 'lib/lotus/model/config/adapter.rb', line 68

def initialize(**options)
  opts     = options.dup

  @type    = opts.delete(:type)
  @uri     = opts.delete(:uri)
  @options = opts

  @class_name ||= Lotus::Utils::String.new("#{@type}_adapter").classify
end

Instance Attribute Details

#class_nameString (readonly)

Returns the adapter class name.

Returns:

  • (String)

    the adapter class name

Since:

  • 0.2.0



56
57
58
# File 'lib/lotus/model/config/adapter.rb', line 56

def class_name
  @class_name
end

#optionsHash (readonly)

Returns a list of non-mandatory options for the adapter.

Returns:

  • (Hash)

    a list of non-mandatory options for the adapter

Since:

  • 0.2.0



51
52
53
# File 'lib/lotus/model/config/adapter.rb', line 51

def options
  @options
end

#typeSymbol (readonly)

Returns the adapter name.

Returns:

  • (Symbol)

    the adapter name

Since:

  • 0.2.0



42
43
44
# File 'lib/lotus/model/config/adapter.rb', line 42

def type
  @type
end

#uriString (readonly)

Returns the adapter URI.

Returns:

  • (String)

    the adapter URI

Since:

  • 0.2.0



47
48
49
# File 'lib/lotus/model/config/adapter.rb', line 47

def uri
  @uri
end

Instance Method Details

#build(mapper) ⇒ Lotus::Model::Adapters::SqlAdapter, Lotus::Model::Adapters::MemoryAdapter

Initialize the adapter

Parameters:

Returns:

See Also:

Since:

  • 0.2.0



87
88
89
90
# File 'lib/lotus/model/config/adapter.rb', line 87

def build(mapper)
  load_adapter
  instantiate_adapter(mapper)
end