Class: Momm::Memcached
Constant Summary collapse
- DEFAULT_OPTIONS =
{ connection: "localhost:11211", namespace: "momm", compress: true }.freeze
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #client ⇒ Object
- #get_rate(currency, date = Date.today) ⇒ Object
-
#initialize(options = {}) ⇒ Memcached
constructor
A new instance of Memcached.
- #set_rate(currency, rate, date = Date.today) ⇒ Object
Methods inherited from Storage
Constructor Details
#initialize(options = {}) ⇒ Memcached
Returns a new instance of Memcached.
10 11 12 13 14 |
# File 'lib/momm/memcached.rb', line 10 def initialize(={}) = DEFAULT_OPTIONS.dup.merge @connection = .delete(:connection) = end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
8 9 10 |
# File 'lib/momm/memcached.rb', line 8 def connection @connection end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/momm/memcached.rb', line 8 def end |
Instance Method Details
#client ⇒ Object
16 17 18 |
# File 'lib/momm/memcached.rb', line 16 def client @client ||= Dalli::Client.new connection, end |
#get_rate(currency, date = Date.today) ⇒ Object
25 26 27 28 |
# File 'lib/momm/memcached.rb', line 25 def get_rate(currency, date = Date.today) date = Date.parse(date) if date.is_a? String client.get("#{date}#{currency}").to_f end |
#set_rate(currency, rate, date = Date.today) ⇒ Object
20 21 22 23 |
# File 'lib/momm/memcached.rb', line 20 def set_rate(currency, rate, date = Date.today) date = Date.parse(date) if date.is_a? String client.set "#{date}#{currency}", rate end |