Sha256: 12f97cb17b3821ccfa2cbd6b4acfc1a9066b6171e8b00ab39a909add57b1c2d5

Contents?: true

Size: 994 Bytes

Versions: 3

Compression:

Stored size: 994 Bytes

Contents

require "extface/engine"
require "extface/routes"
require "extface/mapping"
require "extface/extfaceable"
require "extface/extfaceable"
require "redis-namespace"
module Extface
  mattr_accessor :redis_connection_string
  
  mattr_reader :mappings
  @@mappings = ActiveSupport::OrderedHash.new
  
  mattr_reader :device_timeout
  @@device_timeout = 10
  
  class << self
    def setup
      yield self
    end

    def add_mapping(resource, options)
      mapping = Extface::Mapping.new(resource, options)
      @@mappings[mapping.name] = mapping
    end
    
    def redis_block
      r = redis_instance
      begin
        yield Redis::Namespace.new(:extface, :redis => r)
      ensure
        r.quit
      end
    end
    
    private
      def redis_instance
        if @@redis_connection_string
          uri = URI.parse(@@redis_connection_string)
          Redis.new(host: uri.host, port: uri.port, password: uri.password)
        else
          Redis.new
        end
      end
  end 
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
extface-0.1.0 lib/extface.rb
extface-0.0.8 lib/extface.rb
extface-0.0.7 lib/extface.rb