diff --git a/Gemfile b/Gemfile index 836a5c285..6480c2f73 100644 --- a/Gemfile +++ b/Gemfile @@ -3,10 +3,13 @@ source 'http://gemcutter.org' gem 'rails', '3.0.0.beta4' -gem "mongoid", :git => "git://github.com/durran/mongoid.git" +gem 'mongo_mapper', :git => "http://github.com/BadMinus/mongomapper.git" +gem 'devise', :git => "http://github.com/BadMinus/devise.git" +gem 'jnunemaker-validatable', :git => "http://github.com/BadMinus/validatable.git" +gem 'mongo_ext' gem "bson_ext", "1.0.1" + gem "haml" -gem "devise", :git => "git://github.com/plataformatec/devise.git", :ref => "cfadaf80a2b7e9c0b255" gem 'roxml', :git => "git://github.com/Empact/roxml.git" diff --git a/app/models/blog.rb b/app/models/blog.rb index 3da382754..8cb375f45 100644 --- a/app/models/blog.rb +++ b/app/models/blog.rb @@ -4,16 +4,9 @@ class Blog < Post xml_accessor :body - field :title - field :body + key :title, String + key :body, String validates_presence_of :title, :body - def self.newest(owner_email) - Blog.last(:conditions => {:owner => owner_email}) - end - - def self.my_newest - Blog.newest(User.first.email) - end end diff --git a/app/models/bookmark.rb b/app/models/bookmark.rb index 61f4697f7..3df470a39 100644 --- a/app/models/bookmark.rb +++ b/app/models/bookmark.rb @@ -3,8 +3,8 @@ class Bookmark < Post xml_accessor :link xml_accessor :title - field :link - field :title + key :link, String + key :title, String validates_presence_of :link diff --git a/app/models/friend.rb b/app/models/friend.rb index ece2f16b2..d7809ac6c 100644 --- a/app/models/friend.rb +++ b/app/models/friend.rb @@ -2,7 +2,7 @@ class Friend < Person xml_accessor :url - field :url + key :url, String validates_presence_of :url validates_format_of :url, :with => diff --git a/app/models/person.rb b/app/models/person.rb index 399dbb394..fe6ac6f83 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -1,14 +1,15 @@ class Person - include Mongoid::Document + include MongoMapper::Document include ROXML xml_accessor :email xml_accessor :real_name - field :email - field :real_name + key :type, String + key :email, String + key :real_name, String - has_many_related :posts + has_many :posts validates_presence_of :email, :real_name diff --git a/app/models/post.rb b/app/models/post.rb index e822c6cfe..f8c3789f7 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -4,39 +4,21 @@ class Post # XML accessors must always preceed mongo field tags - include Mongoid::Document - include Mongoid::Timestamps + include MongoMapper::Document include ROXML include Diaspora::Webhooks - xml_accessor :owner - xml_accessor :snippet - xml_accessor :source - field :owner - field :source - field :snippet - - - belongs_to_related :person + key :type, String + key :person_id, ObjectId + belongs_to :person - before_create :set_defaults + + #before_create :set_defaults after_save :send_to_view - @@models = ["StatusMessage", "Bookmark", "Blog"] - - def self.stream - # Need to explicitly name each inherited model for dev environment - query = if Rails.env == "development" - Post.criteria.all(:_type => @@models) - else - Post.criteria.all - end - query.order_by( [:created_at, :desc] ) - end - def each yield self end @@ -49,11 +31,6 @@ class Post end def set_defaults - user_email = User.first.email - self.owner ||= user_email - self.source ||= user_email - self.snippet ||= user_email - self.person ||= User.first end end diff --git a/app/models/status_message.rb b/app/models/status_message.rb index e22bcb621..5b7345288 100644 --- a/app/models/status_message.rb +++ b/app/models/status_message.rb @@ -2,26 +2,14 @@ class StatusMessage < Post #include StatusMessagesHelper xml_name :status_message - xml_accessor :message - field :message + + key :message, String validates_presence_of :message - def self.newest(owner_email) - StatusMessage.last(:conditions => {:owner => owner_email}) - end - - def self.my_newest - StatusMessage.newest(User.first.email) - end - - - def ==(other) - (self.message == other.message) && (self.owner == other.owner) - end end diff --git a/app/models/user.rb b/app/models/user.rb index a1ac4217f..2965da452 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,4 +1,5 @@ -class User < Person +class User + include MongoMapper::Document # Include default devise modules. Others available are: # :token_authenticatable, :confirmable, :lockable and :timeoutable diff --git a/config/application.rb b/config/application.rb index 2044abb07..5d5b90b54 100644 --- a/config/application.rb +++ b/config/application.rb @@ -34,7 +34,7 @@ module Diaspora # Configure generators values. Many other options are available, be sure to check the documentation. config.generators do |g| - g.orm :mongoid + g.orm :mongo_mapper g.template_engine :haml g.test_framework :rspec end diff --git a/config/initializers/_mongo.rb b/config/initializers/_mongo.rb new file mode 100644 index 000000000..2fde0f2ed --- /dev/null +++ b/config/initializers/_mongo.rb @@ -0,0 +1,9 @@ +MongoMapper.connection = Mongo::Connection.new('localhost', 27017) +MongoMapper.database = "#diaspora-#{Rails.env}" + +if defined?(PhusionPassenger) + PhusionPassenger.on_event(:starting_worker_process) do |forked| + MongoMapper.connection.connect_to_master if forked + end +end + diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 9eccb2137..f643e48cd 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -7,7 +7,7 @@ Devise.setup do |config| # ==> ORM configuration # Load and configure the ORM. Supports :active_record (default), :mongoid # (bson_ext recommended) and :data_mapper (experimental). - require 'devise/orm/mongoid' + require 'devise/orm/mongo_mapper' # ==> Configuration for any authentication mechanism # Configure which keys are used when authenticating an user. By default is diff --git a/lib/common.rb b/lib/common.rb index 8da6ddd31..066991613 100644 --- a/lib/common.rb +++ b/lib/common.rb @@ -7,11 +7,11 @@ module Diaspora @@queue = MessageHandler.new def notify_friends - if self.owner == User.first.email + #if self.owner == User.first.email xml = Post.build_xml_for(self) @@queue.add_post_request( friends_with_permissions, xml ) @@queue.process - end + #end end def prep_webhook @@ -19,12 +19,12 @@ module Diaspora end def friends_with_permissions - Friend.only(:url).map{|x| x = x.url + "receive/"} + Friend.all.map{|x| x = x.url + "receive/"} end def self.build_xml_for(posts) xml = "" - xml += Post.generate_header + #xml += Post.generate_header xml += "" posts.each {|x| xml << x.prep_webhook} xml += ""