momm 0.0.7 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +1 -0
  3. data/README.md +11 -8
  4. data/bin/momm +3 -1
  5. data/examples/rack_app/Gemfile +1 -0
  6. data/examples/rack_app/config.ru +3 -1
  7. data/lib/momm/memcached.rb +12 -4
  8. data/lib/momm/redis_store.rb +12 -4
  9. data/lib/momm/storage.rb +3 -7
  10. data/lib/momm/version.rb +1 -1
  11. data/lib/momm/web.rb +1 -1
  12. data/momm.gemspec +4 -4
  13. data/spec/momm/bridge_spec.rb +5 -5
  14. data/spec/momm/calculator_spec.rb +16 -16
  15. data/spec/momm/feeds/ecb_spec.rb +9 -9
  16. data/spec/momm/memcached_spec.rb +9 -5
  17. data/spec/momm/momm_spec.rb +10 -10
  18. data/spec/momm/redis_store_spec.rb +9 -7
  19. data/spec/momm/storage_spec.rb +8 -8
  20. data/spec/momm/version_spec.rb +2 -2
  21. data/spec/momm/web_spec.rb +4 -2
  22. data/spec/spec_helper.rb +5 -4
  23. metadata +46 -115
  24. data/examples/rails_app/.gitignore +0 -16
  25. data/examples/rails_app/Gemfile +0 -12
  26. data/examples/rails_app/README.rdoc +0 -28
  27. data/examples/rails_app/Rakefile +0 -6
  28. data/examples/rails_app/app/assets/images/.keep +0 -0
  29. data/examples/rails_app/app/assets/javascripts/application.js +0 -16
  30. data/examples/rails_app/app/assets/javascripts/pages.js +0 -2
  31. data/examples/rails_app/app/assets/stylesheets/application.css +0 -13
  32. data/examples/rails_app/app/assets/stylesheets/pages.css +0 -4
  33. data/examples/rails_app/app/controllers/application_controller.rb +0 -5
  34. data/examples/rails_app/app/controllers/concerns/.keep +0 -0
  35. data/examples/rails_app/app/controllers/pages_controller.rb +0 -4
  36. data/examples/rails_app/app/helpers/application_helper.rb +0 -2
  37. data/examples/rails_app/app/helpers/pages_helper.rb +0 -2
  38. data/examples/rails_app/app/mailers/.keep +0 -0
  39. data/examples/rails_app/app/models/.keep +0 -0
  40. data/examples/rails_app/app/models/concerns/.keep +0 -0
  41. data/examples/rails_app/app/views/layouts/application.html.erb +0 -14
  42. data/examples/rails_app/app/views/pages/say_hello.html.slim +0 -20
  43. data/examples/rails_app/bin/bundle +0 -3
  44. data/examples/rails_app/bin/rails +0 -4
  45. data/examples/rails_app/bin/rake +0 -4
  46. data/examples/rails_app/config.ru +0 -4
  47. data/examples/rails_app/config/application.rb +0 -28
  48. data/examples/rails_app/config/boot.rb +0 -4
  49. data/examples/rails_app/config/environment.rb +0 -5
  50. data/examples/rails_app/config/environments/development.rb +0 -26
  51. data/examples/rails_app/config/environments/production.rb +0 -80
  52. data/examples/rails_app/config/environments/test.rb +0 -36
  53. data/examples/rails_app/config/initializers/backtrace_silencers.rb +0 -7
  54. data/examples/rails_app/config/initializers/filter_parameter_logging.rb +0 -4
  55. data/examples/rails_app/config/initializers/inflections.rb +0 -16
  56. data/examples/rails_app/config/initializers/mime_types.rb +0 -5
  57. data/examples/rails_app/config/initializers/momm_initializer.rb +0 -3
  58. data/examples/rails_app/config/initializers/secret_token.rb +0 -12
  59. data/examples/rails_app/config/initializers/session_store.rb +0 -3
  60. data/examples/rails_app/config/initializers/wrap_parameters.rb +0 -9
  61. data/examples/rails_app/config/locales/en.yml +0 -23
  62. data/examples/rails_app/config/routes.rb +0 -7
  63. data/examples/rails_app/db/seeds.rb +0 -7
  64. data/examples/rails_app/lib/assets/.keep +0 -0
  65. data/examples/rails_app/lib/tasks/.keep +0 -0
  66. data/examples/rails_app/log/.keep +0 -0
  67. data/examples/rails_app/public/404.html +0 -58
  68. data/examples/rails_app/public/422.html +0 -58
  69. data/examples/rails_app/public/500.html +0 -57
  70. data/examples/rails_app/public/favicon.ico +0 -0
  71. data/examples/rails_app/public/robots.txt +0 -5
  72. data/examples/rails_app/vendor/assets/javascripts/.keep +0 -0
  73. data/examples/rails_app/vendor/assets/stylesheets/.keep +0 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b393642dc01d810177a7c39e8bc94c27afaf6434
4
+ data.tar.gz: b52ae25cd3c12b17bb8698d2495d2f9460af49a4
5
+ SHA512:
6
+ metadata.gz: 3e3b3d1d6aed617daee7e5da579cc96fcd490266dabe84ae83def102668a85580bc10dcc8af400b5f44a684d889168a15812a3a5e4949d06cf3aef1e574d6fcb
7
+ data.tar.gz: de240f07aae21d6dce48949dd79f16bd520a7561ff4428f7197daeebec0fcb00caad16ddf866722c20d7d847465214a7ffafafed75d6ff8398021e74554418d7
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/README.md CHANGED
@@ -28,9 +28,7 @@ Money on My Mind - An awesome gem for currency exchange.
28
28
  ## Requirement
29
29
 
30
30
 
31
- Ensure that [Memcached](http://memcached.org/) or [Redis](http://redis.io/) is installed on your local machine or server or provided by some other cloud service providers. Those are for exchange rate storage, which ensure your fast queries.
32
-
33
- Local storage is not provided, because it might not safe for work on Cloud Platforms such as Heroku.
31
+ Ensure that either [Memcached](http://memcached.org/) or [Redis](http://redis.io/) is installed on the machines/servers for exchange rate store
34
32
 
35
33
  ## Installation
36
34
 
@@ -56,7 +54,7 @@ Or install it yourself as:
56
54
  #### Command Line Tool
57
55
 
58
56
 
59
- After the gem is installed, momm provide you a command line tool. The storage engine by default is Memcached, ensure it is opened.
57
+ After the gem is installed, momm provide you a command line tool. The storage engine by default is Memcached. Make sure that its running in the background. Also make sure that you got the `dalli` gem installed
60
58
 
61
59
  ```
62
60
  $ momm rate GBP CNY # Exchange rate by default is today.
@@ -68,6 +66,7 @@ After the gem is installed, momm provide you a command line tool. The storage en
68
66
 
69
67
 
70
68
  ``` ruby
69
+ require 'dalli' # Make sure that dalli is required before momm
71
70
  require 'momm'
72
71
 
73
72
  Momm.exchange_rate 'GBP', 'USD' # By default Today
@@ -86,7 +85,7 @@ After the gem is installed, momm provide you a command line tool. The storage en
86
85
 
87
86
 
88
87
  ``` ruby
89
- Momm.store :redis_store # Use redis as the default storage
88
+ Momm.store :redis_store # Use redis as the default storage. Ensure 'redis' & 'redis-namespace is installed'
90
89
 
91
90
  Momm.fed :ECB # Use ECB as the default currency exchange feeds
92
91
 
@@ -104,7 +103,7 @@ Web service is provided by Momm on Rails, however you need to install sinatra si
104
103
 
105
104
  ``` ruby
106
105
  # routes.rb
107
-
106
+ require 'dalli'
108
107
  require 'momm/web'
109
108
 
110
109
  Myapp::Application.routes.draw do
@@ -112,11 +111,15 @@ Web service is provided by Momm on Rails, however you need to install sinatra si
112
111
  end
113
112
  ```
114
113
 
115
- The default Storage is Memcached, if you want to switch to Redis, you can create an initialzer like:
114
+ If you want to switch to Redis, you can create an initialzer like:
116
115
 
117
116
  ``` ruby
117
+ # Gemfile
118
+ gem 'redis'
119
+ gem 'redis-namespace'
118
120
 
119
121
  # momm_initialzer.rb
122
+
120
123
  Momm.setup do
121
124
  store :redis_store, host: "127.0.0.1", namespace: "green_tea"
122
125
  end
@@ -161,7 +164,7 @@ Widget of [SLIM](http://slim-lang.com/) template looks like below. Currenly only
161
164
 
162
165
  ``` ruby
163
166
  # config.ru
164
-
167
+ require 'dalli' # again make sure that dalli is required beforehand!!!
165
168
  require 'momm/web'
166
169
  run Momm::Web
167
170
  ```
data/bin/momm CHANGED
@@ -2,6 +2,8 @@
2
2
  $LOAD_PATH << File.dirname(__FILE__) + "/../lib" if $0 == __FILE__
3
3
 
4
4
  require 'optparse'
5
+
6
+ require 'dalli'
5
7
  require 'momm'
6
8
 
7
9
  OPERATIONS = %w{rate exchange update}
@@ -71,4 +73,4 @@ if OPERATIONS.include?(op)
71
73
  end
72
74
  else
73
75
  puts option_parser.help
74
- end
76
+ end
@@ -1,5 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ gem 'dalli'
3
4
  gem 'momm', path: '../..'
4
5
 
5
6
  # Momm::Web dependency
@@ -1,2 +1,4 @@
1
+ require 'dalli'
1
2
  require 'momm/web'
2
- run Momm::Web
3
+
4
+ run Momm::Web
@@ -1,5 +1,3 @@
1
- require 'dalli'
2
-
3
1
  module Momm
4
2
  class Memcached < Storage
5
3
 
@@ -18,5 +16,15 @@ module Momm
18
16
  def client
19
17
  @client ||= Dalli::Client.new connection, options
20
18
  end
21
- end
22
- end
19
+
20
+ def set_rate(currency, rate, date = Date.today)
21
+ date = Date.parse(date) if date.is_a? String
22
+ client.set "#{date}#{currency}", rate
23
+ end
24
+
25
+ def get_rate(currency, date = Date.today)
26
+ date = Date.parse(date) if date.is_a? String
27
+ client.get("#{date}#{currency}").to_f
28
+ end
29
+ end if defined?(::Dalli)
30
+ end
@@ -1,5 +1,3 @@
1
- require 'redis'
2
-
3
1
  module Momm
4
2
  class RedisStore < Storage
5
3
  DEFAULT_OPTIONS = { host: "localhost", port: 6379, namespace: "momm"}
@@ -20,5 +18,15 @@ module Momm
20
18
  Redis::Namespace.new(ns, :redis => native_client)
21
19
  end
22
20
  end
23
- end
24
- end
21
+
22
+ def set_rate(currency, rate, date = Date.today)
23
+ date = Date.parse(date) if date.is_a? String
24
+ client.set "#{date}#{currency}", rate
25
+ end
26
+
27
+ def get_rate(currency, date = Date.today)
28
+ date = Date.parse(date) if date.is_a? String
29
+ client.get("#{date}#{currency}").to_f
30
+ end
31
+ end if defined?(::Redis)
32
+ end
@@ -27,8 +27,7 @@ module Momm
27
27
  # nil
28
28
  #
29
29
  def set_rate(currency, rate, date = Date.today)
30
- date = Date.parse(date) if date.is_a? String
31
- client.set "#{date}#{currency}", rate
30
+ raise NotImplementedError
32
31
  end
33
32
 
34
33
  # Fetch the currency rate from client
@@ -43,8 +42,7 @@ module Momm
43
42
  # the currency rate
44
43
  #
45
44
  def get_rate(currency, date = Date.today)
46
- date = Date.parse(date) if date.is_a? String
47
- client.get("#{date}#{currency}").to_f
45
+ raise NotImplementedError
48
46
  end
49
47
 
50
48
  # update the data to storage
@@ -62,7 +60,5 @@ module Momm
62
60
  end
63
61
  "OK"
64
62
  end
65
-
66
- NotImplementedError = Class.new(StandardError)
67
63
  end
68
- end
64
+ end
@@ -1,3 +1,3 @@
1
1
  module Momm
2
- VERSION = "0.0.7"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -55,4 +55,4 @@ module Momm
55
55
  "#{env['SCRIPT_NAME']}"
56
56
  end
57
57
  end
58
- end
58
+ end
@@ -18,14 +18,14 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "redis", ">= 3.0.6"
22
- spec.add_dependency "redis-namespace", ">= 1.3.2"
23
- spec.add_dependency "dalli", ">= 2.7.0"
24
21
  spec.add_dependency "httparty", ">= 0.12.0"
25
22
  spec.add_dependency "json"
26
23
 
24
+ spec.add_development_dependency "redis"
25
+ spec.add_development_dependency "dalli"
26
+ spec.add_development_dependency "redis-namespace"
27
27
  spec.add_development_dependency "rack-test"
28
28
  spec.add_development_dependency "rake"
29
29
  spec.add_development_dependency "sinatra"
30
- spec.add_development_dependency "rspec"
30
+ spec.add_development_dependency "rspec", "3.4.0"
31
31
  end
@@ -5,8 +5,8 @@ describe Momm::Bridge do
5
5
  it 'should have default' do
6
6
  bridge = Momm::Bridge.new
7
7
 
8
- bridge.storage.should be_a(Momm::Memcached)
9
- bridge.feed.should be_a(Momm::Feeds::ECB)
8
+ expect(bridge.storage).to be_a(Momm::Memcached)
9
+ expect(bridge.feed).to be_a(Momm::Feeds::ECB)
10
10
  end
11
11
  end
12
12
 
@@ -15,12 +15,12 @@ describe Momm::Bridge do
15
15
 
16
16
  it 'should change the storage' do
17
17
  bridge.store :redis_store
18
- bridge.storage.should be_a(Momm::RedisStore)
18
+ expect(bridge.storage).to be_a(Momm::RedisStore)
19
19
  end
20
20
 
21
21
  it 'should change the ECB' do
22
22
  bridge.source :ECB
23
- bridge.feed.should be_a(Momm::Feeds::ECB)
23
+ expect(bridge.feed).to be_a(Momm::Feeds::ECB)
24
24
  end
25
25
  end
26
- end
26
+ end
@@ -6,27 +6,27 @@ describe Momm::Calculator do
6
6
  let(:calc) { calc = Momm::Calculator.new Momm::RedisStore.new }
7
7
 
8
8
  it 'should response to client' do
9
- calc.should respond_to :client
9
+ expect(calc).to respond_to :client
10
10
  end
11
11
 
12
12
  it 'should response to set_rate' do
13
- calc.should respond_to :set_rate
13
+ expect(calc).to respond_to :set_rate
14
14
  end
15
15
 
16
16
  it 'should response to get_rate_origin' do
17
- calc.should respond_to :get_rate_origin
17
+ expect(calc).to respond_to :get_rate_origin
18
18
  end
19
19
 
20
20
  it 'should response to get_rate' do
21
- calc.should respond_to :get_rate
21
+ expect(calc).to respond_to :get_rate
22
22
  end
23
23
 
24
24
  it 'should response to exchange_rate' do
25
- calc.should respond_to :exchange_rate
25
+ expect(calc).to respond_to :exchange_rate
26
26
  end
27
27
 
28
28
  it 'should response to exchange' do
29
- calc.should respond_to :exchange
29
+ expect(calc).to respond_to :exchange
30
30
  end
31
31
  end
32
32
 
@@ -34,42 +34,42 @@ describe Momm::Calculator do
34
34
  let(:calc) { Momm::Calculator.new }
35
35
 
36
36
  it 'should response to client' do
37
- calc.should respond_to :client
37
+ expect(calc).to respond_to :client
38
38
  end
39
39
 
40
40
  it 'should response to update!' do
41
- calc.should respond_to :update!
41
+ expect(calc).to respond_to :update!
42
42
  end
43
43
 
44
44
  it 'should response to set_rate' do
45
- calc.should respond_to :set_rate
45
+ expect(calc).to respond_to :set_rate
46
46
  end
47
47
 
48
48
  it 'should response to get_rate_origin' do
49
- calc.should respond_to :get_rate_origin
49
+ expect(calc).to respond_to :get_rate_origin
50
50
  end
51
51
 
52
52
  it 'should response to get_rate' do
53
- calc.should respond_to :get_rate
53
+ expect(calc).to respond_to :get_rate
54
54
  end
55
55
 
56
56
  it 'should response to exchange_rate' do
57
- calc.should respond_to :exchange_rate
57
+ expect(calc).to respond_to :exchange_rate
58
58
  end
59
59
 
60
60
  it 'should response to exchange' do
61
- calc.should respond_to :exchange
61
+ expect(calc).to respond_to :exchange
62
62
  end
63
63
 
64
64
  it 'should response to currencies' do
65
- calc.should respond_to :currencies
65
+ expect(calc).to respond_to :currencies
66
66
  end
67
67
  end
68
68
 
69
69
  context 'feeds' do
70
70
  it 'should not be nil' do
71
71
  calc = Momm::Calculator.new
72
- calc.feed.should_not be_nil
72
+ expect(calc.feed).not_to be_nil
73
73
  end
74
74
  end
75
- end
75
+ end
@@ -5,44 +5,44 @@ describe Momm::Feeds::ECB do
5
5
  it "cannot call new method do" do
6
6
  expect{
7
7
  Momm::Feeds::ECB.new
8
- }.to raise_error
8
+ }.to raise_error NoMethodError
9
9
  end
10
10
 
11
11
  it "should eager loading the ECB instance" do
12
12
  instance1 = Momm::Feeds::ECB.instance
13
13
  instance2 = Momm::Feeds::ECB.instance
14
- instance1.object_id.should == instance2.object_id
14
+ expect(instance1.object_id).to eq instance2.object_id
15
15
  end
16
16
  end
17
17
 
18
18
  describe ".currencies" do
19
19
  it 'should not be nil' do
20
- Momm::Feeds::ECB.instance.currencies.should be_a(Array)
20
+ expect(Momm::Feeds::ECB.instance.currencies).to be_a(Array)
21
21
  end
22
22
  end
23
23
 
24
24
  describe "#fetching_url" do
25
25
  it 'should not be nil' do
26
- Momm::Feeds::ECB.instance.fetching_url.should be_a String
26
+ expect(Momm::Feeds::ECB.instance.fetching_url).to be_a String
27
27
  end
28
28
  end
29
29
 
30
30
  describe "#currency_rates" do
31
31
  let(:rates) { Momm::Feeds::ECB.instance.currency_rates }
32
32
  it 'should be an array' do
33
- rates.should be_a Array
33
+ expect(rates).to be_a Array
34
34
  end
35
35
 
36
36
  it 'should contain several elements' do
37
- rates.length.should > 0
37
+ expect(rates.length > 0).to eq true
38
38
  end
39
39
 
40
40
  it 'should contain :date, :currency and :rates' do
41
- rates.all?{
41
+ expect(rates.all?{
42
42
  |rate| rate.has_key?(:date) &&
43
43
  rate.has_key?(:currency) &&
44
44
  rate.has_key?(:rate)
45
- }.should be_true
45
+ }).to eq true
46
46
  end
47
47
  end
48
- end
48
+ end
@@ -4,19 +4,23 @@ describe Momm::Memcached do
4
4
  context 'default configurations' do
5
5
 
6
6
  it 'default options should be correct' do
7
- Momm::Memcached::DEFAULT_OPTIONS.should == { connection: "localhost:11211", namespace: "momm", compress: true }
7
+ expect(Momm::Memcached::DEFAULT_OPTIONS).to eq({
8
+ connection: "localhost:11211",
9
+ namespace: "momm",
10
+ compress: true
11
+ })
8
12
  end
9
13
  end
10
14
 
11
15
  context '#initialize' do
12
16
  it 'can be initialized without params passed in' do
13
17
  momm = Momm::Memcached.new
14
- momm.client.should be_a(Dalli::Client)
18
+ expect(momm.client).to be_a(Dalli::Client)
15
19
  end
16
20
 
17
21
  it 'can be initialized' do
18
22
  momm = Momm::Memcached.new connection: '127.0.0.1:12345'
19
- momm.client.should be_a(Dalli::Client)
23
+ expect(momm.client).to be_a(Dalli::Client)
20
24
  end
21
25
  end
22
26
 
@@ -26,9 +30,9 @@ describe Momm::Memcached do
26
30
 
27
31
  money = rand(20)
28
32
  momm.set_rate :USD, money
29
- momm.get_rate(:USD).should == money
33
+ expect(momm.get_rate(:USD)).to eq money
30
34
 
31
35
  Momm.update!
32
36
  end
33
37
  end
34
- end
38
+ end
@@ -3,36 +3,36 @@ require 'spec_helper'
3
3
  describe Momm do
4
4
  context "Calculator delegation" do
5
5
  it "should respond to exchange_rate" do
6
- Momm.should respond_to :exchange_rate
6
+ expect(Momm).to respond_to :exchange_rate
7
7
  end
8
8
 
9
9
  it "should respond to exchange" do
10
- Momm.should respond_to :exchange
10
+ expect(Momm).to respond_to :exchange
11
11
  end
12
12
 
13
13
  it "should respond to exchange_from_gbp_to_usd" do
14
- Momm.should respond_to :exchange_from_gbp_to_usd
14
+ expect(Momm).to respond_to :exchange_from_gbp_to_usd
15
15
  end
16
16
 
17
17
  it "should respond to exchange_rate_from_gbp_to_usd" do
18
- Momm.should respond_to :exchange_rate_from_gbp_to_usd
18
+ expect(Momm).to respond_to :exchange_rate_from_gbp_to_usd
19
19
  end
20
20
 
21
21
  it "should respond to update!" do
22
- Momm.should respond_to :update!
22
+ expect(Momm).to respond_to :update!
23
23
  end
24
24
  end
25
25
 
26
26
  describe "bridge delegation" do
27
27
  it "should be successfully switch to redis store halfway" do
28
28
  Momm.store :redis_store
29
- Momm.send(:calculator).storage.client.should be_a(Redis::Namespace)
29
+ expect(Momm.send(:calculator).storage.client).to be_a(Redis::Namespace)
30
30
  Momm.store :memcached
31
31
  end
32
32
 
33
33
  it "should be successfully switch to ECB halfway" do
34
34
  Momm.source :ECB
35
- Momm.send(:calculator).feed.should be_a(Momm::Feeds::ECB)
35
+ expect(Momm.send(:calculator).feed).to be_a(Momm::Feeds::ECB)
36
36
  end
37
37
  end
38
38
 
@@ -42,10 +42,10 @@ describe Momm do
42
42
  store :redis_store
43
43
  end
44
44
 
45
- Momm.send(:calculator).storage.should be_a(Momm::RedisStore)
46
- Momm.send(:calculator).feed.should be_a(Momm::Feeds::ECB)
45
+ expect(Momm.send(:calculator).storage).to be_a(Momm::RedisStore)
46
+ expect(Momm.send(:calculator).feed).to be_a(Momm::Feeds::ECB)
47
47
 
48
48
  Momm.store :memcached
49
49
  end
50
50
  end
51
- end
51
+ end