Class: Enumerative::EnumerationGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/enumerative/enumeration/enumeration_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



12
13
14
15
# File 'lib/generators/enumerative/enumeration/enumeration_generator.rb', line 12

def self.source_root
  File.join File.dirname(__FILE__),
            'templates'
end

Instance Method Details

#insert_translationObject



25
26
27
28
29
30
31
32
# File 'lib/generators/enumerative/enumeration/enumeration_generator.rb', line 25

def insert_translation
  text = []
  text << "    #{file_name}:"
  text += keys_and_values.sort { |a,b| a.first <=> b.first }.map { |k,v| "      #{k}: #{quote_if_numeric( v )}" }
  inject_into_file 'config/locales/en.yml', after: "enumerations:\n" do
    text.join( "\n" ) + "\n"
  end
end

#install_enumerationObject



17
18
19
# File 'lib/generators/enumerative/enumeration/enumeration_generator.rb', line 17

def install_enumeration
  template "enumeration.rb", File.join( 'app', path, "#{file_name}.rb" )
end

#install_enumeration_specObject



21
22
23
# File 'lib/generators/enumerative/enumeration/enumeration_generator.rb', line 21

def install_enumeration_spec
  template "enumeration_spec.rb", File.join( 'spec', path, "#{file_name}_spec.rb" )
end