Sha256: 0c196276703de761582ffbd897677649c0298795e9ef8b25810aaa4658096855

Contents?: true

Size: 1015 Bytes

Versions: 28

Compression:

Stored size: 1015 Bytes

Contents

# frozen-string-literal: true

module Mobility
  module Plugins
    module Writer
=begin

Defines attribute writer that delegates to +Mobility::Backend#write+.

=end
      extend Plugin

      default true
      requires :backend

      initialize_hook do |*names|
        if options[:writer]
          names.each do |name|
            class_eval <<-EOM, __FILE__, __LINE__ + 1
              def #{name}=(value, locale: nil, **options)
                #{Writer.setup_source}
                mobility_backends[:#{name}].write(locale, value, **options)
              end
            EOM
          end
        end
      end

      def self.setup_source
        <<-EOL
        return super(value) if options[:super]
        if (locale &&= locale.to_sym)
          #{"Mobility.enforce_available_locales!(locale)" if I18n.enforce_available_locales}
          options[:locale] = true
        else
          locale = Mobility.locale
        end
        EOL
      end
    end

    register_plugin(:writer, Writer)
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
mobility-1.3.0.rc3 lib/mobility/plugins/writer.rb
mobility-1.3.0.rc2 lib/mobility/plugins/writer.rb
mobility-1.3.0.rc1 lib/mobility/plugins/writer.rb
mobility-1.2.9 lib/mobility/plugins/writer.rb
mobility-1.2.8 lib/mobility/plugins/writer.rb
mobility-1.2.7 lib/mobility/plugins/writer.rb
mobility-1.2.6 lib/mobility/plugins/writer.rb
mobility-1.2.5 lib/mobility/plugins/writer.rb
mobility-1.2.4 lib/mobility/plugins/writer.rb
mobility-1.2.3 lib/mobility/plugins/writer.rb
mobility-1.2.2 lib/mobility/plugins/writer.rb
mobility-1.2.1 lib/mobility/plugins/writer.rb
mobility-1.2.0 lib/mobility/plugins/writer.rb
mobility-1.1.3 lib/mobility/plugins/writer.rb
mobility-1.1.2 lib/mobility/plugins/writer.rb
mobility-1.1.1 lib/mobility/plugins/writer.rb
mobility-1.1.0 lib/mobility/plugins/writer.rb
mobility-1.0.7 lib/mobility/plugins/writer.rb
mobility-1.0.6 lib/mobility/plugins/writer.rb
mobility-1.0.5 lib/mobility/plugins/writer.rb