module Sir

def required(str)

require File.dirname(__FILE__) + "/" + str

end

Constants

BACKENDS
VERSION

Public Class Methods

annoy(msg) click to toggle source

Send message to annoy stream

# File lib/sir.rb, line 80
def self.annoy(msg)
  $stderr.puts("<=S=I=R=[==] - #{msg}") if self.annoy?
end
annoy?() click to toggle source

Tests if annoy flag is set @returns [boolean] annoy status

# File lib/sir.rb, line 68
def self.annoy?
  return @@configuration[:annoy]
end
config(key) click to toggle source

look up value of single configuration option

# File lib/sir.rb, line 86
def self.config(key)
  return @@configuration[key]
end
configure() { |configuration| ... } click to toggle source

Configuration function yields a config block, see README @returns true

# File lib/sir.rb, line 33
def self.configure(&block)

  if block_given?
    yield(@@configuration)
  end

  #ap @@configuration

  @@backend = BACKENDS[@@configuration[:mode]]
  @@backend.configure(@@configuration[:options])

  # this doesnt work right
  #Sir::Backends::Base::EXPORTS.each do |func|
  #  Sir.send :define_singleton_method, func do |*params|
  #    @@backend.send(func, *params)
  #  end
  #  self.annoy("Attached #{func}")
  #end

  self.debug("SirCachealot #{Sir::VERSION} loaded configuration for #{@@configuration[:mode]}, watching #{Sir::Backends::Base::EXPORTS.length} methods")
  self.annoy("Annoy activated! Bwahaha!")
  return true

end
conredis() click to toggle source

remove me

@todo Remove me
# File lib/sir.rb, line 113
def self.conredis
  require 'redis'
  redis_obj        = Redis.new(:host => "127.0.0.1", :port => "6379")
  opts             = Sir::Backends::RedisCache::DEFAULTS
  opts[:redis_obj] = redis_obj


  Sir.configure do |config|
    config[:mode]           = :redis_cache
    config[:debug]          = true
    config[:options]        = opts
  end

end
debug(msg) click to toggle source

Send message to debug stream

# File lib/sir.rb, line 74
def self.debug(msg)
  $stderr.puts("<=S=I=R=[==] !! #{msg}") if self.debug?
end
debug?() click to toggle source

Tests is debug flag is set @returns [boolean] debug status

# File lib/sir.rb, line 61
def self.debug?
  return @@configuration[:debug]
end
dump_config() click to toggle source
# File lib/sir.rb, line 91
def self.dump_config
  p @@configuration
  return nil
end
method_missing(meth, *args, &block) click to toggle source

TODO: define all these methods on configure(), we should only go here if the user hasnt configured Sir catch on use if unconfigured

Calls superclass method
# File lib/sir.rb, line 99
def self.method_missing(meth, *args, &block)

  if Sir::Backends::Base::EXPORTS.include?(meth)
    self.configure! if @@configuration.nil?
    return @@backend.send(meth, *args, &block)
  else
    super
  end

end

Private Class Methods

crude_clone(obj) click to toggle source
# File lib/sir.rb, line 136
def self.crude_clone(obj)
  return Marshal.load(Marshal.dump(obj))
end
nsed_key(key) click to toggle source

returns a namespaced key

# File lib/sir.rb, line 142
def self.nsed_key(key)
  return "SirCachealot-#{key}"
end
puke() click to toggle source
# File lib/sir.rb, line 131
def self.puke
  raise TypeError, "Invalid config(:mode). Check the inputs sent to Sir.configure()"
end