Sha256: e2f8faf3677c222682e3125d07f4ad7d1e79a942186bfe3baac7db4a672fe4d7

Contents?: true

Size: 592 Bytes

Versions: 24

Compression:

Stored size: 592 Bytes

Contents

module Shoppe
  module AssociatedCountries
    
    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
    
    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
    
    def countries
      return [] unless self.country_ids.is_a?(Array) && !self.country_ids.empty?
      Shoppe::Country.where(:id => self.country_ids)
    end
    
  end
end

Version data entries

24 entries across 24 versions & 3 rubygems

Version Path
shoppe-1.1.2 lib/shoppe/associated_countries.rb
shoppe-1.1.1 lib/shoppe/associated_countries.rb
shoppe-1.1.0 lib/shoppe/associated_countries.rb
shoppe-1.0.9 lib/shoppe/associated_countries.rb
shoppe-1.0.8 lib/shoppe/associated_countries.rb
kylekthompson-shoppe-1.0.7 lib/shoppe/associated_countries.rb
shoppe-1.0.7 lib/shoppe/associated_countries.rb
shoppe-1.0.6 lib/shoppe/associated_countries.rb
shoppe-paypal-1.1.0 vendor/bundle/ruby/2.1.0/gems/shoppe-1.0.5/lib/shoppe/associated_countries.rb
shoppe-1.0.5 lib/shoppe/associated_countries.rb
shoppe-1.0.3 lib/shoppe/associated_countries.rb
shoppe-1.0.2 lib/shoppe/associated_countries.rb
shoppe-1.0.1 lib/shoppe/associated_countries.rb
shoppe-1.0.0 lib/shoppe/associated_countries.rb
shoppe-0.0.21 lib/shoppe/associated_countries.rb
shoppe-0.0.20 lib/shoppe/associated_countries.rb
shoppe-0.0.19 lib/shoppe/associated_countries.rb
shoppe-0.0.18 lib/shoppe/associated_countries.rb
shoppe-0.0.17 lib/shoppe/associated_countries.rb
shoppe-0.0.16 lib/shoppe/associated_countries.rb