Class: YDIM::Server
- Inherits:
-
Object
- Object
- YDIM::Server
- Defined in:
- lib/ydim/server.rb
Constant Summary collapse
- CONFIG =
config- SECONDS_IN_DAY =
24*60*60
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(config, logger) ⇒ Server
constructor
A new instance of Server.
- #login(client, name = nil, &block) ⇒ Object
- #logout(session) ⇒ Object
- #ping ⇒ Object
Constructor Details
#initialize(config, logger) ⇒ Server
Returns a new instance of Server.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/ydim/server.rb', line 70 def initialize(config, logger) @serv = Needle::Registry.new @serv.register(:auth_server) { auth = RRBA::Server.new root = RootUser.new(:root) root.name = config.root_name root.email = config.root_email root_key = config.root_key path = File.(root_key, config.conf_dir) path_or_key = File.exist?(path) ? path : root_key root.public_key = Util.load_key(path_or_key) auth.root = root auth } @serv.register(:clients) { ClientHandler.new(@serv) } @serv.register(:config) { config } @serv.register(:currency_converter) { ODBA.cache.fetch_named('currency_converter', self) { CurrencyConverter.new } } @serv.register(:factory) { Factory.new(@serv) } @serv.register(:id_server) { ODBA.cache.fetch_named('id_server', self) { ODBA::IdServer.new } } @serv.register(:logger) { logger } if(hour = config.autoinvoice_hour) @autoinvoicer = repeat_at(hour, 'AutoInvoicer') { AutoInvoicer.new(@serv).run } end if(hour = config.currency_update_hour) if(@serv.currency_converter.known_currencies \ < @serv.config.currencies.size) CurrencyUpdater.new(@serv).run end @currency_updater = repeat_at(hour, 'CurrencyUpdater') { CurrencyUpdater.new(@serv).run } end @status_updater = repeat_at(1, 'StatusUpdater') { Invoice.all { |inv| inv.save } } @sessions = [] end |
Class Method Details
.config ⇒ Object
67 68 69 |
# File 'lib/ydim/server.rb', line 67 def Server.config CONFIG end |
Instance Method Details
#login(client, name = nil, &block) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/ydim/server.rb', line 125 def login(client, name=nil, &block) @serv.logger.debug(client.__drburi) { "attempting login" } session = @serv.auth_server.authenticate(name, &block) session.serv = @serv session.client = client @serv.logger.info(session.whoami) { 'login' } @sessions.push(session) session rescue Exception => error @serv.logger.error('unknown user') { [error.class, error.].join(' - ') } raise end |
#logout(session) ⇒ Object
138 139 140 141 142 |
# File 'lib/ydim/server.rb', line 138 def logout(session) @serv.logger.info(session.whoami) { 'logout' } @sessions.delete(session) nil end |
#ping ⇒ Object
143 144 145 |
# File 'lib/ydim/server.rb', line 143 def ping true end |