summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2012-09-11 12:35:41 +0200
committerAzul <azul@riseup.net>2012-09-11 12:35:41 +0200
commitc331d70638c35d807128e39a9958cab5ba4eeb25 (patch)
tree329667af3f1624fbe49dd6260dd5c032f64fd7ba /lib
parenta52f357906ed5f54b7a3b64e54be79db83c58e7c (diff)
added config class
Diffstat (limited to 'lib')
-rw-r--r--lib/config.rb18
-rw-r--r--lib/couch_stream.rb9
2 files changed, 22 insertions, 5 deletions
diff --git a/lib/config.rb b/lib/config.rb
new file mode 100644
index 0000000..dded140
--- /dev/null
+++ b/lib/config.rb
@@ -0,0 +1,18 @@
+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 bed296a..081688a 100644
--- a/lib/couch_stream.rb
+++ b/lib/couch_stream.rb
@@ -1,7 +1,6 @@
class CouchStream
- def initialize(server, db)
- @server = server
- @db = db
+ def initialize(config)
+ @config = config
end
def get(path, options)
@@ -11,11 +10,11 @@ class CouchStream
yield(hash)
end
end
-
+
protected
def url_for(path, options = {})
- url = @server + @db + '/' + path
+ url = [@config.server, @config.database, path].join('/')
url += '?' if options.any?
url += options.map {|k,v| "#{k}=#{v}"}.join('&')
end