Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Renamed mentionner to mentioner. duh.

  • Loading branch information...
commit d303bde85ad4861bd3676468700e02be685afae8 1 parent a322459
@cmer authored
View
10 README.rdoc
@@ -69,7 +69,7 @@ Allow a model to be mentioned:
Allow a model to mention:
class Comment < ActiveRecord::Base
...
- acts_as_mentionner
+ acts_as_mentioner
...
end
@@ -130,9 +130,9 @@ Find out if an objects likes
All likers
movie.likers(User)
-=== acts_as_mentionner Methods
+=== acts_as_mentioner Methods
-<b>Note that a "mentionner" is the object containing the mention and not necessarily the actor. For example, John mentions Jane in a comment. The mentionner is the comment object, NOT John.</b>
+<b>Note that a "mentioner" is the object containing the mention and not necessarily the actor. For example, John mentions Jane in a comment. The mentioner is the comment object, NOT John.</b>
Mention something
comment.mention!(user)
@@ -150,8 +150,8 @@ Mentions?
Find out if an objects mentions
user.mentioned_by?(comment)
-All mentionners
- user.mentionners(Comment)
+All mentioners
+ user.mentioners(Comment)
---
View
2  demo/demo_app/Gemfile
@@ -1,7 +1,7 @@
source 'https://rubygems.org'
gem 'rails', '~> 3.2.1'
-gem 'socialization', :git => "git://github.com/cmer/socialization.git", :branch => "mentions"
+gem 'socialization'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
View
2  demo/demo_app/app/models/comment.rb
@@ -1,5 +1,5 @@
class Comment < ActiveRecord::Base
- acts_as_mentionner
+ acts_as_mentioner
belongs_to :user
belongs_to :movie
end
View
6 demo/demo_app/db/migrate/20120221200644_create_mentions.rb
@@ -1,14 +1,14 @@
class CreateMentions < ActiveRecord::Migration
def change
create_table :mentions do |t|
- t.string :mentionner_type
- t.integer :mentionner_id
+ t.string :mentioner_type
+ t.integer :mentioner_id
t.string :mentionable_type
t.integer :mentionable_id
t.datetime :created_at
end
- add_index :mentions, ["mentionner_id", "mentionner_type"], :name => "fk_mentions"
+ add_index :mentions, ["mentioner_id", "mentioner_type"], :name => "fk_mentions"
add_index :mentions, ["mentionable_id", "mentionable_type"], :name => "fk_mentionables"
end
end
View
6 demo/demo_app/db/schema.rb
@@ -48,15 +48,15 @@
add_index "likes", ["liker_id", "liker_type"], :name => "fk_likes"
create_table "mentions", :force => true do |t|
- t.string "mentionner_type"
- t.integer "mentionner_id"
+ t.string "mentioner_type"
+ t.integer "mentioner_id"
t.string "mentionable_type"
t.integer "mentionable_id"
t.datetime "created_at"
end
add_index "mentions", ["mentionable_id", "mentionable_type"], :name => "fk_mentionables"
- add_index "mentions", ["mentionner_id", "mentionner_type"], :name => "fk_mentions"
+ add_index "mentions", ["mentioner_id", "mentioner_type"], :name => "fk_mentions"
create_table "movies", :force => true do |t|
t.string "name"
View
6 generators/socialization/templates/migration_mentions.rb
@@ -1,14 +1,14 @@
class CreateMentions < ActiveRecord::Migration
def change
create_table :mentions do |t|
- t.string :mentionner_type
- t.integer :mentionner_id
+ t.string :mentioner_type
+ t.integer :mentioner_id
t.string :mentionable_type
t.integer :mentionable_id
t.datetime :created_at
end
- add_index :mentions, ["mentionner_id", "mentionner_type"], :name => "fk_mentions"
+ add_index :mentions, ["mentioner_id", "mentioner_type"], :name => "fk_mentions"
add_index :mentions, ["mentionable_id", "mentionable_type"], :name => "fk_mentionables"
end
end
View
6 lib/socialization/hello.rb
@@ -1,6 +1,6 @@
require 'active_support/concern'
-%w{followable follower follow_store likeable liker like_store mentionable mentionner mention_store}.each do |f|
+%w{followable follower follow_store likeable liker like_store mentionable mentioner mention_store}.each do |f|
require "#{File.dirname(__FILE__)}/#{f}"
end
@@ -36,8 +36,8 @@ def acts_as_like_store(opts = nil)
end
## Mention
- def acts_as_mentionner(opts = nil)
- include Socialization::Mentionner
+ def acts_as_mentioner(opts = nil)
+ include Socialization::Mentioner
end
def acts_as_mentionable(opts = nil)
View
6 lib/socialization/mention_store.rb
@@ -3,10 +3,10 @@ module MentionStore
extend ActiveSupport::Concern
included do
- belongs_to :mentionner, :polymorphic => true
- belongs_to :mentionable, :polymorphic => true
+ belongs_to :mentioner, :polymorphic => true
+ belongs_to :mentionable, :polymorphic => true
- validates_uniqueness_of :mentionable_type, :scope => [:mentionable_id, :mentionner_type, :mentionner_id], :message => 'You cannot mention the same thing twice in a given object.'
+ validates_uniqueness_of :mentionable_type, :scope => [:mentionable_id, :mentioner_type, :mentioner_id], :message => 'You cannot mention the same thing twice in a given object.'
def self.human_attribute_name(*args); ''; end
end
View
12 lib/socialization/mentionable.rb
@@ -12,21 +12,21 @@ module Mentionable
included do
# A mentioning is the Mention record of describing the mention relationship between
- # the mentionner and the mentionable (self).
+ # the mentioner and the mentionable (self).
has_many :mentionings, :as => :mentionable, :dependent => :destroy, :class_name => 'Mention'
def is_mentionable?
true
end
- def mentioned_by?(mentionner)
- raise ArgumentError, "#{mentionner} is not a mentionner!" unless mentionner.is_mentionner?
- !self.mentionings.where(:mentionner_type => mentionner.class.to_s, :mentionner_id => mentionner.id).empty?
+ def mentioned_by?(mentioner)
+ raise ArgumentError, "#{mentioner} is not a mentioner!" unless mentioner.is_mentioner?
+ !self.mentionings.where(:mentioner_type => mentioner.class.to_s, :mentioner_id => mentioner.id).empty?
end
- def mentionners(klass)
+ def mentioners(klass)
klass = klass.to_s.singularize.camelize.constantize unless klass.is_a?(Class)
- klass.joins("INNER JOIN mentions ON mentions.mentionner_id = #{klass.to_s.tableize}.id AND mentions.mentionner_type = '#{klass.to_s}'").
+ klass.joins("INNER JOIN mentions ON mentions.mentioner_id = #{klass.to_s.tableize}.id AND mentions.mentioner_type = '#{klass.to_s}'").
where("mentions.mentionable_type = '#{self.class.to_s}'").
where("mentions.mentionable_id = #{self.id}")
end
View
16 lib/socialization/mentionner.rb → lib/socialization/mentioner.rb
@@ -1,30 +1,30 @@
module ActiveRecord
class Base
- def is_mentionner?
+ def is_mentioner?
false
end
end
end
module Socialization
- module Mentionner
+ module Mentioner
extend ActiveSupport::Concern
included do
# A mention is the Mention record (self) mentionning a mentionable record.
- has_many :mentions, :as => :mentionner, :dependent => :destroy, :class_name => 'Mention'
+ has_many :mentions, :as => :mentioner, :dependent => :destroy, :class_name => 'Mention'
- def is_mentionner?
+ def is_mentioner?
true
end
def mention!(mentionable)
ensure_mentionable!(mentionable)
- Mention.create!({ :mentionner => self, :mentionable => mentionable }, :without_protection => true)
+ Mention.create!({ :mentioner => self, :mentionable => mentionable }, :without_protection => true)
end
def unmention!(mentionable)
- mm = mentionable.mentionings.where(:mentionner_type => self.class.to_s, :mentionner_id => self.id)
+ mm = mentionable.mentionings.where(:mentioner_type => self.class.to_s, :mentioner_id => self.id)
unless mm.empty?
mm.each { |m| m.destroy }
else
@@ -40,8 +40,8 @@ def mentions?(mentionable)
def mentionees(klass)
klass = klass.to_s.singularize.camelize.constantize unless klass.is_a?(Class)
klass.joins("INNER JOIN mentions ON mentions.mentionable_id = #{klass.to_s.tableize}.id AND mentions.mentionable_type = '#{klass.to_s}'").
- where("mentions.mentionner_type = '#{self.class.to_s}'").
- where("mentions.mentionner_id = #{self.id}")
+ where("mentions.mentioner_type = '#{self.class.to_s}'").
+ where("mentions.mentioner_id = #{self.id}")
end
private
View
74 test/mention_test.rb
@@ -1,52 +1,52 @@
require File.expand_path(File.dirname(__FILE__))+'/test_helper'
class MentionTest < Test::Unit::TestCase
- context "a Mentionner" do
+ context "a Mentioner" do
setup do
seed
end
- should "be mentionner" do
- assert_equal true, @mentionner1.is_mentionner?
+ should "be mentioner" do
+ assert_equal true, @mentioner1.is_mentioner?
end
should "be able to mention a Mentionable" do
- assert @mentionner1.mention!(@mentionable1)
- assert_equal true, @mentionner1.mentions?(@mentionable1)
- assert_equal false, @mentionner2.mentions?(@mentionable1)
+ assert @mentioner1.mention!(@mentionable1)
+ assert_equal true, @mentioner1.mentions?(@mentionable1)
+ assert_equal false, @mentioner2.mentions?(@mentionable1)
end
should "be able to unmention a Mentionable" do
- Mention.create :mentionner => @mentionner1, :mentionable => @mentionable1
- assert @mentionner1.unmention!(@mentionable1)
- assert_equal false, @mentionner1.mentions?(@mentionable1)
+ Mention.create :mentioner => @mentioner1, :mentionable => @mentionable1
+ assert @mentioner1.unmention!(@mentionable1)
+ assert_equal false, @mentioner1.mentions?(@mentionable1)
end
should "not be able to mention the same thing twice" do
- assert @mentionner1.mention!(@mentionable1)
+ assert @mentioner1.mention!(@mentionable1)
assert_raise ActiveRecord::RecordInvalid do
- @mentionner1.mention!(@mentionable1)
+ @mentioner1.mention!(@mentionable1)
end
end
should "not be able to unmention something that is not mentionned" do
assert_raise ActiveRecord::RecordNotFound do
- @mentionner1.unmention!(@mentionable1)
+ @mentioner1.unmention!(@mentionable1)
end
end
should "be able to mention itself" do
- @mentionner_and_mentionable.mention!(@mentionner_and_mentionable)
+ @mentioner_and_mentionable.mention!(@mentioner_and_mentionable)
end
should "expose a list of its mentionees" do
- Mention.create :mentionner => @mentionner1, :mentionable => @mentionable1
- assert @mentionner1.mentionees(ImAMentionner).is_a?(ActiveRecord::Relation)
- assert_equal [@mentionable1], @mentionner1.mentionees(ImAMentionable).all
+ Mention.create :mentioner => @mentioner1, :mentionable => @mentionable1
+ assert @mentioner1.mentionees(ImAMentioner).is_a?(ActiveRecord::Relation)
+ assert_equal [@mentionable1], @mentioner1.mentionees(ImAMentionable).all
- assert_equal @mentionner1.mentionees(ImAMentionable), @mentionner1.mentionees(:im_a_mentionables)
- assert_equal @mentionner1.mentionees(ImAMentionable), @mentionner1.mentionees("im_a_mentionable")
+ assert_equal @mentioner1.mentionees(ImAMentionable), @mentioner1.mentionees(:im_a_mentionables)
+ assert_equal @mentioner1.mentionees(ImAMentionable), @mentioner1.mentionees("im_a_mentionable")
end
end
@@ -60,57 +60,57 @@ class MentionTest < Test::Unit::TestCase
end
should "be able to determine who mentions it" do
- Mention.create :mentionner => @mentionner1, :mentionable => @mentionable1
- assert_equal true, @mentionable1.mentioned_by?(@mentionner1)
- assert_equal false, @mentionable1.mentioned_by?(@mentionner2)
+ Mention.create :mentioner => @mentioner1, :mentionable => @mentionable1
+ assert_equal true, @mentionable1.mentioned_by?(@mentioner1)
+ assert_equal false, @mentionable1.mentioned_by?(@mentioner2)
end
- should "expose a list of its mentionners" do
- Mention.create :mentionner => @mentionner1, :mentionable => @mentionable1
- assert @mentionable1.mentionners(ImAMentionner).is_a?(ActiveRecord::Relation)
- assert_equal [@mentionner1], @mentionable1.mentionners(ImAMentionner).all
+ should "expose a list of its mentioners" do
+ Mention.create :mentioner => @mentioner1, :mentionable => @mentionable1
+ assert @mentionable1.mentioners(ImAMentioner).is_a?(ActiveRecord::Relation)
+ assert_equal [@mentioner1], @mentionable1.mentioners(ImAMentioner).all
- assert_equal @mentionable1.mentionners(ImAMentionner), @mentionable1.mentionners(:im_a_mentionners)
- assert_equal @mentionable1.mentionners(ImAMentionner), @mentionable1.mentionners("im_a_mentionner")
+ assert_equal @mentionable1.mentioners(ImAMentioner), @mentionable1.mentioners(:im_a_mentioners)
+ assert_equal @mentionable1.mentioners(ImAMentioner), @mentionable1.mentioners("im_a_mentioner")
end
should "expose mentionings" do
- Mention.create :mentionner => @mentionner1, :mentionable => @mentionable1
+ Mention.create :mentioner => @mentioner1, :mentionable => @mentionable1
mentionings = @mentionable1.mentionings
assert_equal 1, mentionings.size
assert mentionings.first.is_a?(Mention)
end
end
- context "Deleting a mentionner" do
+ context "Deleting a mentioner" do
setup do
seed
- @mentionner1.mention!(@mentionable1)
+ @mentioner1.mention!(@mentionable1)
end
should "delete its Mention records" do
- @mentionner1.destroy
- assert_equal false, @mentionable1.mentioned_by?(@mentionner1)
+ @mentioner1.destroy
+ assert_equal false, @mentionable1.mentioned_by?(@mentioner1)
end
end
context "Deleting a Mentionable" do
setup do
seed
- @mentionner1.mention!(@mentionable1)
+ @mentioner1.mention!(@mentionable1)
end
should "delete its Mention records" do
@mentionable1.destroy
- assert_equal false, @mentionner1.mentions?(@mentionable1)
+ assert_equal false, @mentioner1.mentions?(@mentionable1)
end
end
def seed
- @mentionner1 = ImAMentionner.create
- @mentionner2 = ImAMentionner.create
+ @mentioner1 = ImAMentioner.create
+ @mentioner2 = ImAMentioner.create
@mentionable1 = ImAMentionable.create
@mentionable2 = ImAMentionable.create
- @mentionner_and_mentionable = ImAMentionnerAndMentionable.create
+ @mentioner_and_mentionable = ImAMentionerAndMentionable.create
end
end
View
18 test/test_helper.rb
@@ -50,8 +50,8 @@
end
create_table :mentions do |t|
- t.string :mentionner_type
- t.integer :mentionner_id
+ t.string :mentioner_type
+ t.integer :mentioner_id
t.string :mentionable_type
t.integer :mentionable_id
t.datetime :created_at
@@ -73,7 +73,7 @@
t.timestamps
end
- create_table :im_a_mentionners do |t|
+ create_table :im_a_mentioners do |t|
t.timestamps
end
@@ -81,7 +81,7 @@
t.timestamps
end
- create_table :im_a_mentionner_and_mentionables do |t|
+ create_table :im_a_mentioner_and_mentionables do |t|
t.timestamps
end
@@ -106,7 +106,7 @@ class User < ActiveRecord::Base
end
class Comment < ActiveRecord::Base
- acts_as_mentionner
+ acts_as_mentioner
belongs_to :user
belongs_to :movie
end
@@ -144,16 +144,16 @@ class ImALikeable < ActiveRecord::Base
acts_as_likeable
end
-class ImAMentionner < ActiveRecord::Base
- acts_as_mentionner
+class ImAMentioner < ActiveRecord::Base
+ acts_as_mentioner
end
class ImAMentionable < ActiveRecord::Base
acts_as_mentionable
end
-class ImAMentionnerAndMentionable < ActiveRecord::Base
- acts_as_mentionner
+class ImAMentionerAndMentionable < ActiveRecord::Base
+ acts_as_mentioner
acts_as_mentionable
end
Please sign in to comment.
Something went wrong with that request. Please try again.