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 "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"
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ class Friend < Person
|
|||
|
||||
xml_accessor :url
|
||||
|
||||
field :url
|
||||
key :url, String
|
||||
|
||||
validates_presence_of :url
|
||||
validates_format_of :url, :with =>
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
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
|
||||
# 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
|
||||
|
|
|
|||
|
|
@ -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>"
|
||||
xml += Post.generate_header
|
||||
#xml += Post.generate_header
|
||||
xml += "<posts>"
|
||||
posts.each {|x| xml << x.prep_webhook}
|
||||
xml += "</posts>"
|
||||
|
|
|
|||
Loading…
Reference in a new issue