acts-as-messageable 0.4.10 → 0.4.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,16 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "activerecord", "~> 5.2.0"
6
+ gem "activesupport", "~> 5.2.0"
7
+ gem "ancestry", ">= 1.3.0"
8
+ gem "railties", "~> 5.2.0"
9
+
10
+ group :development do
11
+ gem "appraisal"
12
+ gem "coveralls", require: false
13
+ gem "jeweler"
14
+ gem "rspec"
15
+ gem "sqlite3", "~> 1.3.6"
16
+ end
@@ -0,0 +1,155 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ actionpack (5.2.3)
5
+ actionview (= 5.2.3)
6
+ activesupport (= 5.2.3)
7
+ rack (~> 2.0)
8
+ rack-test (>= 0.6.3)
9
+ rails-dom-testing (~> 2.0)
10
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
11
+ actionview (5.2.3)
12
+ activesupport (= 5.2.3)
13
+ builder (~> 3.1)
14
+ erubi (~> 1.4)
15
+ rails-dom-testing (~> 2.0)
16
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
17
+ activemodel (5.2.3)
18
+ activesupport (= 5.2.3)
19
+ activerecord (5.2.3)
20
+ activemodel (= 5.2.3)
21
+ activesupport (= 5.2.3)
22
+ arel (>= 9.0)
23
+ activesupport (5.2.3)
24
+ concurrent-ruby (~> 1.0, >= 1.0.2)
25
+ i18n (>= 0.7, < 2)
26
+ minitest (~> 5.1)
27
+ tzinfo (~> 1.1)
28
+ addressable (2.4.0)
29
+ ancestry (3.0.6)
30
+ activerecord (>= 3.2.0)
31
+ appraisal (2.2.0)
32
+ bundler
33
+ rake
34
+ thor (>= 0.14.0)
35
+ arel (9.0.0)
36
+ builder (3.2.3)
37
+ concurrent-ruby (1.1.5)
38
+ coveralls (0.8.23)
39
+ json (>= 1.8, < 3)
40
+ simplecov (~> 0.16.1)
41
+ term-ansicolor (~> 1.3)
42
+ thor (>= 0.19.4, < 2.0)
43
+ tins (~> 1.6)
44
+ crass (1.0.4)
45
+ descendants_tracker (0.0.4)
46
+ thread_safe (~> 0.3, >= 0.3.1)
47
+ diff-lcs (1.3)
48
+ docile (1.3.1)
49
+ erubi (1.8.0)
50
+ faraday (0.9.2)
51
+ multipart-post (>= 1.2, < 3)
52
+ git (1.5.0)
53
+ github_api (0.16.0)
54
+ addressable (~> 2.4.0)
55
+ descendants_tracker (~> 0.0.4)
56
+ faraday (~> 0.8, < 0.10)
57
+ hashie (>= 3.4)
58
+ mime-types (>= 1.16, < 3.0)
59
+ oauth2 (~> 1.0)
60
+ hashie (3.6.0)
61
+ highline (2.0.2)
62
+ i18n (1.6.0)
63
+ concurrent-ruby (~> 1.0)
64
+ jeweler (2.3.9)
65
+ builder
66
+ bundler
67
+ git (>= 1.2.5)
68
+ github_api (~> 0.16.0)
69
+ highline (>= 1.6.15)
70
+ nokogiri (>= 1.5.10)
71
+ psych
72
+ rake
73
+ rdoc
74
+ semver2
75
+ json (2.2.0)
76
+ jwt (2.2.1)
77
+ loofah (2.2.3)
78
+ crass (~> 1.0.2)
79
+ nokogiri (>= 1.5.9)
80
+ method_source (0.9.2)
81
+ mime-types (2.99.3)
82
+ mini_portile2 (2.4.0)
83
+ minitest (5.11.3)
84
+ multi_json (1.13.1)
85
+ multi_xml (0.6.0)
86
+ multipart-post (2.1.1)
87
+ nokogiri (1.10.3)
88
+ mini_portile2 (~> 2.4.0)
89
+ oauth2 (1.4.1)
90
+ faraday (>= 0.8, < 0.16.0)
91
+ jwt (>= 1.0, < 3.0)
92
+ multi_json (~> 1.3)
93
+ multi_xml (~> 0.5)
94
+ rack (>= 1.2, < 3)
95
+ psych (3.1.0)
96
+ rack (2.0.7)
97
+ rack-test (1.1.0)
98
+ rack (>= 1.0, < 3)
99
+ rails-dom-testing (2.0.3)
100
+ activesupport (>= 4.2.0)
101
+ nokogiri (>= 1.6)
102
+ rails-html-sanitizer (1.0.4)
103
+ loofah (~> 2.2, >= 2.2.2)
104
+ railties (5.2.3)
105
+ actionpack (= 5.2.3)
106
+ activesupport (= 5.2.3)
107
+ method_source
108
+ rake (>= 0.8.7)
109
+ thor (>= 0.19.0, < 2.0)
110
+ rake (12.3.2)
111
+ rdoc (6.1.1)
112
+ rspec (3.8.0)
113
+ rspec-core (~> 3.8.0)
114
+ rspec-expectations (~> 3.8.0)
115
+ rspec-mocks (~> 3.8.0)
116
+ rspec-core (3.8.0)
117
+ rspec-support (~> 3.8.0)
118
+ rspec-expectations (3.8.3)
119
+ diff-lcs (>= 1.2.0, < 2.0)
120
+ rspec-support (~> 3.8.0)
121
+ rspec-mocks (3.8.0)
122
+ diff-lcs (>= 1.2.0, < 2.0)
123
+ rspec-support (~> 3.8.0)
124
+ rspec-support (3.8.0)
125
+ semver2 (3.4.2)
126
+ simplecov (0.16.1)
127
+ docile (~> 1.1)
128
+ json (>= 1.8, < 3)
129
+ simplecov-html (~> 0.10.0)
130
+ simplecov-html (0.10.2)
131
+ sqlite3 (1.3.13)
132
+ term-ansicolor (1.7.1)
133
+ tins (~> 1.0)
134
+ thor (0.20.3)
135
+ thread_safe (0.3.6)
136
+ tins (1.20.3)
137
+ tzinfo (1.2.5)
138
+ thread_safe (~> 0.1)
139
+
140
+ PLATFORMS
141
+ ruby
142
+
143
+ DEPENDENCIES
144
+ activerecord (~> 5.2.0)
145
+ activesupport (~> 5.2.0)
146
+ ancestry (>= 1.3.0)
147
+ appraisal
148
+ coveralls
149
+ jeweler
150
+ railties (~> 5.2.0)
151
+ rspec
152
+ sqlite3 (~> 1.3.6)
153
+
154
+ BUNDLED WITH
155
+ 2.0.1
@@ -0,0 +1,16 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "activerecord", "~> 6.0.0.rc1"
6
+ gem "activesupport", "~> 6.0.0.rc1"
7
+ gem "ancestry", ">= 1.3.0"
8
+ gem "railties", "~> 6.0.0.rc1"
9
+
10
+ group :development do
11
+ gem "appraisal"
12
+ gem "coveralls", require: false
13
+ gem "jeweler"
14
+ gem "rspec"
15
+ gem "sqlite3", "~> 1.4.0"
16
+ end
@@ -0,0 +1,155 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ actionpack (6.0.0.rc1)
5
+ actionview (= 6.0.0.rc1)
6
+ activesupport (= 6.0.0.rc1)
7
+ rack (~> 2.0)
8
+ rack-test (>= 0.6.3)
9
+ rails-dom-testing (~> 2.0)
10
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
11
+ actionview (6.0.0.rc1)
12
+ activesupport (= 6.0.0.rc1)
13
+ builder (~> 3.1)
14
+ erubi (~> 1.4)
15
+ rails-dom-testing (~> 2.0)
16
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
17
+ activemodel (6.0.0.rc1)
18
+ activesupport (= 6.0.0.rc1)
19
+ activerecord (6.0.0.rc1)
20
+ activemodel (= 6.0.0.rc1)
21
+ activesupport (= 6.0.0.rc1)
22
+ activesupport (6.0.0.rc1)
23
+ concurrent-ruby (~> 1.0, >= 1.0.2)
24
+ i18n (>= 0.7, < 2)
25
+ minitest (~> 5.1)
26
+ tzinfo (~> 1.1)
27
+ zeitwerk (~> 2.1, >= 2.1.4)
28
+ addressable (2.4.0)
29
+ ancestry (3.0.6)
30
+ activerecord (>= 3.2.0)
31
+ appraisal (2.2.0)
32
+ bundler
33
+ rake
34
+ thor (>= 0.14.0)
35
+ builder (3.2.3)
36
+ concurrent-ruby (1.1.5)
37
+ coveralls (0.8.23)
38
+ json (>= 1.8, < 3)
39
+ simplecov (~> 0.16.1)
40
+ term-ansicolor (~> 1.3)
41
+ thor (>= 0.19.4, < 2.0)
42
+ tins (~> 1.6)
43
+ crass (1.0.4)
44
+ descendants_tracker (0.0.4)
45
+ thread_safe (~> 0.3, >= 0.3.1)
46
+ diff-lcs (1.3)
47
+ docile (1.3.1)
48
+ erubi (1.8.0)
49
+ faraday (0.9.2)
50
+ multipart-post (>= 1.2, < 3)
51
+ git (1.5.0)
52
+ github_api (0.16.0)
53
+ addressable (~> 2.4.0)
54
+ descendants_tracker (~> 0.0.4)
55
+ faraday (~> 0.8, < 0.10)
56
+ hashie (>= 3.4)
57
+ mime-types (>= 1.16, < 3.0)
58
+ oauth2 (~> 1.0)
59
+ hashie (3.6.0)
60
+ highline (2.0.2)
61
+ i18n (1.6.0)
62
+ concurrent-ruby (~> 1.0)
63
+ jeweler (2.3.9)
64
+ builder
65
+ bundler
66
+ git (>= 1.2.5)
67
+ github_api (~> 0.16.0)
68
+ highline (>= 1.6.15)
69
+ nokogiri (>= 1.5.10)
70
+ psych
71
+ rake
72
+ rdoc
73
+ semver2
74
+ json (2.2.0)
75
+ jwt (2.2.1)
76
+ loofah (2.2.3)
77
+ crass (~> 1.0.2)
78
+ nokogiri (>= 1.5.9)
79
+ method_source (0.9.2)
80
+ mime-types (2.99.3)
81
+ mini_portile2 (2.4.0)
82
+ minitest (5.11.3)
83
+ multi_json (1.13.1)
84
+ multi_xml (0.6.0)
85
+ multipart-post (2.1.1)
86
+ nokogiri (1.10.3)
87
+ mini_portile2 (~> 2.4.0)
88
+ oauth2 (1.4.1)
89
+ faraday (>= 0.8, < 0.16.0)
90
+ jwt (>= 1.0, < 3.0)
91
+ multi_json (~> 1.3)
92
+ multi_xml (~> 0.5)
93
+ rack (>= 1.2, < 3)
94
+ psych (3.1.0)
95
+ rack (2.0.7)
96
+ rack-test (1.1.0)
97
+ rack (>= 1.0, < 3)
98
+ rails-dom-testing (2.0.3)
99
+ activesupport (>= 4.2.0)
100
+ nokogiri (>= 1.6)
101
+ rails-html-sanitizer (1.0.4)
102
+ loofah (~> 2.2, >= 2.2.2)
103
+ railties (6.0.0.rc1)
104
+ actionpack (= 6.0.0.rc1)
105
+ activesupport (= 6.0.0.rc1)
106
+ method_source
107
+ rake (>= 0.8.7)
108
+ thor (>= 0.20.3, < 2.0)
109
+ rake (12.3.2)
110
+ rdoc (6.1.1)
111
+ rspec (3.8.0)
112
+ rspec-core (~> 3.8.0)
113
+ rspec-expectations (~> 3.8.0)
114
+ rspec-mocks (~> 3.8.0)
115
+ rspec-core (3.8.0)
116
+ rspec-support (~> 3.8.0)
117
+ rspec-expectations (3.8.3)
118
+ diff-lcs (>= 1.2.0, < 2.0)
119
+ rspec-support (~> 3.8.0)
120
+ rspec-mocks (3.8.0)
121
+ diff-lcs (>= 1.2.0, < 2.0)
122
+ rspec-support (~> 3.8.0)
123
+ rspec-support (3.8.0)
124
+ semver2 (3.4.2)
125
+ simplecov (0.16.1)
126
+ docile (~> 1.1)
127
+ json (>= 1.8, < 3)
128
+ simplecov-html (~> 0.10.0)
129
+ simplecov-html (0.10.2)
130
+ sqlite3 (1.4.1)
131
+ term-ansicolor (1.7.1)
132
+ tins (~> 1.0)
133
+ thor (0.20.3)
134
+ thread_safe (0.3.6)
135
+ tins (1.20.3)
136
+ tzinfo (1.2.5)
137
+ thread_safe (~> 0.1)
138
+ zeitwerk (2.1.6)
139
+
140
+ PLATFORMS
141
+ ruby
142
+
143
+ DEPENDENCIES
144
+ activerecord (~> 6.0.0.rc1)
145
+ activesupport (~> 6.0.0.rc1)
146
+ ancestry (>= 1.3.0)
147
+ appraisal
148
+ coveralls
149
+ jeweler
150
+ railties (~> 6.0.0.rc1)
151
+ rspec
152
+ sqlite3 (~> 1.4.0)
153
+
154
+ BUNDLED WITH
155
+ 2.0.1
@@ -4,32 +4,32 @@ module ActsAsMessageable
4
4
  class Message < ::ActiveRecord::Base
5
5
  include ActsAsMessageable::Scopes
6
6
 
7
- belongs_to :received_messageable, :polymorphic => true
8
- belongs_to :sent_messageable, :polymorphic => true
7
+ belongs_to :received_messageable, polymorphic: true
8
+ belongs_to :sent_messageable, polymorphic: true
9
9
 
10
10
  attr_accessor :removed, :restored
11
11
  cattr_accessor :required
12
12
 
13
- ActsAsMessageable.rails_api.new(self).default_scope("created_at desc")
13
+ ActsAsMessageable.rails_api.new(self).default_scope('created_at desc')
14
14
 
15
15
  def open?
16
- self.opened?
16
+ opened?
17
17
  end
18
18
 
19
19
  def open
20
- update_attributes!(:opened => true)
20
+ update_attributes!(opened: true)
21
21
  end
22
- alias :mark_as_read :open
23
- alias :read :open
22
+ alias mark_as_read open
23
+ alias read open
24
24
 
25
25
  def close
26
- update_attributes!(:opened => false)
26
+ update_attributes!(opened: false)
27
27
  end
28
- alias :mark_as_unread :close
29
- alias :unread :close
28
+ alias mark_as_unread close
29
+ alias unread close
30
30
 
31
- alias :from :sent_messageable
32
- alias :to :received_messageable
31
+ alias from sent_messageable
32
+ alias to received_messageable
33
33
 
34
34
  def real_receiver(user)
35
35
  user == from ? to : from
@@ -56,7 +56,7 @@ module ActsAsMessageable
56
56
  end
57
57
 
58
58
  def people
59
- conversation.map{ |x| x.from }.uniq!
59
+ conversation.map(&:from).uniq!
60
60
  end
61
61
  end
62
62
  end
@@ -1,6 +1,5 @@
1
1
  module ActsAsMessageable
2
2
  module Model
3
-
4
3
  def self.included(base)
5
4
  base.extend ClassMethods
6
5
  end
@@ -15,47 +14,46 @@ module ActsAsMessageable
15
14
  # @param [Symbol] :dependent - dependent option from ActiveRecord has_many method
16
15
  def acts_as_messageable(options = {})
17
16
  default_options = {
18
- :table_name => "messages",
19
- :class_name => "ActsAsMessageable::Message",
20
- :required => [:topic, :body],
21
- :dependent => :nullify,
22
- :group_messages => false,
17
+ table_name: 'messages',
18
+ class_name: 'ActsAsMessageable::Message',
19
+ required: %i[topic body],
20
+ dependent: :nullify,
21
+ group_messages: false
23
22
  }
24
23
  options = default_options.merge(options)
25
24
 
26
25
  has_many :received_messages_relation,
27
- :as => :received_messageable,
28
- :class_name => options[:class_name],
29
- :dependent => options[:dependent]
26
+ as: :received_messageable,
27
+ class_name: options[:class_name],
28
+ dependent: options[:dependent]
30
29
  has_many :sent_messages_relation,
31
- :as => :sent_messageable,
32
- :class_name => options[:class_name],
33
- :dependent => options[:dependent]
30
+ as: :sent_messageable,
31
+ class_name: options[:class_name],
32
+ dependent: options[:dependent]
34
33
 
35
34
  self.messages_class_name = options[:class_name].constantize
36
- self.messages_class_name.has_ancestry
35
+ messages_class_name.has_ancestry
37
36
 
38
- if self.messages_class_name.respond_to?(:table_name=)
39
- self.messages_class_name.table_name = options[:table_name]
40
- self.messages_class_name.initialize_scopes
37
+ if messages_class_name.respond_to?(:table_name=)
38
+ messages_class_name.table_name = options[:table_name]
39
+ messages_class_name.initialize_scopes
41
40
  else
42
- self.messages_class_name.set_table_name(options[:table_name])
41
+ messages_class_name.set_table_name(options[:table_name])
43
42
  ActiveSupport::Deprecation.warn("Calling set_table_name is deprecated. Please use `self.table_name = 'the_name'` instead.")
44
43
  end
45
44
 
46
- self.messages_class_name.required = Array.wrap(options[:required])
47
- self.messages_class_name.validates_presence_of self.messages_class_name.required
45
+ messages_class_name.required = Array.wrap(options[:required])
46
+ messages_class_name.validates_presence_of messages_class_name.required
48
47
  self.group_messages = options[:group_messages]
49
48
 
50
49
  include ActsAsMessageable::Model::InstanceMethods
51
50
  end
52
51
 
53
- # Method recognize real object class
54
- # @return [ActiveRecord::Base] class or relation object
55
- def resolve_active_record_ancestor
56
- self.reflect_on_association(:received_messages_relation).active_record
57
- end
58
-
52
+ # Method recognize real object class
53
+ # @return [ActiveRecord::Base] class or relation object
54
+ def resolve_active_record_ancestor
55
+ reflect_on_association(:received_messages_relation).active_record
56
+ end
59
57
  end
60
58
 
61
59
  module InstanceMethods
@@ -70,7 +68,7 @@ module ActsAsMessageable
70
68
  # @return [ActiveRecord::Relation] returns all messages from inbox
71
69
  def received_messages
72
70
  result = ActsAsMessageable.rails_api.new(received_messages_relation)
73
- result = result.scoped.where(:recipient_delete => false)
71
+ result = result.scoped.where(recipient_delete: false)
74
72
  result.relation_context = self
75
73
 
76
74
  result
@@ -79,7 +77,7 @@ module ActsAsMessageable
79
77
  # @return [ActiveRecord::Relation] returns all messages from outbox
80
78
  def sent_messages
81
79
  result = ActsAsMessageable.rails_api.new(sent_messages_relation)
82
- result = result.scoped.where(:sender_delete => false)
80
+ result = result.scoped.where(sender_delete: false)
83
81
  result.relation_context = self
84
82
 
85
83
  result
@@ -100,12 +98,12 @@ module ActsAsMessageable
100
98
  message_attributes = {}
101
99
 
102
100
  case args.first
103
- when String
104
- self.class.messages_class_name.required.each_with_index do |attribute, index|
105
- message_attributes[attribute] = args[index]
106
- end
107
- when Hash
108
- message_attributes = args.first
101
+ when String
102
+ self.class.messages_class_name.required.each_with_index do |attribute, index|
103
+ message_attributes[attribute] = args[index]
104
+ end
105
+ when Hash
106
+ message_attributes = args.first
109
107
  end
110
108
 
111
109
  message = self.class.messages_class_name.new message_attributes
@@ -124,7 +122,9 @@ module ActsAsMessageable
124
122
  #
125
123
  # @return [ActsAsMessageable::Message] the message object
126
124
  def send_message!(to, *args)
127
- send_message(to, *args).save!
125
+ send_message(to, *args).tap do |message|
126
+ message.save!
127
+ end
128
128
  end
129
129
 
130
130
  # Reply to given message
@@ -150,12 +150,12 @@ module ActsAsMessageable
150
150
  current_user = self
151
151
 
152
152
  case current_user
153
- when message.to
154
- attribute = message.recipient_delete ? :recipient_permanent_delete : :recipient_delete
155
- when message.from
156
- attribute = message.sender_delete ? :sender_permanent_delete : :sender_delete
157
- else
158
- raise "#{current_user} can't delete this message"
153
+ when message.to
154
+ attribute = message.recipient_delete ? :recipient_permanent_delete : :recipient_delete
155
+ when message.from
156
+ attribute = message.sender_delete ? :sender_permanent_delete : :sender_delete
157
+ else
158
+ raise "#{current_user} can't delete this message"
159
159
  end
160
160
 
161
161
  message.update_attributes!(attribute => true)
@@ -166,12 +166,12 @@ module ActsAsMessageable
166
166
  current_user = self
167
167
 
168
168
  case current_user
169
- when message.to
170
- attribute = :recipient_delete
171
- when message.from
172
- attribute = :sender_delete
173
- else
174
- raise "#{current_user} can't restore this message"
169
+ when message.to
170
+ attribute = :recipient_delete
171
+ when message.from
172
+ attribute = :sender_delete
173
+ else
174
+ raise "#{current_user} can't restore this message"
175
175
  end
176
176
 
177
177
  message.update_attributes!(attribute => false)