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.4"- @@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
-
.annoy(msg) ⇒ Object
Send message to annoy stream.
-
.annoy? ⇒ Boolean
Tests if annoy flag is set.
-
.config(key) ⇒ Object
look up value of single configuration option.
-
.configure(&block) ⇒ Object
Configuration function yields a config block, see README.
-
.conredis ⇒ Object
remove me.
- .crude_clone(obj) ⇒ Object
-
.debug(msg) ⇒ Object
Send message to debug stream.
-
.debug? ⇒ Boolean
Tests is debug flag is set.
- .dump_config ⇒ Object
-
.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.
-
.nsed_key(key) ⇒ Object
returns a namespaced key.
- .puke ⇒ Object
Class Method Details
.annoy(msg) ⇒ Object
Send message to annoy stream
78 79 80 |
# File 'lib/sir.rb', line 78 def self.annoy(msg) $stderr.puts("<=S=I=R=[==] - #{msg}") if self.annoy? end |
.annoy? ⇒ Boolean
Tests if annoy flag is set
66 67 68 |
# File 'lib/sir.rb', line 66 def self.annoy? return @@configuration[:annoy] end |
.config(key) ⇒ Object
look up value of single configuration option
84 85 86 |
# File 'lib/sir.rb', line 84 def self.config(key) return @@configuration[key] end |
.configure(&block) ⇒ Object
Configuration function yields a config block, see README
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/sir.rb', line 31 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 ⇒ Object
Remove me
remove me
111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/sir.rb', line 111 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 |
.crude_clone(obj) ⇒ Object
134 135 136 |
# File 'lib/sir.rb', line 134 def self.crude_clone(obj) return Marshal.load(Marshal.dump(obj)) end |
.debug(msg) ⇒ Object
Send message to debug stream
72 73 74 |
# File 'lib/sir.rb', line 72 def self.debug(msg) $stderr.puts("<=S=I=R=[==] !! #{msg}") if self.debug? end |
.debug? ⇒ Boolean
Tests is debug flag is set
59 60 61 |
# File 'lib/sir.rb', line 59 def self.debug? return @@configuration[:debug] end |
.dump_config ⇒ Object
89 90 91 92 |
# File 'lib/sir.rb', line 89 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
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/sir.rb', line 97 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 |
.nsed_key(key) ⇒ Object
returns a namespaced key
140 141 142 |
# File 'lib/sir.rb', line 140 def self.nsed_key(key) return "SirCachealot-#{key}" end |
.puke ⇒ Object
129 130 131 |
# File 'lib/sir.rb', line 129 def self.puke raise TypeError, "Invalid config(:mode). Check the inputs sent to Sir.configure()" end |