Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

moving to mongo

  • Loading branch information...
commit aa3192b6eb96343a6c3d2fbac30c10a9fb7364b6 1 parent b455cce
@yonkeltron yonkeltron authored
View
4 libscosugbot.rb
@@ -1,6 +1,4 @@
#!/usr/bin/env ruby
-require 'libscosugbot/config'
require 'libscosugbot/pstorestorage'
-require 'libscosugbot/couchstorage'
-
+require 'libscosugbot/mongostorage'
View
11 libscosugbot/config.rb
@@ -1,12 +1,19 @@
#!/usr/bin/env
+require 'rubygems'
require 'yaml'
+require 'relaxdb'
module LibScosugBot
class Config
def self.couch
- config = YAML.load_file('config.yml')
- "http://#{config['couchdb']['host']}:#{config['couchdb']['port']}/#{config['couchdb']['db']}"
+ @config ||= YAML.load_file('config.yml')['couchdb']
+ RelaxDB.configure :host => @config['host'], :port => @config['port']
+ RelaxDB.use_db @config['db']
+ RelaxDB.enable_view_creation
+ RelaxDB::View.design_doc.save
+ @config
end
end
end
+
View
34 libscosugbot/couchstorage.rb
@@ -1,34 +0,0 @@
-#!/usr/bin/env ruby
-
-require 'rubygems'
-require 'couchrest'
-
-module LibScosugBot
- module Storage
- class CouchStore
- attr_reader :host, :dbname, :port, :db
- def initialize(host, port, dbname)
- @host = host
- @port = port
- @dbname = dbname
- @db = CouchRest.database!("http://#{@host}:#{@port}/#{@dbname}")
- end
- end
-
- class Definition < CouchRest::ExtendedDocument
- include CouchRest::Validation
-
- use_database CouchRest.database!(LibScosugBot::Config.couch)
-
- property :type, :read_only => true
-
- property :name
- property :definitions, :cast_as => ['String']
-
- timestamps!
-
- validates_presence_of :name
- validates_presence_of :definitions
- end
- end
-end
View
44 libscosugbot/mongostorage.rb
@@ -0,0 +1,44 @@
+#!/usr/bin/env ruby
+
+require 'rubygems'
+require 'mongoid'
+require 'mongo'
+
+module LibScosugBot
+ module Storage
+ module MongoDB
+ class MongoStore
+ attr_accessor :db
+
+ def initialize(dbname, host = 'localhost', port = '27017')
+ @db = Mongo::Connection.new(host, port).db(dbname)
+ Mongoid.configure do |config|
+ config.master = @db
+ end
+ end
+
+ def memorize(key,val)
+ Definition.create!(:term => key, :contents => val)
+ end
+
+ def recall(key)
+ Definition.first(:conditions => {:term => key})
+ end
+
+ def log(message, priority, service = 'system')
+ end
+
+ end
+
+ class Definition
+ include Mongoid::Document
+ include Mongoid::Timestamps
+
+ field :term, :type => String
+ field :contents, :type => String
+
+ index :term, :background => true
+ end
+ end
+ end
+end
View
44 specs/couch/couch_basic_spec.rb
@@ -1,44 +0,0 @@
-require 'libscosugbot'
-require 'specs/spec_helper'
-
-describe LibScosugBot::Storage::CouchStore do
-
- before(:each) do
- @host = COUCHHOST
- @port = COUCHPORT
- @dbname = TESTDB
- @cs = LibScosugBot::Storage::CouchStore.new(@host, @port, @dbname)
- end
-
- after(:each) do
- @cs.db.delete! #rescue nil
- end
-
- describe "should assign config variables properly with readers" do
-
- it "and provide host reader" do
- @cs.should respond_to(:host)
- end
-
- it "and assign host properly" do
- @cs.host.should eql(@host)
- end
-
- it "and provide port reader" do
- @cs.should respond_to(:port)
- end
-
- it "and assign port properly" do
- @cs.port.should eql(@port)
- end
-
- it "and provide dbname reader" do
- @cs.should respond_to(:dbname)
- end
-
- it "and assign dbname properly" do
- @cs.dbname.should eql(@dbname)
- end
-
- end
-end
Please sign in to comment.
Something went wrong with that request. Please try again.