Sha256: b2ceb43afb9719c69c40538ed5174d7c8feecb98eb8578662da530e497c7776a

Contents?: true

Size: 538 Bytes

Versions: 9

Compression:

Stored size: 538 Bytes

Contents

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

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

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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
tienda-2.1.3 lib/tienda/associated_countries.rb
tienda-2.1.2 lib/tienda/associated_countries.rb
tienda-2.1.1 lib/tienda/associated_countries.rb
tienda-2.1.0 lib/tienda/associated_countries.rb
tienda-2.0.2 lib/tienda/associated_countries.rb
tienda-2.0.1 lib/tienda/associated_countries.rb
tienda-1.1.2 lib/tienda/associated_countries.rb
tienda-1.1.1 lib/tienda/associated_countries.rb
tienda-1.1.0 lib/tienda/associated_countries.rb