Class: NetMate::Generators::ModelGenerator
- Inherits:
-
Object
- Object
- NetMate::Generators::ModelGenerator
- Defined in:
- lib/net_mate/model_generator.rb
Instance Method Summary collapse
- #generate_model ⇒ Object
-
#initialize(model, columns) ⇒ ModelGenerator
constructor
A new instance of ModelGenerator.
Constructor Details
#initialize(model, columns) ⇒ ModelGenerator
Returns a new instance of ModelGenerator.
8 9 10 11 |
# File 'lib/net_mate/model_generator.rb', line 8 def initialize model, columns @model = model.dup @columns = columns end |
Instance Method Details
#generate_model ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/net_mate/model_generator.rb', line 13 def generate_model flag = false cur_dir = Dir.pwd while cur_dir != "/" do if Dir.exist? 'app' FileUtils.cd 'app' if Dir.exist? 'models' call_create_table FileUtils.cd 'models' model_rb = ActiveSupport::Inflector.underscore "#{@model}.rb" output = "class #{ActiveSupport::Inflector.camelize(@model)} < NetMate::Model\nend" IO.write model_rb, output puts "Created app/models/#{model_rb}" flag = true break else abort 'ERROR: app/models folder does not exist' end else cur_dir = File. '..', Dir.pwd FileUtils.cd cur_dir end end abort "ERROR: please move to the application folder" unless flag end |