Class: Gemgento::Address
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Gemgento::Address
- Defined in:
- app/models/gemgento/address.rb
Overview
Instance Attribute Summary collapse
-
#address1 ⇒ Object
Returns the value of attribute address1.
-
#address2 ⇒ Object
Returns the value of attribute address2.
-
#address3 ⇒ Object
Returns the value of attribute address3.
-
#copy_to_user ⇒ Object
Returns the value of attribute copy_to_user.
Instance Method Summary collapse
-
#as_json(options = nil) ⇒ String
Return the Address as JSON.
-
#copy_from_addressable_to_user ⇒ Gemgento::Address
Duplicate address from addressable user to user.
- #copy_from_addressable_to_user? ⇒ Boolean
-
#create_magento_address? ⇒ Boolean
Check if a Magento address can be created.
-
#duplicate ⇒ Gemgento::Address
Duplicate an address.
- #is_addressable_user? ⇒ Boolean
-
#street=(value) ⇒ Object
Set the street attribute.
-
#update_magento_address? ⇒ Boolean
Check if a Magento address can be updated.
Instance Attribute Details
#address1 ⇒ Object
Returns the value of attribute address1.
11 12 13 |
# File 'app/models/gemgento/address.rb', line 11 def address1 @address1 end |
#address2 ⇒ Object
Returns the value of attribute address2.
11 12 13 |
# File 'app/models/gemgento/address.rb', line 11 def address2 @address2 end |
#address3 ⇒ Object
Returns the value of attribute address3.
11 12 13 |
# File 'app/models/gemgento/address.rb', line 11 def address3 @address3 end |
#copy_to_user ⇒ Object
Returns the value of attribute copy_to_user.
11 12 13 |
# File 'app/models/gemgento/address.rb', line 11 def copy_to_user @copy_to_user end |
Instance Method Details
#as_json(options = nil) ⇒ String
Return the Address as JSON.
35 36 37 38 39 40 41 42 43 |
# File 'app/models/gemgento/address.rb', line 35 def as_json( = nil) result = super result['address1'] = self.address1 result['address2'] = self.address2 result['address3'] = self.address3 result['country'] = self.country.name unless self.country.nil? result['region'] = self.region.code unless self.region.nil? return result end |
#copy_from_addressable_to_user ⇒ Gemgento::Address
Duplicate address from addressable user to user.
48 49 50 51 52 53 54 55 56 57 |
# File 'app/models/gemgento/address.rb', line 48 def copy_from_addressable_to_user address = duplicate address.addressable = self.addressable.user address.is_billing = self.is_billing address.is_shipping = self.is_shipping address.sync_needed = true address.save return address end |
#copy_from_addressable_to_user? ⇒ Boolean
60 61 62 |
# File 'app/models/gemgento/address.rb', line 60 def copy_from_addressable_to_user? self.copy_to_user.to_bool && self.addressable.try(:user).is_a?(Gemgento::User) end |
#create_magento_address? ⇒ Boolean
Check if a Magento address can be created.
95 96 97 |
# File 'app/models/gemgento/address.rb', line 95 def create_magento_address? self.magento_id.nil? && self.is_addressable_user? end |
#duplicate ⇒ Gemgento::Address
Duplicate an address. Different from dup because it avoids unique magento attributes and includes country and region associations.
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/models/gemgento/address.rb', line 74 def duplicate address = self.dup address.region = self.region address.country = self.country address.magento_id = nil address.addressable = nil address.is_billing = false address.is_shipping = false address.increment_id = nil address.sync_needed = false return address end |
#is_addressable_user? ⇒ Boolean
88 89 90 |
# File 'app/models/gemgento/address.rb', line 88 def is_addressable_user? self.addressable.is_a?(Gemgento::User) end |
#street=(value) ⇒ Object
Set the street attribute. Override required to explode the street into address lines.
65 66 67 68 |
# File 'app/models/gemgento/address.rb', line 65 def street=(value) super explode_street_address end |
#update_magento_address? ⇒ Boolean
Check if a Magento address can be updated.
102 103 104 |
# File 'app/models/gemgento/address.rb', line 102 def update_magento_address? !self.magento_id.nil? && self.is_addressable_user? end |