Module: Sir

Defined in:
lib/sir.rb,
lib/sir/version.rb

Defined Under Namespace

Modules: Backends

Constant Summary collapse

BACKENDS =
{
    ram_cache:   Sir::Backends::RamCache,
    redis_cache: Sir::Backends::RedisCache
}
VERSION =
"0.6.8"
@@backend =
Sir::Backends::RamCache
@@configuration =
{
    mode:           :ram_cache,
    debug:          false, #debug messages (prints to stderr)
    annoy:          false, #super annoying debug messages (prints to stderr)
    default_expiry: 3600,  #Integer(1.hour)
    options:        {}
}

Class Method Summary collapse

Class Method Details

.annoy(msg) ⇒ Object

Send message to annoy stream



80
81
82
# File 'lib/sir.rb', line 80

def self.annoy(msg)
  $stderr.puts("<=S=I=R=[==] - #{msg}") if self.annoy?
end

.annoy?Boolean

Tests if annoy flag is set

Returns:

  • (Boolean)


68
69
70
# File 'lib/sir.rb', line 68

def self.annoy?
  return @@configuration[:annoy]
end

.config(key) ⇒ Object

look up value of single configuration option



86
87
88
# File 'lib/sir.rb', line 86

def self.config(key)
  return @@configuration[key]
end

.configure(&block) ⇒ Object

Configuration function yields a config block, see README



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# 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

.conredisObject

TODO:

Remove me

remove me



113
114
115
116
117
118
119
120
121
122
123
124
125
126
# 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) ⇒ Object

Send message to debug stream



74
75
76
# File 'lib/sir.rb', line 74

def self.debug(msg)
  $stderr.puts("<=S=I=R=[==] !! #{msg}") if self.debug?
end

.debug?Boolean

Tests is debug flag is set

Returns:

  • (Boolean)


61
62
63
# File 'lib/sir.rb', line 61

def self.debug?
  return @@configuration[:debug]
end

.dump_configObject



91
92
93
94
# File 'lib/sir.rb', line 91

def self.dump_config
  p @@configuration
  return nil
end

.method_missing(meth, *args, &block) ⇒ Object

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



99
100
101
102
103
104
105
106
107
108
# 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