MS mongomapper works kinda
This commit is contained in:
parent
a0eeb43176
commit
5f3a6a7aa0
12 changed files with 40 additions and 68 deletions
7
Gemfile
7
Gemfile
|
|
@ -3,10 +3,13 @@ source 'http://gemcutter.org'
|
||||||
|
|
||||||
gem 'rails', '3.0.0.beta4'
|
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 "bson_ext", "1.0.1"
|
||||||
|
|
||||||
gem "haml"
|
gem "haml"
|
||||||
gem "devise", :git => "git://github.com/plataformatec/devise.git", :ref => "cfadaf80a2b7e9c0b255"
|
|
||||||
gem 'roxml', :git => "git://github.com/Empact/roxml.git"
|
gem 'roxml', :git => "git://github.com/Empact/roxml.git"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,16 +4,9 @@ class Blog < Post
|
||||||
xml_accessor :body
|
xml_accessor :body
|
||||||
|
|
||||||
|
|
||||||
field :title
|
key :title, String
|
||||||
field :body
|
key :body, String
|
||||||
|
|
||||||
validates_presence_of :title, :body
|
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
|
end
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@ class Bookmark < Post
|
||||||
xml_accessor :link
|
xml_accessor :link
|
||||||
xml_accessor :title
|
xml_accessor :title
|
||||||
|
|
||||||
field :link
|
key :link, String
|
||||||
field :title
|
key :title, String
|
||||||
|
|
||||||
|
|
||||||
validates_presence_of :link
|
validates_presence_of :link
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ class Friend < Person
|
||||||
|
|
||||||
xml_accessor :url
|
xml_accessor :url
|
||||||
|
|
||||||
field :url
|
key :url, String
|
||||||
|
|
||||||
validates_presence_of :url
|
validates_presence_of :url
|
||||||
validates_format_of :url, :with =>
|
validates_format_of :url, :with =>
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,15 @@
|
||||||
class Person
|
class Person
|
||||||
include Mongoid::Document
|
include MongoMapper::Document
|
||||||
include ROXML
|
include ROXML
|
||||||
|
|
||||||
xml_accessor :email
|
xml_accessor :email
|
||||||
xml_accessor :real_name
|
xml_accessor :real_name
|
||||||
|
|
||||||
field :email
|
key :type, String
|
||||||
field :real_name
|
key :email, String
|
||||||
|
key :real_name, String
|
||||||
|
|
||||||
has_many_related :posts
|
has_many :posts
|
||||||
|
|
||||||
validates_presence_of :email, :real_name
|
validates_presence_of :email, :real_name
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,39 +4,21 @@ class Post
|
||||||
|
|
||||||
# XML accessors must always preceed mongo field tags
|
# XML accessors must always preceed mongo field tags
|
||||||
|
|
||||||
include Mongoid::Document
|
include MongoMapper::Document
|
||||||
include Mongoid::Timestamps
|
|
||||||
include ROXML
|
include ROXML
|
||||||
include Diaspora::Webhooks
|
include Diaspora::Webhooks
|
||||||
|
|
||||||
xml_accessor :owner
|
|
||||||
xml_accessor :snippet
|
|
||||||
xml_accessor :source
|
|
||||||
|
|
||||||
field :owner
|
key :type, String
|
||||||
field :source
|
key :person_id, ObjectId
|
||||||
field :snippet
|
|
||||||
|
|
||||||
|
|
||||||
belongs_to_related :person
|
|
||||||
|
|
||||||
|
belongs_to :person
|
||||||
|
|
||||||
before_create :set_defaults
|
|
||||||
|
#before_create :set_defaults
|
||||||
|
|
||||||
after_save :send_to_view
|
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
|
def each
|
||||||
yield self
|
yield self
|
||||||
end
|
end
|
||||||
|
|
@ -49,11 +31,6 @@ class Post
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_defaults
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,26 +2,14 @@ class StatusMessage < Post
|
||||||
#include StatusMessagesHelper
|
#include StatusMessagesHelper
|
||||||
|
|
||||||
xml_name :status_message
|
xml_name :status_message
|
||||||
|
|
||||||
xml_accessor :message
|
xml_accessor :message
|
||||||
field :message
|
|
||||||
|
key :message, String
|
||||||
|
|
||||||
|
|
||||||
validates_presence_of :message
|
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
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
class User < Person
|
class User
|
||||||
|
include MongoMapper::Document
|
||||||
|
|
||||||
# Include default devise modules. Others available are:
|
# Include default devise modules. Others available are:
|
||||||
# :token_authenticatable, :confirmable, :lockable and :timeoutable
|
# :token_authenticatable, :confirmable, :lockable and :timeoutable
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ module Diaspora
|
||||||
|
|
||||||
# Configure generators values. Many other options are available, be sure to check the documentation.
|
# Configure generators values. Many other options are available, be sure to check the documentation.
|
||||||
config.generators do |g|
|
config.generators do |g|
|
||||||
g.orm :mongoid
|
g.orm :mongo_mapper
|
||||||
g.template_engine :haml
|
g.template_engine :haml
|
||||||
g.test_framework :rspec
|
g.test_framework :rspec
|
||||||
end
|
end
|
||||||
|
|
|
||||||
9
config/initializers/_mongo.rb
Normal file
9
config/initializers/_mongo.rb
Normal file
|
|
@ -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
|
||||||
|
|
||||||
|
|
@ -7,7 +7,7 @@ Devise.setup do |config|
|
||||||
# ==> ORM configuration
|
# ==> ORM configuration
|
||||||
# Load and configure the ORM. Supports :active_record (default), :mongoid
|
# Load and configure the ORM. Supports :active_record (default), :mongoid
|
||||||
# (bson_ext recommended) and :data_mapper (experimental).
|
# (bson_ext recommended) and :data_mapper (experimental).
|
||||||
require 'devise/orm/mongoid'
|
require 'devise/orm/mongo_mapper'
|
||||||
|
|
||||||
# ==> Configuration for any authentication mechanism
|
# ==> Configuration for any authentication mechanism
|
||||||
# Configure which keys are used when authenticating an user. By default is
|
# Configure which keys are used when authenticating an user. By default is
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,11 @@ module Diaspora
|
||||||
@@queue = MessageHandler.new
|
@@queue = MessageHandler.new
|
||||||
|
|
||||||
def notify_friends
|
def notify_friends
|
||||||
if self.owner == User.first.email
|
#if self.owner == User.first.email
|
||||||
xml = Post.build_xml_for(self)
|
xml = Post.build_xml_for(self)
|
||||||
@@queue.add_post_request( friends_with_permissions, xml )
|
@@queue.add_post_request( friends_with_permissions, xml )
|
||||||
@@queue.process
|
@@queue.process
|
||||||
end
|
#end
|
||||||
end
|
end
|
||||||
|
|
||||||
def prep_webhook
|
def prep_webhook
|
||||||
|
|
@ -19,12 +19,12 @@ module Diaspora
|
||||||
end
|
end
|
||||||
|
|
||||||
def friends_with_permissions
|
def friends_with_permissions
|
||||||
Friend.only(:url).map{|x| x = x.url + "receive/"}
|
Friend.all.map{|x| x = x.url + "receive/"}
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.build_xml_for(posts)
|
def self.build_xml_for(posts)
|
||||||
xml = "<XML>"
|
xml = "<XML>"
|
||||||
xml += Post.generate_header
|
#xml += Post.generate_header
|
||||||
xml += "<posts>"
|
xml += "<posts>"
|
||||||
posts.each {|x| xml << x.prep_webhook}
|
posts.each {|x| xml << x.prep_webhook}
|
||||||
xml += "</posts>"
|
xml += "</posts>"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue