Module: CrossStub
- Extended by:
- Forwardable
- Defined in:
- lib/cross-stub.rb,
lib/cross-stub/cache.rb,
lib/cross-stub/stubber.rb,
lib/cross-stub/arguments.rb,
lib/cross-stub/stores/base.rb,
lib/cross-stub/stores/file.rb,
lib/cross-stub/stores/redis.rb,
lib/cross-stub/arguments/hash.rb,
lib/cross-stub/arguments/proc.rb,
lib/cross-stub/arguments/array.rb,
lib/cross-stub/stores/memcache.rb
Defined Under Namespace
Modules: Arguments, Cache, ClassMethods, InstanceMethods, Stores, Stubber
Classes: CannotStubInstanceError, Error, ModuleCannotBeInstantiatedError, UnsupportedCacheStore, UnsupportedStoreGetMode
Class Method Summary
collapse
Class Method Details
.apply(type, thing, cache_key, args, &block) ⇒ Object
43
44
45
46
47
|
# File 'lib/cross-stub.rb', line 43
def apply(type, thing, cache_key, args, &block)
Cache.set(Cache.get.merge(
cache_key => Stubber.apply(type, thing, Arguments.parse(args, &block))
))
end
|
.clear ⇒ Object
35
36
37
38
39
40
41
|
# File 'lib/cross-stub.rb', line 35
def clear
Cache.get.map do |cache_key, stubs|
type, thing = stubbable(cache_key)
Stubber.unapply(type, thing, stubs)
end
Cache.clear
end
|
.klassify(str) ⇒ Object
56
57
58
|
# File 'lib/cross-stub.rb', line 56
def klassify(str)
str.split('::').inject(Object){|klass, const| klass.const_get(const) }
end
|
.refresh(opts) ⇒ Object
25
26
27
28
29
30
31
32
33
|
# File 'lib/cross-stub.rb', line 25
def refresh(opts)
Cache.refresh(opts)
[[:previous, :unapply], [:current, :apply]].each do |(mode, method)|
Cache.get(mode).map do |cache_key, stubs|
type, thing = stubbable(cache_key)
Stubber.send(method, type, thing, stubs)
end
end
end
|
.stubbable(str) ⇒ Object
49
50
51
52
53
54
|
# File 'lib/cross-stub.rb', line 49
def stubbable(str)
[
str.end_with?(suffix = '#instance') ? :instance : :class,
klassify(str.sub(suffix,''))
]
end
|