View moneta-memcached.rb
begin | |
require "memcached" | |
rescue LoadError | |
puts "You need the memcached (the libmemcached client, not the other one) gem to use the Memcached moneta store" | |
exit | |
end | |
# uses the memcached gem properly, and traps the weirdass exception a get on an undefined key throws. May be worth changing | |
# further to allow the extra flags memcached lets you use, like marshal => true|false or the various memcached flags |
View gist:109499
begin | |
require "memcached" | |
rescue LoadError | |
require "memcache" | |
rescue LoadError | |
puts "You need the memcache or the memcached gem to use the Memcache moneta store" | |
exit | |
end | |
module Moneta |
View gist:112031
class MessageController < ApplicationController | |
def index | |
@messagee = User.by_name(params[:nick]) | |
end | |
def newpmthr | |
if request.post? | |
pmthr = PMThread.new | |
unless (pmthr) | |
raise "Something's wrong" |
View gist:118462
class StoryController < ApplicationController | |
#require 'utility' | |
def index | |
@story = Story.get(params[:id]) | |
#@comments = repository(:default).adapter.query('SELECT comments.id, story_id, user_id, parent_id, time, sid, cid, pid, subject, recrate, trollrate, raters, commentip, comment, nickname from comments left join users on comments.user_id = users.id where story_id = ?', @story.id) | |
#@comments = Comment.find_by_sql(['SELECT comments.id, subject, nickname from comments left join users on comments.user_id = users.id where story_id = ?', @story.id]) | |
# experiment... | |
clist = repository(:default).adapter.query('SELECT comments.id, story_id, user_id, parent_id, time, sid, cid, pid, subject, recrate, trollrate, raters, commentip, comment, nickname from comments left join users on comments.user_id = users.id where story_id = ?', @story.id) | |
chash = Hash.new |
View gist:118846
def self.treeify_comments(clist, pid = 0) | |
chash = Hash.new # comments grouped by parent_id | |
comhash = Hash.new # comments in a hash, w/ comment id as key | |
comments = Array.new # for the ordered comments | |
depth_tree = Hash.new # comment depth | |
clist.collect { |x| comhash[x.id] = x } | |
# ? | |
clist.collect do |c| | |
chash[c.parent_id] ||= Array.new |
View gist:124738
# what breaks | |
<% blogs = @story.user.blogs %> | |
# with: | |
Cannot find the child_model Blogadmin for User | |
# the relationship in User | |
# doesn't work |
View gist:126070
/usr/lib/ruby/gems/1.8/gems/dm-core-0.9.11/lib/dm-core/property.rb:450:in `lazy_load' | |
/usr/lib/ruby/gems/1.8/gems/dm-core-0.9.11/lib/dm-core/property.rb:390:in `get' | |
/usr/lib/ruby/gems/1.8/gems/dm-core-0.9.11/lib/dm-core/property_set.rb:82:in `get' | |
/usr/lib/ruby/gems/1.8/gems/dm-core-0.9.11/lib/dm-core/associations/relationship.rb:74:in `map' | |
/usr/lib/ruby/gems/1.8/gems/dm-core-0.9.11/lib/dm-core/property_set.rb:55:in `each' | |
/usr/lib/ruby/gems/1.8/gems/dm-core-0.9.11/lib/dm-core/property_set.rb:55:in `each' | |
/usr/lib/ruby/gems/1.8/gems/dm-core-0.9.11/lib/dm-core/property_set.rb:82:in `map' | |
/usr/lib/ruby/gems/1.8/gems/dm-core-0.9.11/lib/dm-core/property_set.rb:82:in `get' | |
/usr/lib/ruby/gems/1.8/gems/dm-core-0.9.11/lib/dm-core/associations/relationship.rb:178:in `attach_parent' | |
/usr/lib/ruby/gems/1.8/gems/dm-core-0.9.11/lib/dm-core/associations/many_to_one.rb:55:in `replace' |
View gist:126075
# comment.rb | |
class Comment | |
include DataMapper::Resource | |
property :id, Integer, :serial => true | |
property :story_id, Integer | |
property :user_id, Integer | |
property :parent_id, Integer | |
property :time, DateTime |
View gist:126244
# works | |
# friends, followers | |
has n, :friended_users | |
has n, :friends, :through => :friended_users, :class_name => "User", :child_key => [:user_id], :mutable => true | |
has n, :followers, :through => :friended_users, :class_name => "User", :remote_name => :user, :child_key => [:friend_id], :mutable => true | |
# does not work | |
has n, :block_users | |
has n, :you_blockeds, :through => :block_users, :class_name => "User", :child_key => [:user_id], :mutable => true | |
has n, :blocked_yous, :through => :block_users, :class_name => "User", :child_key => [:blocked_id], :mutable => true |
View gist:128360
# since you're curiuos.... | |
# inside the story view | |
<div id="comments"> | |
<ul class="cm i0"> | |
<% @n = 0 %> | |
<% @od = 0 %> | |
<% while @n < @comments.length do %> | |
<%= render :partial => 'comment/comment', :locals => { :comments => @comments, :depth_tree => @depth_tree } %> | |
<% end %> |
OlderNewer