Class: Apollo::Instance
- Inherits:
-
Object
- Object
- Apollo::Instance
- Defined in:
- lib/apollo/instance.rb
Overview
A copy of Apollo’s base module class methods.
Instance Attribute Summary collapse
- #client ⇒ Object
-
#configuration ⇒ Object
See Apollo::Configuration.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #configure {|configuration| ... } ⇒ Object
- #fetch(key, default = nil, opts = {}, &block) ⇒ Object
-
#initialize(config = nil) ⇒ Instance
constructor
A new instance of Instance.
Constructor Details
#initialize(config = nil) ⇒ Instance
Returns a new instance of Instance.
12 13 14 |
# File 'lib/apollo/instance.rb', line 12 def initialize(config = nil) self.configuration = config || Configuration.new end |
Instance Attribute Details
#client ⇒ Object
16 17 18 |
# File 'lib/apollo/instance.rb', line 16 def client @client ||= Client.new(configuration) end |
#configuration ⇒ Object
See Apollo::Configuration
10 11 12 |
# File 'lib/apollo/instance.rb', line 10 def configuration @configuration end |
Instance Method Details
#[](key) ⇒ Object
31 32 33 |
# File 'lib/apollo/instance.rb', line 31 def [](key) fetch(key) end |
#configure {|configuration| ... } ⇒ Object
20 21 22 23 |
# File 'lib/apollo/instance.rb', line 20 def configure yield(configuration) if block_given? self.client = @client || Client.new(configuration) end |
#fetch(key, default = nil, opts = {}, &block) ⇒ Object
25 26 27 28 29 |
# File 'lib/apollo/instance.rb', line 25 def fetch(key, default = nil, opts = {}, &block) opts[:disable_cache] = false unless opts.key?(:disable_cache) value = client.fetch(key, opts[:disable_cache]) value || (block_given? ? block.call(key) : default) end |