Class: FOSClassGenerator
Constant Summary collapse
- CLASS_TEXT =
<<-STR class CLASS_NAME < Sequel::Model(:'TABLE_NAME')\n SEQUEL_INFO end STR
- SEQUEL_TEXT =
<<-STR #### BEGIN GENERATED SECTION #### \tset_primary_key [:'kid - user', :'kid - mult', :'kid - comm', :'kid - date', :'kid - time'] COLUMN_DEFINITIONS #### END GENERATED SECTION #### STR
Instance Method Summary collapse
-
#initialize(file) ⇒ FOSClassGenerator
constructor
A new instance of FOSClassGenerator.
- #write_class_file ⇒ Object
Constructor Details
#initialize(file) ⇒ FOSClassGenerator
Returns a new instance of FOSClassGenerator.
51 52 53 54 55 56 57 |
# File 'lib/fos_schema/fos_table_gen.rb', line 51 def initialize( file ) @file = file @table_name = file[:'xf$name'].downcase @escaped_table_name = @table_name.gsub('\'', "\\\\\\\\'") @class_name = make_pretty_table_name(@table_name) @file_name = make_pretty_file_name(@table_name) end |
Instance Method Details
#write_class_file ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/fos_schema/fos_table_gen.rb', line 59 def write_class_file file_name = File.join("..","models","#{@file_name}.rb") puts "filename=#{file_name}" file_str = File.exists?(file_name) ? File.read(file_name) : new_class_text sequel_part = build_sequel_section #~ puts sequel_part if @file_name == "aircraft" if( !file_str.sub!(/#### BEGIN GENERATED SECTION ####[^.|.]*#### END GENERATED SECTION ####/, sequel_part.chop) ) puts "CANNOT SUBSTITUTE NEW TEXT INTO OLD FILE for #{@file_name}" return end File.open(file_name,"w"){ |file| file.write(file_str) } end |