Sha256: fce6ff9164e699b316ed019cb7cc64444c96126785b4b3110e496be526bc8e3e

Contents?: true

Size: 875 Bytes

Versions: 3

Compression:

Stored size: 875 Bytes

Contents

module Locomotive::Steam
  module Models

    class I18nField

      extend Forwardable

      def_delegators :@translations, :values, :blank?

      attr_reader :name, :translations

      def initialize(name, translations)
        @name = name
        self.translations = translations
      end

      def [](locale)
        @translations[locale]
      end

      def []=(locale, value)
        @translations[locale] = value
      end

      def translations=(translations)
        @translations = (if translations.respond_to?(:fetch)
          translations
        else
          Hash.new { translations }
        end).with_indifferent_access
      end

      def each(&block)
        @translations.each(&block)
      end

      alias :__translations__ :translations

      def serialize(attributes)
        attributes[@name] = @translations
      end

    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
locomotivecms_steam-1.0.0.pre.beta.3 lib/locomotive/steam/models/i18n_field.rb
locomotivecms_steam-1.0.0.pre.beta.2 lib/locomotive/steam/models/i18n_field.rb
locomotivecms_steam-1.0.0.pre.beta.1 lib/locomotive/steam/models/i18n_field.rb