Sha256: db3e6eab60ef8c78017ad7991b0d105e510d442f07e349200afac7f4bccd599c

Contents?: true

Size: 847 Bytes

Versions: 24

Compression:

Stored size: 847 Bytes

Contents

module Kuhsaft
  module Translatable

    def self.included(base)
      base.extend ClassMethods
    end

    module ClassMethods
      def translate *args
        args.each do |attr_name|
          define_method attr_name do
            send "#{attr_name}_#{I18n.locale}"
          end

          define_method "#{attr_name}?" do
            send "#{attr_name}_#{I18n.locale}?"
          end

          define_method "#{attr_name}=" do |val|
            send "#{attr_name}_#{I18n.locale}=", val
          end

          define_singleton_method "find_by_#{attr_name}" do |val|
            send "find_by_#{attr_name}_#{I18n.locale}", val
          end
        end
      end

      def locale_attr attr_name
        "#{attr_name}_#{I18n.locale}"
      end
    end

    def locale_attr attr_name
      "#{attr_name}_#{I18n.locale}"
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
kuhsaft-2.2.6 lib/kuhsaft/translatable.rb
kuhsaft-2.2.5 lib/kuhsaft/translatable.rb
kuhsaft-2.2.4 lib/kuhsaft/translatable.rb
kuhsaft-2.2.3 lib/kuhsaft/translatable.rb
kuhsaft-2.2.2 lib/kuhsaft/translatable.rb
kuhsaft-2.2.1 lib/kuhsaft/translatable.rb
kuhsaft-2.2.0 lib/kuhsaft/translatable.rb
kuhsaft-2.1.2 lib/kuhsaft/translatable.rb
kuhsaft-2.1.1 lib/kuhsaft/translatable.rb
kuhsaft-2.1.0 lib/kuhsaft/translatable.rb
kuhsaft-1.8.6 lib/kuhsaft/translatable.rb
kuhsaft-1.8.5 lib/kuhsaft/translatable.rb
kuhsaft-2.0.3 lib/kuhsaft/translatable.rb
kuhsaft-2.0.2 lib/kuhsaft/translatable.rb
kuhsaft-1.8.4 lib/kuhsaft/translatable.rb
kuhsaft-1.8.1 lib/kuhsaft/translatable.rb
kuhsaft-2.0.1 lib/kuhsaft/translatable.rb
kuhsaft-2.0.0 lib/kuhsaft/translatable.rb
kuhsaft-1.8.0 lib/kuhsaft/translatable.rb
kuhsaft-1.7.1 lib/kuhsaft/translatable.rb