app/models/country.rb in has_addresses-0.5.0 vs app/models/country.rb in has_addresses-0.5.1
- old
+ new
@@ -43,15 +43,22 @@
alias_attribute :abbreviation_2, :alpha_2_code
alias_attribute :abbreviation_3, :alpha_3_code
def initialize(attributes = nil) #:nodoc:
- super
- self.official_name ||= name unless attributes && attributes.include?(:official_name)
+ super(self.class.with_defaults(attributes))
end
- fast_bootstrap(
+ # Adds the default attributes for the given country attributes
+ def self.with_defaults(attributes = nil)
+ attributes ||= {}
+ attributes.symbolize_keys!
+ attributes[:official_name] = attributes[:name] unless attributes.include?(:official_name)
+ attributes
+ end
+
+ fast_bootstrap([
{:id => 4, :name => "Afghanistan", :official_name => "Islamic Republic of Afghanistan", :alpha_2_code => 'AF', :alpha_3_code => 'AFG'},
{:id => 8, :name => "Albania", :official_name => "Republic of Albania", :alpha_2_code => 'AL', :alpha_3_code => 'ALB'},
{:id => 10, :name => "Antarctica", :alpha_2_code => 'AQ', :alpha_3_code => 'ATA'},
{:id => 12, :name => "Algeria", :official_name => "People's Democratic Republic of Algeria", :alpha_2_code => 'DZ', :alpha_3_code => 'DZA'},
{:id => 16, :name => "American Samoa", :alpha_2_code => 'AS', :alpha_3_code => 'ASM'},
@@ -294,7 +301,7 @@
{:id => 862, :name => "Venezuela", :official_name => "Bolivarian Republic of Venezuela", :alpha_2_code => 'VE', :alpha_3_code => 'VEN'},
{:id => 876, :name => "Wallis and Futuna", :alpha_2_code => 'WF', :alpha_3_code => 'WLF'},
{:id => 882, :name => "Samoa", :official_name => "Independent State of Samoa", :alpha_2_code => 'WS', :alpha_3_code => 'WSM'},
{:id => 887, :name => "Yemen", :official_name => "Republic of Yemen", :alpha_2_code => 'YE', :alpha_3_code => 'YEM'},
{:id => 894, :name => "Zambia", :official_name => "Republic of Zambia", :alpha_2_code => 'ZM', :alpha_3_code => 'ZMB'}
- )
+ ].map {|attributes| with_defaults(attributes)})
end