devise_invitable 0.5.5 → 0.5.6

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of devise_invitable might be problematic. Click here for more details.

data/README.rdoc CHANGED
@@ -184,6 +184,18 @@ And include DeviseInvitable::Inviter module into Admin model:
184
184
  include DeviseInvitable::Inviter
185
185
  end
186
186
 
187
+ == Has many invitations
188
+
189
+ If you want to get all records invited by a resource, you should define has_many association in the model allowed to send invitations.
190
+
191
+ For the default behavior, define it like this:
192
+
193
+ has_many :invitations, :class_name => self.class.to_s, :as => :invited_by
194
+
195
+ For the previous example, where admins send invitations to users, define it like this:
196
+
197
+ has_many :invitations, :class_name => 'User', :as => :invited_by
198
+
187
199
  == I18n
188
200
 
189
201
  DeviseInvitable uses flash messages with I18n with the flash keys <tt>:send_instructions</tt>, <tt>:invitation_token_invalid</tt> and <tt>:updated</tt>. To customize your app, you can modify the generated locale file:
@@ -33,7 +33,7 @@ module Devise
33
33
  def accept_invitation!
34
34
  if self.invited? && self.valid?
35
35
  self.invitation_token = nil
36
- self.invitation_accepted_at = Time.now.utc
36
+ self.invitation_accepted_at = Time.now.utc if has_attribute? :invitation_accepted_at
37
37
  self.save
38
38
  end
39
39
  end
@@ -51,7 +51,7 @@ module Devise
51
51
  self.invitation_sent_at = Time.now.utc
52
52
  if save(:validate => self.class.validate_on_invite)
53
53
  self.invited_by.decrement_invitation_limit! if self.invited_by
54
- !!deliver_invitation unless @skip_invitation
54
+ deliver_invitation unless @skip_invitation
55
55
  end
56
56
  end
57
57
 
@@ -120,7 +120,7 @@ module Devise
120
120
  # If user is found and still have pending invitation, email is resend unless
121
121
  # resend_invitation is set to false
122
122
  # Attributes must contain the user email, other attributes will be set in the record
123
- def invite!(attributes={}, invited_by=nil, &block)
123
+ def _invite(attributes={}, invited_by=nil, &block)
124
124
  invitable = find_or_initialize_with_error_by(invite_key, attributes.delete(invite_key))
125
125
  invitable.attributes = attributes
126
126
  invitable.invited_by = invited_by
@@ -131,13 +131,23 @@ module Devise
131
131
  invitable.errors.add(invite_key, :taken) unless invitable.invited? && self.resend_invitation
132
132
  end
133
133
 
134
- if invitable.errors.empty?
134
+ if self.validate_on_invite || invitable.errors.empty?
135
135
  yield invitable if block_given?
136
- invitable.invite!
136
+ mail = invitable.invite!
137
137
  end
138
+ [invitable, mail]
139
+ end
140
+
141
+ def invite!(attributes={}, invited_by=nil, &block)
142
+ invitable, mail = _invite(attributes, invited_by, &block)
138
143
  invitable
139
144
  end
140
-
145
+
146
+ def invite_mail!(attributes={}, invited_by=nil, &block)
147
+ invitable, mail = _invite(attributes, invited_by, &block)
148
+ mail
149
+ end
150
+
141
151
  # Attempt to find a user by it's invitation_token to set it's password.
142
152
  # If a user is found, reset it's password and automatically try saving
143
153
  # the record. If not user is found, returns a new user containing an
@@ -1,3 +1,3 @@
1
1
  module DeviseInvitable
2
- VERSION = '0.5.5'
2
+ VERSION = '0.5.6'
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devise_invitable
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
4
+ hash: 7
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 5
10
- version: 0.5.5
9
+ - 6
10
+ version: 0.5.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sergio Cambra
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-20 00:00:00 Z
18
+ date: 2011-10-25 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: bundler