Class: WeaponGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/support/grape_entity/grape_entity_generator.rb

Instance Method Summary collapse

Instance Method Details

#generate_grape_entityObject



4
5
6
7
8
9
10
11
12
13
# File 'lib/support/grape_entity/grape_entity_generator.rb', line 4

def generate_grape_entity
  names = args[0].split('/')
  column_names = names[-1].camelize.constantize.column_names
  infos = column_names.map {|column| "expose :#{column}"}
  a = Magicfile.new
  a.append_modules(names[0..-2])
  a.append_class(names[-1].camelize, 'Grape::Entity')
  a.append_string_lines(infos)
  a.to_file("app/#{args[0]}.rb")
end