Sha256: 6ce777151d6cae3db6f22e2dc9fe3e038e3bc739f671104cee06d09fa2e616f6

Contents?: true

Size: 917 Bytes

Versions: 7

Compression:

Stored size: 917 Bytes

Contents

class EnumerateItGenerator < Rails::Generators::NamedBase
  source_root File.expand_path('../templates', __FILE__)

  argument :attributes, :type => 'array', :default => []

  class_option :singular, :type => 'string', :desc => 'Singular name for i18n'

  class_option :lang, :type => 'string', :desc => 'Lang to use in i18n', :default => 'en'

  def create_locale
    template "locale.yml", File.join('config/locales', "#{singular_name}.yml")
  end

  def create_enumerate_it
    template "enumerate_it.rb", File.join('app/enumerations', "#{singular_name}.rb")
  end

  protected

  def default_lang
    options[:lang]
  end

  def singular
    singular_name
  end

  def locale_fields
    attributes.map(&:name)
  end

  def fields
    if attributes.first.type == :string
      attributes.map(&:name)
    else
      attributes.map do |attribute|
        [attribute.name, attribute.type]
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
enumerate_it-1.0.0 lib/generators/enumerate_it_generator.rb
enumerate_it-0.7.17 lib/generators/enumerate_it_generator.rb
enumerate_it-0.7.16 lib/generators/enumerate_it_generator.rb
enumerate_it-0.7.15 lib/generators/enumerate_it_generator.rb
enumerate_it-0.7.14 lib/generators/enumerate_it_generator.rb
enumerate_it-0.7.13 lib/generators/enumerate_it_generator.rb
enumerate_it-0.7.12 lib/generators/enumerate_it_generator.rb