momm 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a45aa436a6e5e383aa428d867a364275fd238200
4
- data.tar.gz: 69436a4520944e7e6be27f0d6029e5412c7943b0
3
+ metadata.gz: 88f614087dabe0ac7ecef7529fd568c0c1ddb058
4
+ data.tar.gz: 03a1106a8ecaf7d43d0589b2ebdb6b0fcb79ee46
5
5
  SHA512:
6
- metadata.gz: 24bda37e47c9f1e8d450b41ae9ddf2ed94723d0d609affb54757c3f5343bfd8076537c80cd51b0f4529f29425b3f73da7d1ae01e47e6cc5389da52c62c85c344
7
- data.tar.gz: 9b0f5931df09c80d82348bcda08bd6eea49e46d05d44cc6eb0097f4eff258417b8104960039a6e652fd529cb449e3cb87fea96cebdfa536b8f3a233165e35c21
6
+ metadata.gz: f6d66f452241aeac2a0ebf7003fd42880a228b47423a99f7edb8a6a8c6fcf926a3dd9ea04844d1ec958273804cf4b12c398e2381a2d32cc0854e1e4b1973c116
7
+ data.tar.gz: 12575b5a233a3c8a088a9a7b0c5f649237e1c9a7453023b4f5568b0b4bf0324b2bdb8ca3521895506c80477ec9a69df898024dd5180bb555e2dfe639bad22082
data/README.md CHANGED
@@ -59,6 +59,7 @@ After the gem is installed, momm provide you a command line tool. The storage en
59
59
  ```
60
60
  $ momm rate GBP CNY # Exchange rate by default is today.
61
61
  $ momm exchange 100 GBP USD 2014-3-1 # Exchange rate at 2013-3-1
62
+ $ momm update # Fetch feeds from remote and update the storage
62
63
  ```
63
64
 
64
65
  #### Ruby
@@ -75,6 +76,8 @@ After the gem is installed, momm provide you a command line tool. The storage en
75
76
  Momm.exchange 100, 'GBP', 'USD', date: Date.today
76
77
  Momm.exchange_from_gbp_to_usd 100
77
78
  Momm.exchange_from_gbp_to_usd 100, date: "2014-3-4"
79
+
80
+ Momm.update! # Fetching the feeds from remote. Only do that if you find any abnormal.
78
81
  ```
79
82
 
80
83
  #### Configuration
data/bin/momm CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH << File.dirname(__FILE__) + "/../lib" if $0 == __FILE__
4
4
  require 'optparse'
5
5
  require 'momm'
6
6
 
7
- OPERATIONS = %w{rate exchange}
7
+ OPERATIONS = %w{rate exchange update}
8
8
 
9
9
  option_parser = OptionParser.new do |opts|
10
10
  opts.banner = Momm::BANNER
@@ -15,7 +15,7 @@ Supported commands:
15
15
 
16
16
  rate [country_code] [country_code] [YYYY-MM-DD] Display rate!
17
17
  exchange [money] [country_code] [country_code] [YYYY-MM-DD] Exchange for you!
18
-
18
+ update Fetch feeds from Remote!
19
19
  Examples:
20
20
  momm exchange 20 GBP CNY Convert the between currencies
21
21
  momm rate GBP CNY Simply display the rate
@@ -57,6 +57,8 @@ if OPERATIONS.include?(op)
57
57
  end
58
58
 
59
59
  puts Momm.exchange money, from, to, date: date
60
+ when "update"
61
+ puts Momm.update!
60
62
  end
61
63
 
62
64
  rescue ArgumentError => ex
data/lib/momm.rb CHANGED
@@ -54,17 +54,14 @@ module Momm
54
54
  # delegate the exchange, :currencies, exchange_rate,
55
55
  # as well as meta programmed methods to module level
56
56
  delegate [:currencies, :exchange, :exchange_rate,
57
- :method_missing, :respond_to?] => :calculator
57
+ :method_missing, :respond_to?, :update! ] => :calculator
58
58
 
59
59
  private
60
60
 
61
61
  # Delegate the calculator
62
62
  def calculator
63
- @calculator ||= if storage || feed
64
- Calculator.new storage, feed
65
- else
66
- Calculator.new
67
- end
63
+ @calculator = Calculator.new(
64
+ (storage || Memcached.new), (feed || Feeds::ECB.instance))
68
65
  end
69
66
  end
70
67
 
@@ -16,14 +16,25 @@ module Momm
16
16
 
17
17
  attr_reader :storage, :feed
18
18
 
19
- # delegate the client and update method from storage
20
- delegate [:client, :update, :set_rate] => :storage
19
+ # delegate the client and set_rate method from storage
20
+ delegate [:client, :set_rate] => :storage
21
21
 
22
22
  # delegate the currencies method from feed
23
23
  delegate :currencies => :feed
24
24
 
25
- # delegate the get rate method with a different naming
25
+ # delegate methods with different naming for overriding
26
26
  def_delegator :storage, :get_rate, :get_rate_origin
27
+ def_delegator :storage, :update, :origin_update
28
+
29
+
30
+ # Update the feeds. In most case, you do not need to call this,
31
+ # because Momm will update the feeds everytime she find something missing ;)
32
+ # == Returns
33
+ # nil
34
+ #
35
+ def update!
36
+ origin_update(feed.currency_rates)
37
+ end
27
38
 
28
39
  # Exchange Rate
29
40
  #
@@ -101,7 +112,7 @@ module Momm
101
112
  res = get_rate_origin(from, date)
102
113
  return res if res != 0 && res
103
114
 
104
- update(feed.currency_rates)
115
+ update!
105
116
  get_rate_origin(from, date)
106
117
  end
107
118
 
@@ -11,8 +11,8 @@ module Momm
11
11
 
12
12
  def initialize(options={})
13
13
  _options = DEFAULT_OPTIONS.dup.merge options
14
- @connection = options.delete(:connection)
15
- @options = options
14
+ @connection = _options.delete(:connection)
15
+ @options = _options
16
16
  end
17
17
 
18
18
  def client
data/lib/momm/storage.rb CHANGED
@@ -54,13 +54,13 @@ module Momm
54
54
  # An array looks like [{date: Date.now, currency: :CNY, rate: 1.23} ...]
55
55
  #
56
56
  # == Returns
57
- # nil
57
+ # "OK"
58
58
  #
59
59
  def update(data)
60
60
  data.each do |d|
61
61
  set_rate d[:currency], d[:rate], d[:date]
62
62
  end
63
- nil
63
+ "OK"
64
64
  end
65
65
 
66
66
  NotImplementedError = Class.new(StandardError)
data/lib/momm/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Momm
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -9,10 +9,6 @@ describe Momm::Calculator do
9
9
  calc.should respond_to :client
10
10
  end
11
11
 
12
- it 'should response to update' do
13
- calc.should respond_to :update
14
- end
15
-
16
12
  it 'should response to set_rate' do
17
13
  calc.should respond_to :set_rate
18
14
  end
@@ -41,8 +37,8 @@ describe Momm::Calculator do
41
37
  calc.should respond_to :client
42
38
  end
43
39
 
44
- it 'should response to update' do
45
- calc.should respond_to :update
40
+ it 'should response to update!' do
41
+ calc.should respond_to :update!
46
42
  end
47
43
 
48
44
  it 'should response to set_rate' do
@@ -27,6 +27,8 @@ describe Momm::Memcached do
27
27
  money = rand(20)
28
28
  momm.set_rate :USD, money
29
29
  momm.get_rate(:USD).should == money
30
+
31
+ Momm.update!
30
32
  end
31
33
  end
32
34
  end
@@ -17,5 +17,17 @@ describe Momm do
17
17
  it "should respond to exchange_rate_from_gbp_to_usd" do
18
18
  Momm.should respond_to :exchange_rate_from_gbp_to_usd
19
19
  end
20
+
21
+ it "should respond to update!" do
22
+ Momm.should respond_to :update!
23
+ end
24
+ end
25
+
26
+ context ".store" do
27
+ it "should be successfully switch to redis store halfway" do
28
+ Momm.store :redis_store
29
+ Momm.send(:calculator).storage.client.should be_a(Redis::Namespace)
30
+ Momm.store :memcached
31
+ end
20
32
  end
21
33
  end
@@ -30,6 +30,8 @@ describe Momm::RedisStore do
30
30
 
31
31
  calc.set_rate :USD, money
32
32
  calc.get_rate(:USD).should == money
33
+
34
+ Momm.update!
33
35
  end
34
36
  end
35
37
  end
@@ -2,6 +2,6 @@ require 'spec_helper'
2
2
 
3
3
  describe 'momm version' do
4
4
  it 'should be correct' do
5
- Momm::VERSION.should == '0.0.3'
5
+ Momm::VERSION.should == '0.0.4'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: momm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jingkai He