Sha256: 1d45b46ab112944f606f06a66acd7de0d1ffb7571c1381a8dba3f02bfcfce6d4
Contents?: true
Size: 980 Bytes
Versions: 2
Compression:
Stored size: 980 Bytes
Contents
require 'active_support' class SiteHub class ConfigServer attr_reader :server_url, :http_client def initialize(url) @server_url = url @http_client = Faraday.new(ssl: { verify: false }) do |con| con.adapter :em_synchrony end end def get JSON(http_client.get(server_url).body, symbolize_names: true) end end module Middleware class ConfigLoader attr_reader :config_server, :app, :cache def initialize(_app, config_server_url) @config_server = ConfigServer.new(config_server_url) @cache = ActiveSupport::Cache::MemoryStore.new(size: 1.megabytes) end def call(env) load_config @app.call env end # TODO: handle errors connecting to the config server def load_config config = cache.fetch(:sitehub_config, expires_in: 30) do config_server.get end @app = Core.from_hash(config).build end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
sitehub-0.5.0.alpha7 | lib/sitehub/middleware/config_loader.rb |
sitehub-0.5.0.alpha6 | lib/sitehub/middleware/config_loader.rb |