Class: NetSystem::Database

Inherits:
Liza::Controller show all
Defined in:
lib/net_system/sub/database/database.rb

Direct Known Subclasses

MongoDb, MysqlDb, PgsqlDb, RedisDb, SqliteDb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Liza::Controller

color, on_connected

Methods inherited from Liza::Unit

const_missing, division, part, system, #system, test_class

Constructor Details

#initialize(client: get(:client).new) ⇒ Database

Returns a new instance of Database.



13
14
15
# File 'lib/net_system/sub/database/database.rb', line 13

def initialize client: get(:client).new
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



11
12
13
# File 'lib/net_system/sub/database/database.rb', line 11

def client
  @client
end

Class Method Details

.callObject



28
# File 'lib/net_system/sub/database/database.rb', line 28

def self.call(...); current.call(...); end

.currentObject



21
22
23
24
25
26
# File 'lib/net_system/sub/database/database.rb', line 21

def self.current
  Thread.current[last_namespace] ||= begin
    log "Connecting to #{last_namespace}"
    new
  end
end

.inherited(sub) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/net_system/sub/database/database.rb', line 3

def self.inherited sub
  super

  return if sub.name.nil?
  return if sub.name.end_with? "Db"
  raise "please rename #{sub.name} to #{sub.name}Db"
end

.set_client(client_id) ⇒ Object



17
18
19
# File 'lib/net_system/sub/database/database.rb', line 17

def self.set_client client_id
  set :client, Liza.const("#{client_id}_client")
end

Instance Method Details

#callObject



29
# File 'lib/net_system/sub/database/database.rb', line 29

def call(...); @client.call(...); end