Sha256: efd3a9e078dac193a272cf9873b87e4aa2858910e241e100663bbacf91fb0c5b

Contents?: true

Size: 1.31 KB

Versions: 13

Compression:

Stored size: 1.31 KB

Contents

module Cmor
  module Legal
    class AllowedCookie
      extend ActiveModel::Model
      extend ActiveModel::Translation

      def self.attribute_names
        %w(name domain expiry description url)
      end

      attr_accessor *self.attribute_names

      def initialize(attributes = {})
        attributes.each do |key, value|
          send("#{key}=", value)
        end
      end

      def expiry(options = {})
        return if @expiry.nil?

        if options.has_key?(:locale)
          @expiry.is_a?(Symbol) ? I18n.t("activemodel.values.#{self.class.name.underscore}.expiry.#{@expiry}") : localize(options[:locale], @expiry)
        else
          @expiry
        end
      end

      def description(locale: I18n.locale)
        return unless @description.respond_to?(:[]) && @description.has_key?(locale.to_sym)
        @description[locale.to_sym]
      end

      module L10nConcern
        extend ActiveSupport::Concern

        def localize(locale, object, format = :default, options = {})
          if object.is_a?(ActiveSupport::Duration)
            object.parts.collect { |k, v| I18n.t("datetime.distance_in_words.x_#{k}", count: v) }.to_sentence
          else
            I18n.localize(object, locale: locale, format: format, **options)
          end
        end
      end

      include L10nConcern
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
cmor_legal-0.0.60.pre app/models/cmor/legal/allowed_cookie.rb
cmor_legal-0.0.59.pre app/models/cmor/legal/allowed_cookie.rb
cmor_legal-0.0.58.pre app/models/cmor/legal/allowed_cookie.rb
cmor_legal-0.0.57.pre app/models/cmor/legal/allowed_cookie.rb
cmor_legal-0.0.56.pre app/models/cmor/legal/allowed_cookie.rb
cmor_legal-0.0.55.pre app/models/cmor/legal/allowed_cookie.rb
cmor_legal-0.0.54.pre app/models/cmor/legal/allowed_cookie.rb
cmor_legal-0.0.53.pre app/models/cmor/legal/allowed_cookie.rb
cmor_legal-0.0.52.pre app/models/cmor/legal/allowed_cookie.rb
cmor_legal-0.0.51.pre app/models/cmor/legal/allowed_cookie.rb
cmor_legal-0.0.50.pre app/models/cmor/legal/allowed_cookie.rb
cmor_legal-0.0.49.pre app/models/cmor/legal/allowed_cookie.rb
cmor_legal-0.0.48.pre app/models/cmor/legal/allowed_cookie.rb