has_vcards 0.5.4 → 0.5.5
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/app/models/vcard.rb +13 -8
- metadata +2 -2
data/app/models/vcard.rb
CHANGED
@@ -1,9 +1,20 @@
|
|
1
|
-
|
1
|
+
module HasAddress
|
2
|
+
def self.included(base)
|
3
|
+
base.alias_method_chain :address, :autobuild
|
4
|
+
end
|
5
|
+
|
6
|
+
def address_with_autobuild
|
7
|
+
address_without_autobuild || build_address
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class Vard < ActiveRecord::Base
|
2
12
|
has_one :address, :autosave => true, :validate => true
|
3
13
|
accepts_nested_attributes_for :address
|
4
14
|
delegate :post_office_box, :extended_address, :street_address, :locality, :region, :postal_code, :country_name, :to => :address
|
5
15
|
delegate :post_office_box=, :extended_address=, :street_address=, :locality=, :region=, :postal_code=, :country_name=, :to => :address
|
6
|
-
|
16
|
+
include HasAddress
|
17
|
+
|
7
18
|
has_many :addresses, :autosave => true, :validate => true
|
8
19
|
accepts_nested_attributes_for :addresses
|
9
20
|
|
@@ -12,12 +23,6 @@ class Vcard < ActiveRecord::Base
|
|
12
23
|
|
13
24
|
belongs_to :object, :polymorphic => true
|
14
25
|
|
15
|
-
# Constructor
|
16
|
-
def initialize(attributes = nil)
|
17
|
-
super
|
18
|
-
|
19
|
-
build_address unless address
|
20
|
-
end
|
21
26
|
|
22
27
|
# Convenience accessors
|
23
28
|
def full_name
|