Skip to content

Commit

Permalink
Replace Lotus::Model::Adapter with Lotus::Model::Config::Adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
Trung Lê committed Jul 14, 2014
1 parent 85a0b6f commit fb3cfe8
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 4 deletions.
5 changes: 2 additions & 3 deletions lib/lotus/model.rb
Expand Up @@ -2,6 +2,7 @@
require 'lotus/entity'
require 'lotus/repository'
require 'lotus/model/mapper'
require 'lotus/model/config/adapter'

module Lotus
# Model
Expand All @@ -27,8 +28,6 @@ class NonPersistedEntityError < ::StandardError

include Utils::ClassAttribute

Adapter = Struct.new(:name, :uri, :default)

# Framework adapters
#
# @since 0.2.0
Expand Down Expand Up @@ -80,7 +79,7 @@ def self.configure(&block)
# adapter :sql, 'postgres://localhost/database', default: true
# end
def self.adapter(name, uri, default: false)
adapters[name] = Adapter.new(name, uri, default)
adapters[name] = Lotus::Model::Config::Adapter.new(name, uri, default)
end
end
end
64 changes: 64 additions & 0 deletions lib/lotus/model/config/adapter.rb
@@ -0,0 +1,64 @@
module Lotus
module Model
module Config
# 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`.
#
# @see Lotus::Model.adapter
#
# @example
# require 'lotus/model'
#
# Lotus::Model.configure do
# adapter :sql, 'postgres://localhost/database'
# end
#
# Registered adapters can be retrieved via `Lotus::Model.adapters`
#
# @see Lotus::Model.adapters
#
# @example
# Lotus::Model.adapter[:sql]
# # => Lotus::Model::Config::Adapter(name: :sql, uri: 'postgres://localhost/database')
#
# @since 0.2.0
class Adapter
# @return name [Symbol] the unique adapter name
#
# @since 0.2.0
#
# @see Lotus::Config::Adapter#name
attr_reader :name

# @return uri [String] the adapter URI
#
# @since 0.2.0
#
# @see Lotus::Config::Adapter#uri
attr_reader :uri

# @return default [TrueClass, FalseClass] Decide if the adapter
# is used by default
#
# @since 0.2.0
#
# @see Lotus::Config::Adapter#default
attr_reader :default

# Initialize an adapter configuration instance
#
# @return [Lotus::Model::Config::Adapter] a new apdapter configuration's
# instance
#
# @since 0.2.0
def initialize(name, uri, default = false)
@name, @uri, @default = name, uri, default
end
end
end
end
end
1 change: 0 additions & 1 deletion test/model_test.rb
Expand Up @@ -18,7 +18,6 @@
adapter = Lotus::Model.adapters[:sql]

adapter.default.must_equal(true)
#adapter.class.must_equal(Lotus::Model::Adapters::SqlAdapter)
adapter.uri.must_equal('postgres://localhost/database')
end
end
Expand Down

0 comments on commit fb3cfe8

Please sign in to comment.