has_many_emails 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.3
|
data/has_many_emails.gemspec
CHANGED
@@ -2,23 +2,23 @@ class <%= migration_name %> < ActiveRecord::Migration
|
|
2
2
|
|
3
3
|
def self.up
|
4
4
|
create_table :<%= email_address_table_name %> do |t|
|
5
|
-
t.integer :
|
6
|
-
t.string :
|
5
|
+
t.integer :addressee_id, :null => false
|
6
|
+
t.string :addressee_type, :null => false
|
7
7
|
t.string :email, :null => false
|
8
8
|
# t.boolean :is_main, :null => false, :default=>false
|
9
9
|
|
10
10
|
t.timestamps
|
11
11
|
end
|
12
12
|
|
13
|
-
add_index :<%= email_address_table_name %>, [:
|
13
|
+
add_index :<%= email_address_table_name %>, [:addressee_id, :addressee_type, :email], :unique=>true, :name=>:index_<%= email_address_table_name %>_addressee_id
|
14
14
|
add_index :<%= email_address_table_name %>, :email
|
15
15
|
|
16
16
|
|
17
17
|
<% models_with_emails.each do |model| %>
|
18
18
|
if <%= model %>.column_names.include? 'email'
|
19
19
|
raise "PROBLEM! <%= model %> does not have 'has_many_emails'. Insert it before usage." unless <%= model %>.respond_to? :has_many_emails
|
20
|
-
<%= model %>.all.each do |
|
21
|
-
|
20
|
+
<%= model %>.all.each do |addressee|
|
21
|
+
addressee.add_email addressee.attributes['email']
|
22
22
|
end
|
23
23
|
end
|
24
24
|
<% end %>
|
data/lib/has_many_emails.rb
CHANGED
@@ -13,7 +13,7 @@ module HasManyEmails
|
|
13
13
|
def has_many_emails
|
14
14
|
class_eval <<-EOV
|
15
15
|
|
16
|
-
has_many :email_addresses, :dependent=>:destroy, :class_name => 'HasManyEmails::EmailAddress'
|
16
|
+
has_many :email_addresses, :dependent=>:destroy, :class_name => 'HasManyEmails::EmailAddress', :as => :addressee
|
17
17
|
|
18
18
|
validate :validate_email_addresses
|
19
19
|
|
@@ -4,7 +4,7 @@ module HasManyEmails
|
|
4
4
|
module ClassMethods
|
5
5
|
|
6
6
|
def find_by_email( email )
|
7
|
-
address = HasManyEmails::EmailAddress.find_by_email( email.downcase ) and address.
|
7
|
+
address = HasManyEmails::EmailAddress.find_by_email( email.downcase ) and address.addressee
|
8
8
|
end
|
9
9
|
|
10
10
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: has_many_emails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 3
|
10
|
+
version: 0.3.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Danil Pismenny
|