diff options
author | Azul <azul@riseup.net> | 2012-09-11 13:02:27 +0200 |
---|---|---|
committer | Azul <azul@riseup.net> | 2012-09-11 13:02:27 +0200 |
commit | c0fc5ac5b5d955b1789a58153952e43bb7052b07 (patch) | |
tree | fd9b3e98cd9c75c09b33c4ee8e8af3996309abb4 | |
parent | c331d70638c35d807128e39a9958cab5ba4eeb25 (diff) |
configuring couchDB the CouchRest way and using that for tracking
-rw-r--r-- | config.yml | 2 | ||||
-rw-r--r-- | config/couchdb.yml.example | 8 | ||||
-rw-r--r-- | leap_ca.rb | 7 | ||||
-rw-r--r-- | lib/config.rb | 18 | ||||
-rw-r--r-- | lib/couch_stream.rb | 6 | ||||
-rw-r--r-- | test/unit/config.yml | 2 | ||||
-rw-r--r-- | test/unit/config_test.rb | 14 | ||||
-rw-r--r-- | test/unit/couch_stream_test.rb | 6 |
8 files changed, 17 insertions, 46 deletions
diff --git a/config.yml b/config.yml deleted file mode 100644 index c78104d..0000000 --- a/config.yml +++ /dev/null @@ -1,2 +0,0 @@ -database: salticidae_certs -server: http://localhost:5984 diff --git a/config/couchdb.yml.example b/config/couchdb.yml.example new file mode 100644 index 0000000..1dd5fef --- /dev/null +++ b/config/couchdb.yml.example @@ -0,0 +1,8 @@ +development: + protocol: 'https' + host: sample.cloudant.com + port: 443 + prefix: project + suffix: test + username: test + password: user @@ -2,15 +2,14 @@ require 'rubygems' require 'yajl/http_stream' -require 'lib/config' +require 'lib/cert' require 'lib/couch_stream' require 'lib/couch_changes' def main - config = LeapCA::Config.new(File.expand_path("../config.yml", __FILE__)) - p "Tracking #{config.database} on #{config.server}" - couch = CouchStream.new(config) + puts "Tracking #{Cert.database.root}" + couch = CouchStream.new(Cert.database.root) changes = CouchChanges.new(couch) changes.follow do |hash| p hash diff --git a/lib/config.rb b/lib/config.rb deleted file mode 100644 index dded140..0000000 --- a/lib/config.rb +++ /dev/null @@ -1,18 +0,0 @@ -require 'yaml' - -module LeapCA - class Config - def initialize(filename) - file = File.new(filename, 'r') - @hash = YAML::load(file) - end - - def server - @hash['server'] - end - - def database - @hash['database'] - end - end -end diff --git a/lib/couch_stream.rb b/lib/couch_stream.rb index 081688a..ed56db2 100644 --- a/lib/couch_stream.rb +++ b/lib/couch_stream.rb @@ -1,6 +1,6 @@ class CouchStream - def initialize(config) - @config = config + def initialize(database_url) + @database_url = database_url end def get(path, options) @@ -14,7 +14,7 @@ class CouchStream protected def url_for(path, options = {}) - url = [@config.server, @config.database, path].join('/') + url = [@database_url, path].join('/') url += '?' if options.any? url += options.map {|k,v| "#{k}=#{v}"}.join('&') end diff --git a/test/unit/config.yml b/test/unit/config.yml deleted file mode 100644 index 725e5af..0000000 --- a/test/unit/config.yml +++ /dev/null @@ -1,2 +0,0 @@ -database: test-db -server: test-server diff --git a/test/unit/config_test.rb b/test/unit/config_test.rb deleted file mode 100644 index 545bedd..0000000 --- a/test/unit/config_test.rb +++ /dev/null @@ -1,14 +0,0 @@ -require 'test_helper' -require 'lib/config' - -class ConfigTest < MiniTest::Unit::TestCase - - def setup - @config = LeapCA::Config.new(File.expand_path("../config.yml", __FILE__)) - end - - def test_initial_content - assert_equal 'test-server', @config.server - assert_equal 'test-db', @config.database - end -end diff --git a/test/unit/couch_stream_test.rb b/test/unit/couch_stream_test.rb index 438049b..af5a34e 100644 --- a/test/unit/couch_stream_test.rb +++ b/test/unit/couch_stream_test.rb @@ -10,9 +10,9 @@ end class CouchStreamTest < MiniTest::Unit::TestCase def setup - @config = stub(:server => "http://server", :database => "database") - @stream = CouchStream.new(@config) - @url = "http://server/database/_changes?c=d&a=b" + @root = "http://server/database" + @stream = CouchStream.new(@root) + @url = @root + "/_changes?a=b&c=d" @path = "_changes" @options = {:a => :b, :c => :d} end |