Sha256: 77e30b795db7b26bf85f87fbeac34e71c8b2c02bccae5c277e44e73f7978e140

Contents?: true

Size: 1004 Bytes

Versions: 6

Compression:

Stored size: 1004 Bytes

Contents

require 'carmen'

connection      = ActiveRecord::Base.connection
country_inserts = []

country_values = -> do
  Carmen::Country.all.each do |country|
    name            = connection.quote country.name
    iso3            = connection.quote country.alpha_3_code
    iso             = connection.quote country.alpha_2_code
    iso_name        = connection.quote country.name.upcase
    numcode         = connection.quote country.numeric_code
    states_required = connection.quote country.subregions?

    country_inserts << [name, iso3, iso, iso_name, numcode, states_required].join(", ")
  end

  country_inserts.join("), (")
end

columns = ["name", "iso3", "iso", "iso_name", "numcode", "states_required"]
columns = connection.adapter_name =~ /MySQL/i ? columns.join(", ") : "\"#{columns.join('", "')}\""

connection.execute <<-SQL
  INSERT INTO spree_countries (#{columns})
  VALUES (#{country_values.call});
SQL

Spree::Config[:default_country_id] = Spree::Country.find_by(name: "United States").id

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
spree_core-3.0.2 db/default/spree/countries.rb
spree_core-3.0.1 db/default/spree/countries.rb
spree_core-3.0.0 db/default/spree/countries.rb
spree_core-3.0.0.rc4 db/default/spree/countries.rb
spree_core-3.0.0.rc3 db/default/spree/countries.rb
spree_core-3.0.0.rc1 db/default/spree/countries.rb