Sha256: becf3ea2cfef62d6f8a287d163c288422d05b049e43e248b76df41d895b56d98

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

module Sequel
  module Plugins
    module Translatable
      def self.configure(model, attributes = [])
        attributes = [*attributes]
        raise Error, "please specify attributes to use for translatable plugin" if attributes.empty?
        attributes.each do |attribute|
          model.class_eval <<-EOS, __FILE__, __LINE__
            def #{attribute}=(value)
              send "#{attribute}_\#{base_locale}=", value
            end
            def #{attribute}
              send "#{attribute}_\#{base_locale}"
            end
            def #{attribute}_hash
              @#{attribute}_columns ||= columns.collect do |column|
                $1 if column=~/\\A#{Regexp.escape attribute}_(.+)\\z/
              end.compact.sort.collect(&:to_sym)
              hash = {}
              @#{attribute}_columns.each do |column|
                hash[column] = send "#{attribute}_\#{column}"
              end
              hash
            end
          EOS
        end
      end
      module ClassMethods
      end
      module DatasetMethods
      end
      module InstanceMethods
      private
        def base_locale
          I18n.locale.to_s[0..1]
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sequel_translatable-0.1.0 lib/sequel/plugins/translatable.rb