Module: Shoppe::AssociatedCountries

Included in:
DeliveryServicePrice, TaxRate
Defined in:
lib/shoppe/associated_countries.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object


4
5
6
7
# File 'lib/shoppe/associated_countries.rb', line 4

def self.included(base)
  base.serialize :country_ids, Array
  base.before_validation { self.country_ids = self.country_ids.map(&:to_i).select { |i| i > 0} if self.country_ids.is_a?(Array) }
end

Instance Method Details

#countriesObject


14
15
16
17
# File 'lib/shoppe/associated_countries.rb', line 14

def countries
  return [] unless self.country_ids.is_a?(Array) && !self.country_ids.empty?
  Shoppe::Country.where(:id => self.country_ids)
end

#country?(id) ⇒ Boolean

Returns:

  • (Boolean)

9
10
11
12
# File 'lib/shoppe/associated_countries.rb', line 9

def country?(id)
  id = id.id if id.is_a?(Shoppe::Country)
  self.country_ids.is_a?(Array) && self.country_ids.include?(id.to_i)
end