Sha256: 38c59946909cf0e55ac2d974972a49cb99789fdf2456fbd800a7b049920e8e82
Contents?: true
Size: 920 Bytes
Versions: 3
Compression:
Stored size: 920 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 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
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
sitehub-0.5.0.alpha5 | lib/sitehub/middleware/config_loader.rb |
sitehub-0.5.0.alpha4 | lib/sitehub/middleware/config_loader.rb |
sitehub-0.5.0.alpha3 | lib/sitehub/middleware/config_loader.rb |