Sha256: 1c8052ac4d253cf671b2bd77d9571049d9f9c62787e69eb34121ad2a48f994e7

Contents?: true

Size: 914 Bytes

Versions: 3

Compression:

Stored size: 914 Bytes

Contents

module Iquest
  module SimpleTable
    module AttributeDescription
      def human_attribute_description(attribute, options = {})
        parts     = attribute.to_s.split(".")
        attribute = parts.pop
        namespace = parts.join("/") unless parts.empty?
        attributes_scope = "#{i18n_scope}.descriptions"

        if namespace
          defaults = lookup_ancestors.map do |klass|
            :"#{attributes_scope}.#{klass.model_name.i18n_key}/#{namespace}.#{attribute}"
          end
          defaults << :"#{attributes_scope}.#{namespace}.#{attribute}"
        else
          defaults = lookup_ancestors.map do |klass|
            :"#{attributes_scope}.#{klass.model_name.i18n_key}.#{attribute}"
          end
        end

        defaults << options.delete(:default) if options[:default]

        options[:default] = ''
        I18n.translate(defaults.shift, **options)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
iquest-simple_table-0.4.4 lib/iquest/simple_table/attribute_description.rb
iquest-simple_table-0.4.3 lib/iquest/simple_table/attribute_description.rb
iquest-simple_table-0.4.2 lib/iquest/simple_table/attribute_description.rb