redis_knock 0.0.1 → 0.0.2

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.
@@ -2,7 +2,8 @@
2
2
 
3
3
  module RedisKnock
4
4
  class Control
5
- def initialize(options)
5
+ def initialize(args)
6
+ options = convert_keys_to_symbols args
6
7
  check! options
7
8
 
8
9
  @client = get_connection options[:redis]
@@ -21,6 +22,14 @@ module RedisKnock
21
22
 
22
23
  private
23
24
 
25
+ def convert_keys_to_symbols(args)
26
+ args.keys.inject({}) do |hash, key|
27
+ value = args[key]
28
+ hash[key.to_sym] = value.is_a?(Hash) ? convert_keys_to_symbols(value) : value
29
+ hash
30
+ end
31
+ end
32
+
24
33
  def check!(options)
25
34
  raise ArgumentError.new('A limit must be supplied') if options[:limit].nil?
26
35
  raise ArgumentError.new('A interval must be supplied') if options[:interval].nil?
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  module RedisKnock
4
- VERSION = '0.0.1'
4
+ VERSION = '0.0.2'
5
5
  end
@@ -15,7 +15,19 @@ describe RedisKnock::Control do
15
15
  let(:redis_options) { { :host => host, :port => port, :db => db } }
16
16
  let(:options) { { :limit => limit, :interval => interval, :redis => redis_options } }
17
17
 
18
- context 'invalid arguments validation' do
18
+ describe 'converting hash keys to symbols' do
19
+ it 'serializes all attributes recursively' do
20
+ args = { 'limit' => limit, 'interval' => interval, 'redis' => { 'host' => host, 'port' => port, 'db' => db } }
21
+
22
+ Redis.should_receive(:new).with(redis_options).and_return(redis_client)
23
+
24
+ control = subject.new args
25
+ control.instance_variable_get('@limit').should == limit
26
+ control.instance_variable_get('@interval').should == interval
27
+ end
28
+ end
29
+
30
+ describe 'invalid arguments validation' do
19
31
  it 'raises ArgumentError if limit is not informed' do
20
32
  options.delete :limit
21
33
 
@@ -61,7 +73,7 @@ describe RedisKnock::Control do
61
73
  end
62
74
  end
63
75
 
64
- context 'when cannot connect to Redis server' do
76
+ describe 'when cannot connect to Redis server' do
65
77
  it 'raises ConnectionError' do
66
78
  Redis.should_receive(:new).and_raise('An error')
67
79
 
@@ -70,7 +82,7 @@ describe RedisKnock::Control do
70
82
  end
71
83
  end
72
84
 
73
- context 'checking for allowed requests' do
85
+ describe 'checking for allowed requests' do
74
86
  before :each do
75
87
  Redis.should_receive(:new).with(redis_options).and_return(redis_client)
76
88
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis_knock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-18 00:00:00.000000000 Z
12
+ date: 2012-01-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &70260527478660 !ruby/object:Gem::Requirement
16
+ requirement: &70120181868400 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70260527478660
24
+ version_requirements: *70120181868400
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70260527403560 !ruby/object:Gem::Requirement
27
+ requirement: &70120181789120 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70260527403560
35
+ version_requirements: *70120181789120
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rack-test
38
- requirement: &70260527402640 !ruby/object:Gem::Requirement
38
+ requirement: &70120181788220 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70260527402640
46
+ version_requirements: *70120181788220
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: redis
49
- requirement: &70260527401620 !ruby/object:Gem::Requirement
49
+ requirement: &70120181787240 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70260527401620
57
+ version_requirements: *70120181787240
58
58
  description: The gem redis_knock implements a HTTP Throttle Control engine using Redis
59
59
  to store rate-limiting IP's.
60
60
  email: