Sha256: e51e6d3e3c821be989110532e3b620c9d251ff3072b0f24b50d015422cdbfdf9

Contents?: true

Size: 1.7 KB

Versions: 10

Compression:

Stored size: 1.7 KB

Contents

require 'lolita-translation/translation_class_builder'
module Lolita
  module Translation

    def self.included(base)
      base.extend(Lolita::Translation::ORM::ClassMethods)
      base.class_eval do
        include Lolita::Translation::ORM::InstanceMethods
      end
    end

    class Configuration
      attr_reader :klass, :attributes, :translation_class, :options
      alias :translation_attributes :attributes

      def initialize(base_klass, *args, &block)
        @options            = (args.respond_to?(:last) && args.last.is_a?(Hash) && args.pop) || {}
        @klass              = base_klass
        @attributes         = args
        if base_klass.table_exists?
          build_translation_class
          if block_given?
            block.call(self)
          end
        end
      end

      def association_name
        options[:association_name] || :translations
      end

      def locales
        if options[:locales]
          Lolita::Translation::Locales.new(options[:locales])
        else
          Lolita::Translation.locales
        end
      end

      def locale_field_name
        options[:locale_field_name] || :default_locale
      end

      def association_key
        options[:association_key] || :"#{demodulized_class_name}_id"
      end

      def table_name
        options[:table_name] || "#{klass.table_name}_translations"
      end

      def demodulized_class_name
        klass.to_s.demodulize.underscore
      end

      private

      def build_translation_class
        @builder            = Lolita::Translation::TranslationClassBuilder.new(self.klass, self)
        @translation_class  = @builder.build_class
        @builder.override_attributes(@attributes)
      end

    end

  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
lolita-translation-0.8.4 lib/lolita-translation/configuration.rb
lolita-translation-0.8.3 lib/lolita-translation/configuration.rb
lolita-translation-0.8.2 lib/lolita-translation/configuration.rb
lolita-translation-0.8.1 lib/lolita-translation/configuration.rb
lolita-translation-0.8.0 lib/lolita-translation/configuration.rb
lolita-translation-0.7.4 lib/lolita-translation/configuration.rb
lolita-translation-0.7.3 lib/lolita-translation/configuration.rb
lolita-translation-0.7.2 lib/lolita-translation/configuration.rb
lolita-translation-0.7.1 lib/lolita-translation/configuration.rb
lolita-translation-0.7.0 lib/lolita-translation/configuration.rb