schlep 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/schlep.rb CHANGED
@@ -2,11 +2,12 @@ require "schlep/version"
2
2
 
3
3
  require "json"
4
4
  require "redis"
5
+ require "uri"
5
6
 
6
7
  module Schlep
7
8
  extend self
8
9
 
9
- attr_writer :app, :hostname
10
+ attr_writer :app, :hostname, :redis_url
10
11
 
11
12
  def app
12
13
  @app ||= ""
@@ -37,11 +38,27 @@ module Schlep
37
38
  end
38
39
 
39
40
  def redis
40
- @redis ||= Redis.new
41
+ @redis ||= Redis.new redis_options
42
+ end
43
+
44
+ def redis_options
45
+ return {} unless redis_url
46
+
47
+ parsed_url = URI::parse(redis_url)
48
+
49
+ {
50
+ :host => parsed_url.host,
51
+ :port => parsed_url.port,
52
+ :password => parsed_url.password
53
+ }
54
+ end
55
+
56
+ def redis_url
57
+ @redis_url ||= ENV["REDIS_URL"] or ENV["REDISTOGO_URL"]
41
58
  end
42
59
 
43
60
  def reset
44
- %w[app hostname redis].each do |ivar|
61
+ %w[app hostname redis redis_url].each do |ivar|
45
62
  instance_variable_set "@#{ivar}", nil
46
63
  end
47
64
  end
@@ -1,3 +1,3 @@
1
1
  module Schlep
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/test/schlep_test.rb CHANGED
@@ -5,6 +5,16 @@ rescue LoadError
5
5
  end
6
6
 
7
7
  class SchlepTest < Test::Unit::TestCase
8
+ def setup
9
+ Schlep.reset
10
+ end
11
+
12
+ def teardown
13
+ %w[REDIS_URL REDISTOGO_URL].each do |e|
14
+ ENV[e] = nil
15
+ end
16
+ end
17
+
8
18
  context "schlep" do
9
19
  should "be defined as a module" do
10
20
  assert_equal Module, Schlep.class
@@ -13,21 +23,25 @@ class SchlepTest < Test::Unit::TestCase
13
23
 
14
24
  context "configure" do
15
25
  should "be configurable with setters" do
16
- Schlep.app = "test_app_1"
17
- Schlep.hostname = "test_hostname_1"
26
+ Schlep.app = "test_app_1"
27
+ Schlep.hostname = "test_hostname_1"
28
+ Schlep.redis_url = "redis://localhost:1234"
18
29
 
19
- assert_equal "test_app_1", Schlep.app, "app"
20
- assert_equal "test_hostname_1", Schlep.hostname, "hostname"
30
+ assert_equal "test_app_1", Schlep.app, "app"
31
+ assert_equal "test_hostname_1", Schlep.hostname, "hostname"
32
+ assert_equal "redis://localhost:1234", Schlep.redis_url, "redis_url"
21
33
  end
22
34
 
23
35
  should "be configurable with a block" do
24
36
  Schlep.configure do |config|
25
- config.app = "test_app_2"
26
- config.hostname = "test_hostname_2"
37
+ config.app = "test_app_2"
38
+ config.hostname = "test_hostname_2"
39
+ config.redis_url = "redis://localhost:4321"
27
40
  end
28
41
 
29
- assert_equal "test_app_2", Schlep.app, "app"
30
- assert_equal "test_hostname_2", Schlep.hostname, "hostname"
42
+ assert_equal "test_app_2", Schlep.app, "app"
43
+ assert_equal "test_hostname_2", Schlep.hostname, "hostname"
44
+ assert_equal "redis://localhost:4321", Schlep.redis_url, "redis_url"
31
45
  end
32
46
  end
33
47
 
@@ -45,6 +59,45 @@ class SchlepTest < Test::Unit::TestCase
45
59
  end
46
60
  end
47
61
 
62
+ context "redis_url" do
63
+ should "connect locally by default" do
64
+ assert_equal "127.0.0.1", Schlep.redis.client.host
65
+ assert_equal 6379, Schlep.redis.client.port
66
+ end
67
+
68
+ should "connect to a basic url" do
69
+ Schlep.redis_url = "redis://1.2.3.4:1234"
70
+
71
+ assert_equal "1.2.3.4", Schlep.redis.client.host
72
+ assert_equal 1234, Schlep.redis.client.port
73
+ assert_nil Schlep.redis.client.password
74
+ end
75
+
76
+ should "connect to a url with a username and password" do
77
+ Schlep.redis_url = "redis://redis:password@1.2.3.4:1234"
78
+
79
+ assert_equal "1.2.3.4", Schlep.redis.client.host
80
+ assert_equal 1234, Schlep.redis.client.port
81
+ assert_equal "password", Schlep.redis.client.password
82
+ end
83
+
84
+ should "detect the url from ENV[\"REDIS_URL\"]" do
85
+ ENV["REDIS_URL"] = "redis://redis:secret@4.3.2.1:4321"
86
+
87
+ assert_equal "4.3.2.1", Schlep.redis.client.host
88
+ assert_equal 4321, Schlep.redis.client.port
89
+ assert_equal "secret", Schlep.redis.client.password
90
+ end
91
+
92
+ should "detect the url from ENV[\"REDISTOGO_URL\"]" do
93
+ ENV["REDISTOGO_URL"] = "redis://redis:secret@4.3.2.1:4321"
94
+
95
+ assert_equal "4.3.2.1", Schlep.redis.client.host
96
+ assert_equal 4321, Schlep.redis.client.port
97
+ assert_equal "secret", Schlep.redis.client.password
98
+ end
99
+ end
100
+
48
101
  context "reset" do
49
102
  should "reset instance variables to nil" do
50
103
  Schlep.configure do |config|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schlep
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
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: 2011-12-12 00:00:00.000000000 Z
12
+ date: 2011-12-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redis
16
- requirement: &70138116747200 !ruby/object:Gem::Requirement
16
+ requirement: &70137973953740 !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: :runtime
23
23
  prerelease: false
24
- version_requirements: *70138116747200
24
+ version_requirements: *70137973953740
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: guard-test
27
- requirement: &70138116746760 !ruby/object:Gem::Requirement
27
+ requirement: &70137973953300 !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: *70138116746760
35
+ version_requirements: *70137973953300
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &70138116746340 !ruby/object:Gem::Requirement
38
+ requirement: &70137973952880 !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: *70138116746340
46
+ version_requirements: *70137973952880
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: shoulda
49
- requirement: &70138116745900 !ruby/object:Gem::Requirement
49
+ requirement: &70137973952300 !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: :development
56
56
  prerelease: false
57
- version_requirements: *70138116745900
57
+ version_requirements: *70137973952300
58
58
  description: Ruby client for schlep. Schlep provides a simple interface for logging
59
59
  and broadcasting events.
60
60
  email: