Sha256: 1d7c1caceafe7615c9df996dd6be5764fa92cc255f0ff3471426747dbd7d6124

Contents?: true

Size: 1.15 KB

Versions: 4

Compression:

Stored size: 1.15 KB

Contents

require "extface/engine"
require "extface/routes"
require "extface/mapping"
require "extface/extfaceable"
require "extface/extfaceable"
require "redis-namespace"
module Extface
  RAW_DRIVER = "Raw Communication Devices"
  PRINT_DRIVER = "Print Devices"
  FISCAL_DRIVER = "Fiscal Printers & Cash Registers"
  REPORT_DRIVER = "CDR Loggers, Report Devices"
    
  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

4 entries across 4 versions & 1 rubygems

Version Path
extface-0.1.4 lib/extface.rb
extface-0.1.3 lib/extface.rb
extface-0.1.2 lib/extface.rb
extface-0.1.1 lib/extface.rb