Class: Vines::Storage::Mongomapper
- Inherits:
-
Vines::Storage
- Object
- Vines::Storage
- Vines::Storage::Mongomapper
- Defined in:
- lib/vines/mongomapper.rb
Instance Method Summary collapse
- #find_fragment(jid, node) ⇒ Object
- #find_user(jid) ⇒ Object
-
#find_vcard(jid) ⇒ Object
def save_user(user).
- #get ⇒ Object
- #host(name, port) ⇒ Object
-
#initialize(&block) ⇒ Mongomapper
constructor
A new instance of Mongomapper.
- #save(model) ⇒ Object
- #save_fragment(jid, node) ⇒ Object
- #save_vcard(jid, card) ⇒ Object
Constructor Details
#initialize(&block) ⇒ Mongomapper
Returns a new instance of Mongomapper.
19 20 21 22 23 24 25 |
# File 'lib/vines/mongomapper.rb', line 19 def initialize(&block) @config, @hosts = {}, [] instance_eval(&block) raise "Must provide database" unless @config[:database] raise "Must provide at least one host connection" if @hosts.empty? connect end |
Instance Method Details
#find_fragment(jid, node) ⇒ Object
87 88 89 |
# File 'lib/vines/mongomapper.rb', line 87 def find_fragment(jid, node) end |
#find_user(jid) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/vines/mongomapper.rb', line 33 def find_user(jid) jid = JID.new(jid)..to_s return if jid.empty? #find a usr by it's bson id u = Vines::User.where(:_id=>jid_to_bson_id(jid)).first # find a user by it's name user_name = jid.split('@')[0] u = Vines::User.where(:user_name=>user_name).first unless u u.jid = JID.new(jid)if u u.roster=[] if u u end |
#find_vcard(jid) ⇒ Object
def save_user(user)
jid = user.jid..to_s
user_name = user.user_name
#find a user by name create a new if failed
u = Vines::User.where(:user_name=>user_name).first
u = Vines::User.new(jid:user.jid) unless u
u.email = jid
u.name = user.name
u.user_name = user_name
u.password = user.password
# doc['roster'] = {}
# user.roster.each do |contact|
# doc['roster'][contact.jid.bare.to_s] = contact.to_h
# end
save(u)
end
79 80 81 |
# File 'lib/vines/mongomapper.rb', line 79 def find_vcard(jid) end |
#get ⇒ Object
96 97 98 |
# File 'lib/vines/mongomapper.rb', line 96 def get end |
#host(name, port) ⇒ Object
27 28 29 30 31 |
# File 'lib/vines/mongomapper.rb', line 27 def host(name, port) pair = [name, port] raise "duplicate hosts not allowed: #{name}:#{port}" if @hosts.include?(pair) @hosts << pair end |
#save(model) ⇒ Object
101 102 103 |
# File 'lib/vines/mongomapper.rb', line 101 def save(model) model.save! end |
#save_fragment(jid, node) ⇒ Object
91 92 93 |
# File 'lib/vines/mongomapper.rb', line 91 def save_fragment(jid, node) end |
#save_vcard(jid, card) ⇒ Object
83 84 85 |
# File 'lib/vines/mongomapper.rb', line 83 def save_vcard(jid, card) end |