Sha256: adda1bc9e69eddd21ce57f28530b2a1a8f5206b830e24e8a9fce8afabffe03ab
Contents?: true
Size: 1.17 KB
Versions: 1
Compression:
Stored size: 1.17 KB
Contents
# frozen_string_literal: true module Mobility module Backends =begin Defines read and write methods that access the value at a key with value +locale+ on a +translations+ hash. =end module HashValued # @!macro backend_constructor # @option options [Symbol] column_prefix Prefix added to generate column # name from attribute name # @option options [Symbol] column_suffix Suffix added to generate column # name from attribute name def initialize(_model, _attribute, options = {}) super @column_affix = "#{options[:column_prefix]}%s#{options[:column_suffix]}" end # @!group Backend Accessors # # @!macro backend_reader def read(locale, _options = nil) translations[locale] end # @!macro backend_writer def write(locale, value, _options = nil) translations[locale] = value end # @!endgroup # @!macro backend_iterator def each_locale translations.each { |l, _| yield l } end private def column_name @column_name ||= (@column_affix % attribute) end end private_constant :HashValued end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mobility-0.6.0 | lib/mobility/backends/hash_valued.rb |