Sha256: 841b9c4a6e57b102ca5f5e929f94fd22a12a36cc70ec793a7b0421889301249e

Contents?: true

Size: 930 Bytes

Versions: 3

Compression:

Stored size: 930 Bytes

Contents

require "yaml"

module I18nAttributes
  module GeneratorHelpers

    def generate_yaml_file_data(locale, singular_name, human_name, attributes, orm="active_record")
      YAML.dump_stream(
        {
          locale.to_s => {
            orm.to_s => {
              "models" => {
                singular_name => human_name.to_s
              },
              "attributes" => {
                singular_name => columns_hash(attributes).merge(enums_hash(attributes))
              }
            }
          }
        }
      )
    end

    private
      def columns_hash(attributes)
        Hash[ attributes.keys.map {|k| [k.to_s, k.to_s.humanize]} ]
      end

      def enums_hash(attributes)
        enums = {}
        I18nAttributes::Configuration.enums_attributes.each do |k,v|
          attributes.keys.index(k) ? enums.merge!(k => v) : next
        end
        enums.empty? ? {} : { "enums" => enums }
      end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
i18n_attributes-0.1.2 lib/i18n_attributes/generator_helpers.rb
i18n_attributes-0.1.1.1 lib/i18n_attributes/generator_helpers.rb
i18n_attributes-0.1.1 lib/i18n_attributes/generator_helpers.rb