momm 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -2
- data/examples/rails_app/config/initializers/momm_initializer.rb +3 -0
- data/lib/momm.rb +16 -37
- data/lib/momm/bridge.rb +47 -0
- data/lib/momm/version.rb +1 -1
- data/spec/momm/bridge_spec.rb +26 -0
- data/spec/momm/momm_spec.rb +19 -1
- data/spec/momm/version_spec.rb +1 -1
- metadata +6 -3
- data/examples/rails_app/config/initializers/momm.rb +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d4fcb3d9c4bd72a12fe00f385a990f5687cde25
|
4
|
+
data.tar.gz: c7cdcb1425605cfcd312f86378bb43385ebd13ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c1df21f53643262c53f47dd2bcec2b7e947c9f209a592d481e84dc0c0e952a14bb2a7f211b3197f7cc8836d1164ff5851543e9c3f4529cc4f4a25008923e439
|
7
|
+
data.tar.gz: 176f324ad735b62a0931fa4e56399b12d0d0491165f1543e1814c48320e31022ecf089f3366283470510bb46f5196eae14d95556986ee194081d9a75b21a24f3
|
data/README.md
CHANGED
@@ -87,6 +87,12 @@ After the gem is installed, momm provide you a command line tool. The storage en
|
|
87
87
|
Momm.store :redis_store # Use redis as the default storage
|
88
88
|
|
89
89
|
Momm.fed :ECB # Use ECB as the default currency exchange feeds
|
90
|
+
|
91
|
+
# Favoured way of configuration
|
92
|
+
Momm.setup do
|
93
|
+
store :redis_store, host: "127.0.0.1", namespace: "green_tea"
|
94
|
+
end
|
95
|
+
|
90
96
|
```
|
91
97
|
|
92
98
|
### Momm on Rails
|
@@ -109,8 +115,9 @@ The default Storage is Memcached, if you want to switch to Redis, you can create
|
|
109
115
|
``` ruby
|
110
116
|
|
111
117
|
# momm_initialzer.rb
|
112
|
-
Momm.
|
113
|
-
|
118
|
+
Momm.setup do
|
119
|
+
store :redis_store, host: "127.0.0.1", namespace: "green_tea"
|
120
|
+
end
|
114
121
|
```
|
115
122
|
|
116
123
|
After boot your rails application, you can visit '/momm'. A mounted app has already been in place.
|
data/lib/momm.rb
CHANGED
@@ -6,62 +6,41 @@ require "momm/storage"
|
|
6
6
|
require "momm/memcached"
|
7
7
|
require "momm/redis_store"
|
8
8
|
require "momm/calculator"
|
9
|
+
require "momm/bridge"
|
9
10
|
require "momm/rails"
|
10
11
|
module Momm
|
11
12
|
|
12
13
|
class << self
|
13
14
|
extend ::Forwardable
|
14
15
|
|
15
|
-
#
|
16
|
+
# Default options setup
|
16
17
|
#
|
17
|
-
# ==
|
18
|
-
#
|
19
|
-
# :redis_store
|
18
|
+
# == Example
|
19
|
+
# Momm.setup do
|
20
|
+
# store :redis_store, host: "127.0.0.1"
|
21
|
+
# end
|
20
22
|
#
|
21
|
-
|
22
|
-
|
23
|
-
#
|
24
|
-
# == Examples
|
25
|
-
# store :redis_store, port: 12345
|
26
|
-
#
|
27
|
-
def store(storage_name, **kv)
|
28
|
-
@storage = begin
|
29
|
-
name = storage_name.to_s.split('_').map(&:capitalize).join
|
30
|
-
klass = Kernel.const_get("Momm::#{name}")
|
31
|
-
|
32
|
-
klass.new **kv
|
33
|
-
end
|
23
|
+
def setup(&block)
|
24
|
+
bridge.instance_eval(&block)
|
34
25
|
end
|
35
26
|
|
36
|
-
# Inject the storage into class variable
|
37
|
-
#
|
38
|
-
# == Parameters
|
39
|
-
# feed_name::
|
40
|
-
# currently only support ECB
|
41
|
-
#
|
42
|
-
# == Returns
|
43
|
-
# the picked feed
|
44
|
-
#
|
45
|
-
# == Examples
|
46
|
-
# source :ECB (which is by default)
|
47
|
-
#
|
48
|
-
def source(feed_name)
|
49
|
-
@feed = Kernel.const_get("Momm::Feeds::#{feed_name}").instance
|
50
|
-
end
|
51
|
-
|
52
|
-
attr_reader :storage, :feed
|
53
|
-
|
54
27
|
# delegate the exchange, :currencies, exchange_rate,
|
55
28
|
# as well as meta programmed methods to module level
|
56
29
|
delegate [:currencies, :exchange, :exchange_rate,
|
57
30
|
:method_missing, :respond_to?, :update! ] => :calculator
|
58
31
|
|
32
|
+
delegate [:store, :source ] => :bridge
|
33
|
+
|
59
34
|
private
|
60
35
|
|
61
36
|
# Delegate the calculator
|
62
37
|
def calculator
|
63
|
-
@calculator = Calculator.new
|
64
|
-
|
38
|
+
@calculator = Calculator.new bridge.storage, bridge.feed
|
39
|
+
end
|
40
|
+
|
41
|
+
# Delegate the bridge
|
42
|
+
def bridge
|
43
|
+
@bridge ||= Bridge.new
|
65
44
|
end
|
66
45
|
end
|
67
46
|
|
data/lib/momm/bridge.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
module Momm
|
2
|
+
class Bridge
|
3
|
+
def initialize(options={})
|
4
|
+
@storage = options[:store] || Memcached.new
|
5
|
+
@feed = options[:feed] || Feeds::ECB.instance
|
6
|
+
end
|
7
|
+
|
8
|
+
# Inject the storage
|
9
|
+
#
|
10
|
+
# == Parameters
|
11
|
+
# storage_name::
|
12
|
+
# :redis_store or memcached. Memcached is set as default.
|
13
|
+
#
|
14
|
+
# == Returns
|
15
|
+
# the picked storage
|
16
|
+
#
|
17
|
+
# == Examples
|
18
|
+
# store :redis_store, port: 12345
|
19
|
+
#
|
20
|
+
def store(storage_name, **kv)
|
21
|
+
@storage = begin
|
22
|
+
name = storage_name.to_s.split('_').map(&:capitalize).join
|
23
|
+
klass = Kernel.const_get("Momm::#{name}")
|
24
|
+
|
25
|
+
klass.new **kv
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Inject the feed
|
30
|
+
#
|
31
|
+
# == Parameters
|
32
|
+
# feed_name::
|
33
|
+
# currently only support ECB
|
34
|
+
#
|
35
|
+
# == Returns
|
36
|
+
# the picked feed
|
37
|
+
#
|
38
|
+
# == Examples
|
39
|
+
# source :ECB (which is by default)
|
40
|
+
#
|
41
|
+
def source(feed_name)
|
42
|
+
@feed = Kernel.const_get("Momm::Feeds::#{feed_name}").instance
|
43
|
+
end
|
44
|
+
|
45
|
+
attr_reader :storage, :feed
|
46
|
+
end
|
47
|
+
end
|
data/lib/momm/version.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Momm::Bridge do
|
4
|
+
describe '#initialize' do
|
5
|
+
it 'should have default' do
|
6
|
+
bridge = Momm::Bridge.new
|
7
|
+
|
8
|
+
bridge.storage.should be_a(Momm::Memcached)
|
9
|
+
bridge.feed.should be_a(Momm::Feeds::ECB)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#store' do
|
14
|
+
let(:bridge) { Momm::Bridge.new }
|
15
|
+
|
16
|
+
it 'should change the storage' do
|
17
|
+
bridge.store :redis_store
|
18
|
+
bridge.storage.should be_a(Momm::RedisStore)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should change the ECB' do
|
22
|
+
bridge.source :ECB
|
23
|
+
bridge.feed.should be_a(Momm::Feeds::ECB)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/spec/momm/momm_spec.rb
CHANGED
@@ -23,11 +23,29 @@ describe Momm do
|
|
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
29
|
Momm.send(:calculator).storage.client.should be_a(Redis::Namespace)
|
30
30
|
Momm.store :memcached
|
31
31
|
end
|
32
|
+
|
33
|
+
it "should be successfully switch to ECB halfway" do
|
34
|
+
Momm.source :ECB
|
35
|
+
Momm.send(:calculator).feed.should be_a(Momm::Feeds::ECB)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe ".setup" do
|
40
|
+
it "can config" do
|
41
|
+
Momm.setup do
|
42
|
+
store :redis_store
|
43
|
+
end
|
44
|
+
|
45
|
+
Momm.send(:calculator).storage.should be_a(Momm::RedisStore)
|
46
|
+
Momm.send(:calculator).feed.should be_a(Momm::Feeds::ECB)
|
47
|
+
|
48
|
+
Momm.store :memcached
|
49
|
+
end
|
32
50
|
end
|
33
51
|
end
|
data/spec/momm/version_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: momm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jingkai He
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
@@ -171,7 +171,7 @@ files:
|
|
171
171
|
- examples/rails_app/config/initializers/filter_parameter_logging.rb
|
172
172
|
- examples/rails_app/config/initializers/inflections.rb
|
173
173
|
- examples/rails_app/config/initializers/mime_types.rb
|
174
|
-
- examples/rails_app/config/initializers/
|
174
|
+
- examples/rails_app/config/initializers/momm_initializer.rb
|
175
175
|
- examples/rails_app/config/initializers/secret_token.rb
|
176
176
|
- examples/rails_app/config/initializers/session_store.rb
|
177
177
|
- examples/rails_app/config/initializers/wrap_parameters.rb
|
@@ -189,6 +189,7 @@ files:
|
|
189
189
|
- examples/rails_app/vendor/assets/javascripts/.keep
|
190
190
|
- examples/rails_app/vendor/assets/stylesheets/.keep
|
191
191
|
- lib/momm.rb
|
192
|
+
- lib/momm/bridge.rb
|
192
193
|
- lib/momm/calculator.rb
|
193
194
|
- lib/momm/feeds/ecb.rb
|
194
195
|
- lib/momm/memcached.rb
|
@@ -198,6 +199,7 @@ files:
|
|
198
199
|
- lib/momm/version.rb
|
199
200
|
- lib/momm/web.rb
|
200
201
|
- momm.gemspec
|
202
|
+
- spec/momm/bridge_spec.rb
|
201
203
|
- spec/momm/calculator_spec.rb
|
202
204
|
- spec/momm/feeds/ecb_spec.rb
|
203
205
|
- spec/momm/memcached_spec.rb
|
@@ -235,6 +237,7 @@ signing_key:
|
|
235
237
|
specification_version: 4
|
236
238
|
summary: A Currency Exchange Calculator
|
237
239
|
test_files:
|
240
|
+
- spec/momm/bridge_spec.rb
|
238
241
|
- spec/momm/calculator_spec.rb
|
239
242
|
- spec/momm/feeds/ecb_spec.rb
|
240
243
|
- spec/momm/memcached_spec.rb
|