Class: SgPostcode::Proxy
- Inherits:
-
Object
- Object
- SgPostcode::Proxy
- Defined in:
- lib/sg_postcode/services/proxy.rb
Instance Attribute Summary collapse
-
#cache_adapter ⇒ Object
readonly
Returns the value of attribute cache_adapter.
-
#service ⇒ Object
readonly
Returns the value of attribute service.
Instance Method Summary collapse
-
#initialize(service, postcode, cache: true) ⇒ Proxy
constructor
A new instance of Proxy.
- #request ⇒ Object
Constructor Details
#initialize(service, postcode, cache: true) ⇒ Proxy
Returns a new instance of Proxy.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/sg_postcode/services/proxy.rb', line 5 def initialize(service, postcode, cache: true) @postcode = postcode case service when :Google @service = Google.new(postcode) end @cache_adapter = CacheAdapter.new(postcode) if cache end |
Instance Attribute Details
#cache_adapter ⇒ Object (readonly)
Returns the value of attribute cache_adapter.
3 4 5 |
# File 'lib/sg_postcode/services/proxy.rb', line 3 def cache_adapter @cache_adapter end |
#service ⇒ Object (readonly)
Returns the value of attribute service.
3 4 5 |
# File 'lib/sg_postcode/services/proxy.rb', line 3 def service @service end |
Instance Method Details
#request ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/sg_postcode/services/proxy.rb', line 16 def request return nil unless service if cache_adapter cache_adapter.fetch || cache_adapter.store(@postcode, service.request) else service.request end end |