Class: Ratbug::Generators::JbuilderGenerator
- Inherits:
-
Object
- Object
- Ratbug::Generators::JbuilderGenerator
- Defined in:
- lib/ratbug/generators/jbuilder_generator.rb
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(table, options) ⇒ JbuilderGenerator
constructor
A new instance of JbuilderGenerator.
Constructor Details
#initialize(table, options) ⇒ JbuilderGenerator
Returns a new instance of JbuilderGenerator.
6 7 8 9 |
# File 'lib/ratbug/generators/jbuilder_generator.rb', line 6 def initialize(table, ) @table = table = end |
Instance Method Details
#generate ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ratbug/generators/jbuilder_generator.rb', line 11 def generate singular = @table.name.singularize output = "" output << "json.#{singular} do\n" columns.values.sort_by(&:name).each do |column| output << column_row(column, singular) end output << "end" dirname = File.dirname(output_path) unless File.directory?(dirname) FileUtils.mkdir_p(dirname) end File.open(output_path, "w") do |f| f.puts(output) end puts "generated: #{output_path}" end |