private_messages 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +49 -0
- data/Rakefile +1 -0
- data/lib/private_messages/engine.rb +14 -0
- data/lib/private_messages/models/private_message.rb +46 -0
- data/lib/private_messages/models/private_user.rb +50 -0
- data/lib/private_messages/string.rb +6 -0
- data/lib/private_messages/version.rb +3 -0
- data/lib/private_messages.rb +6 -0
- data/private_messages.gemspec +25 -0
- metadata +106 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Andrey
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
private_messages
|
2
|
+
================
|
3
|
+
|
4
|
+
Sending Messages beetween users. Rails + Devise
|
5
|
+
|
6
|
+
## Установка
|
7
|
+
|
8
|
+
Install gem:
|
9
|
+
|
10
|
+
gem "private_messages"
|
11
|
+
|
12
|
+
Migrations:
|
13
|
+
|
14
|
+
1. Create Users
|
15
|
+
|
16
|
+
2. Create Messages
|
17
|
+
|
18
|
+
For example:
|
19
|
+
|
20
|
+
def change
|
21
|
+
# Messages
|
22
|
+
create_table :messages do |t|
|
23
|
+
t.integer :sender_id
|
24
|
+
t.integer :recipient_id
|
25
|
+
t.string :subject
|
26
|
+
t.text :body
|
27
|
+
t.datetime :read_at
|
28
|
+
t.integer :parent_id
|
29
|
+
t.integer :lft
|
30
|
+
t.integer :rgt
|
31
|
+
t.integer :depth
|
32
|
+
t.timestamps
|
33
|
+
end
|
34
|
+
|
35
|
+
add_index :messages, :sender_id
|
36
|
+
add_index :messages, :recipient_id
|
37
|
+
end
|
38
|
+
|
39
|
+
Models:
|
40
|
+
|
41
|
+
user.rb:
|
42
|
+
|
43
|
+
has_private_messages
|
44
|
+
|
45
|
+
message.rb:
|
46
|
+
|
47
|
+
is_private_message
|
48
|
+
|
49
|
+
TODO: message controller include in engine (Possible?)
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
module PrivateMessages
|
3
|
+
class Engine < ::Rails::Engine
|
4
|
+
isolate_namespace PrivateMessages
|
5
|
+
engine_name "private_messages"
|
6
|
+
|
7
|
+
initializer "private_messages.includers" do |app|
|
8
|
+
# TODO: вынести контроллеры в engine
|
9
|
+
# ActionController::Base.send :include, DeviseRussian::Controllers::Base
|
10
|
+
ActiveRecord::Base.send :include, PrivateMessages::Models::PrivateUser
|
11
|
+
ActiveRecord::Base.send :include, PrivateMessages::Models::PrivateMessage
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
module PrivateMessages
|
3
|
+
module Models
|
4
|
+
module PrivateMessage
|
5
|
+
def self.included(base)
|
6
|
+
base.extend ClassMethods
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def is_private_message(options = {})
|
11
|
+
class_attribute :options
|
12
|
+
self.options = options
|
13
|
+
|
14
|
+
klass_name = options[:class_name] ||= "User"
|
15
|
+
|
16
|
+
belongs_to :sender, :class_name => klass_name, :foreign_key => 'sender_id'
|
17
|
+
belongs_to :recipient, :class_name => klass_name, :foreign_key => 'recipient_id'
|
18
|
+
|
19
|
+
scope :unread, where("read_at is null")
|
20
|
+
|
21
|
+
def around_user(user)
|
22
|
+
klass_name.constantize.where("sender_id = ? or recipient_id = ?", user.id, user.id)
|
23
|
+
end
|
24
|
+
|
25
|
+
unless included_modules.include? InstanceMethods
|
26
|
+
include InstanceMethods
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
module InstanceMethods
|
32
|
+
def unread?
|
33
|
+
!self.read?
|
34
|
+
end
|
35
|
+
|
36
|
+
def read?
|
37
|
+
!self.read_at.blank?
|
38
|
+
end
|
39
|
+
|
40
|
+
def read!
|
41
|
+
self.update_attribute(:read_at, Time.now)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
module PrivateMessages
|
3
|
+
module Models
|
4
|
+
module PrivateUser
|
5
|
+
def self.included(base)
|
6
|
+
base.extend ClassMethods
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def has_private_messages(options = {})
|
11
|
+
class_attribute :options
|
12
|
+
klass_name = options[:class_name] ||= "Message"
|
13
|
+
table_name = klass_name.constantize.table_name
|
14
|
+
|
15
|
+
has_many :outbox_messages, :class_name => klass_name,
|
16
|
+
:foreign_key => 'sender_id', :include => :recipient,
|
17
|
+
:order => "#{table_name}.created_at desc"
|
18
|
+
|
19
|
+
has_many :inbox_messages, :class_name => klass_name,
|
20
|
+
:foreign_key => 'recipient_id', :include => :sender,
|
21
|
+
:order => "#{table_name}.created_at desc"
|
22
|
+
|
23
|
+
unless included_modules.include? InstanceMethods
|
24
|
+
include InstanceMethods
|
25
|
+
end
|
26
|
+
|
27
|
+
self.options = options
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
module InstanceMethods
|
32
|
+
def unread_messages
|
33
|
+
self.inbox_messages.unread
|
34
|
+
end
|
35
|
+
|
36
|
+
def is_sender_of?(message)
|
37
|
+
message.sender_id == self.id
|
38
|
+
end
|
39
|
+
|
40
|
+
def is_recipient_of?(message)
|
41
|
+
message.recipient_id == self.id
|
42
|
+
end
|
43
|
+
|
44
|
+
def has_message?(message)
|
45
|
+
self.is_sender_of?(message) || self.is_recipient_of?(message)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'private_messages/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "private_messages"
|
8
|
+
spec.version = PrivateMessages::VERSION
|
9
|
+
spec.authors = ["Andrey"]
|
10
|
+
spec.email = ["railscode@gmail.com"]
|
11
|
+
spec.description = "Sending Messages beetween users. Rails + Devise"
|
12
|
+
spec.summary = "Sending Messages beetween users. Rails + Devise"
|
13
|
+
spec.homepage = "https://github.com/vav/private_messages"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
|
24
|
+
spec.add_dependency "rails", ">= 3.2.12"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: private_messages
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Andrey
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-31 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rails
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 3.2.12
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.2.12
|
62
|
+
description: Sending Messages beetween users. Rails + Devise
|
63
|
+
email:
|
64
|
+
- railscode@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- Gemfile
|
71
|
+
- LICENSE.txt
|
72
|
+
- README.md
|
73
|
+
- Rakefile
|
74
|
+
- lib/private_messages.rb
|
75
|
+
- lib/private_messages/engine.rb
|
76
|
+
- lib/private_messages/models/private_message.rb
|
77
|
+
- lib/private_messages/models/private_user.rb
|
78
|
+
- lib/private_messages/string.rb
|
79
|
+
- lib/private_messages/version.rb
|
80
|
+
- private_messages.gemspec
|
81
|
+
homepage: https://github.com/vav/private_messages
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 1.8.19
|
103
|
+
signing_key:
|
104
|
+
specification_version: 3
|
105
|
+
summary: Sending Messages beetween users. Rails + Devise
|
106
|
+
test_files: []
|