Class: Columns::ModelWriter
- Inherits:
-
Object
- Object
- Columns::ModelWriter
- Defined in:
- lib/columns/model_writer.rb
Overview
Add schema info to the end of a ruby model.
Instance Method Summary collapse
-
#add_info(model_data) ⇒ Object
Public: Puts model data and meta data to the end of a model file.
-
#initialize(path: './app/models/') ⇒ ModelWriter
constructor
Public: Creates a new ModelWriter.
Constructor Details
#initialize(path: './app/models/') ⇒ ModelWriter
Public: Creates a new ModelWriter.
path - String relative or absolute path to the models directory.
It's handy to be able to change the path during tests.
Default is './app/models/'.
11 12 13 |
# File 'lib/columns/model_writer.rb', line 11 def initialize(path: './app/models/') @path = path end |
Instance Method Details
#add_info(model_data) ⇒ Object
Public: Puts model data and meta data to the end of a model file.
model_data - A ModelData, used to deduce the model file and to
grab data.
Returns nothing.
21 22 23 24 25 26 27 28 29 |
# File 'lib/columns/model_writer.rb', line 21 def add_info(model_data) @model_data = model_data ensure_file_end_with_empty_line if File.exists?(model_path) File.open(model_path, 'a') do |file| file.puts(ExtendedContent.from(@model_data.content)) end end end |