ciclope 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -10,26 +10,25 @@ Configuration
10
10
 
11
11
  Only has to specify a array of two or more Rails database config names:
12
12
 
13
- > Ciclope.connections = [:production, :production\_in\_aws, :production\_in\_other_location]
13
+ Ciclope.connections = [:production, :production\_in\_aws, :production\_in\_other_location]
14
14
 
15
15
  The ring will be auto-sorted guessing the master host for each connection, you could bypass this feature setting:
16
16
 
17
- > Ciclope.auto\_sort\_connections = false
17
+ Ciclope.auto\_sort\_connections = false
18
18
 
19
19
  Use
20
20
  ---
21
21
 
22
22
  Actually there is one class methods to inspect replication data and one to show seconds behind master:
23
23
 
24
- > Ciclope.replication\_status \# => returns a array of hashes with replication data
24
+ Ciclope.replication\_status \# => returns a array of hashes with replication data
25
25
 
26
- > Ciclope.replication\_seconds\_behind\_master # => returns a simple string with the host status like:
26
+ Ciclope.replication\_seconds\_behind\_master # => returns a simple string with the host status like:
27
27
 
28
- >> host1 ––– 0 seconds –––> host2 ––– 0 seconds –––> host3 ––– 0 seconds –––> host1
28
+ host1 ––– 0 seconds –––> host2 ––– 0 seconds –––> host3 ––– 0 seconds –––> host1
29
29
 
30
30
  TODO
31
31
  ----
32
-
33
32
  Extend and refact in order to let work with others frameworks ruby based (Sinatra, Merb), and others ORMs (DataMapper).
34
33
 
35
34
  Licence
data/lib/ciclope/host.rb CHANGED
@@ -28,16 +28,17 @@ module Ciclope
28
28
  cleanfy_log_name relay_log_file.split('.').first
29
29
  end
30
30
 
31
- def master_log_file
31
+ # rename becuse there is a key with the same name
32
+ def _master_log_file
32
33
  cleanfy_log_name relay_master_log_file.split('.').first
33
34
  end
34
35
 
35
36
  # sort by log file names, there is no way to do this by host names, may be there is another way to do this more clean
36
37
  # TODO: find the right sort
37
38
  def <=>(other)
38
- if log_file == other.master_log_file
39
+ if log_file == other._master_log_file
39
40
  1
40
- elsif other.log_file == master_log_file
41
+ elsif other.log_file == _master_log_file
41
42
  -1
42
43
  else
43
44
  0
data/lib/ciclope/ring.rb CHANGED
@@ -19,6 +19,7 @@ module Ciclope
19
19
 
20
20
  connections.each do |c|
21
21
  config = Rails.configuration.database_configuration[c.to_s]
22
+ next if config['adapter'] != 'mysql'
22
23
  @hosts << Host.new(ActiveRecord::Base.mysql_connection(config)) if config
23
24
  end
24
25
 
@@ -1,3 +1,3 @@
1
1
  module Ciclope
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,8 @@
1
+ require File.dirname(__FILE__) + '/../lib/ciclope.rb'
2
+
3
+ describe Ciclope do
4
+ it "connections must be configurated with two or more connection names through 'connections' class variable" do
5
+ lambda { Ciclope.replication_seconds_behind_master }.should raise_exception(Ciclope::Ring::NotEnoughConnections)
6
+ end
7
+
8
+ end
data/spec/host_spec.rb ADDED
@@ -0,0 +1,13 @@
1
+ require File.dirname(__FILE__) + '/../lib/ciclope.rb'
2
+
3
+ describe Ciclope::Host do
4
+ it "must be initialized with a mysql connection" do
5
+ lambda { Ciclope::Host.new }.should raise_error
6
+ end
7
+
8
+ it "must be valid" do
9
+ c = mock(:connection, :select_one => { "Master_Log_File" => "L", "Relay_Master_Log_File" => "ML", "Seconds_Behind_Master" => "0" })
10
+ h = Ciclope::Host.new(c)
11
+ h.should be_an_instance_of Ciclope::Host
12
+ end
13
+ end
data/spec/ring_spec.rb ADDED
@@ -0,0 +1,21 @@
1
+ require File.dirname(__FILE__) + '/../lib/ciclope.rb'
2
+
3
+ module Rails
4
+ end
5
+
6
+ describe Ciclope::Ring do
7
+ before do
8
+ config = mock :configuration, :database_configuration => { :c1 => {}, :c2 => {} }
9
+ Rails.stub!(:configuration).and_return(config)
10
+ end
11
+
12
+ it "must be configurated with two or more connection names through 'Ciclope.connections' class variable" do
13
+ lambda { Ciclope::Ring.new }.should raise_exception(Ciclope::Ring::NotEnoughConnections)
14
+ end
15
+
16
+ it "must be valid" do
17
+ r = Ciclope::Ring.new(:c1, :c2)
18
+ r.should be_an_instance_of Ciclope::Ring
19
+ end
20
+
21
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ciclope
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Hugo Geronimo Diaz
@@ -78,6 +78,9 @@ files:
78
78
  - lib/ciclope/host.rb
79
79
  - lib/ciclope/ring.rb
80
80
  - lib/ciclope/version.rb
81
+ - spec/ciclope_spec.rb
82
+ - spec/host_spec.rb
83
+ - spec/ring_spec.rb
81
84
  homepage: http://github.com/geronimod/ciclope
82
85
  licenses: []
83
86
 
@@ -111,5 +114,7 @@ rubygems_version: 1.8.12
111
114
  signing_key:
112
115
  specification_version: 3
113
116
  summary: Simple MySQL Replication Utility.
114
- test_files: []
115
-
117
+ test_files:
118
+ - spec/ciclope_spec.rb
119
+ - spec/host_spec.rb
120
+ - spec/ring_spec.rb