Class: Localtower::Generators::Model
- Inherits:
-
Object
- Object
- Localtower::Generators::Model
- Defined in:
- lib/localtower/generators/model.rb
Instance Method Summary collapse
-
#initialize(opts) ⇒ Model
constructor
A new instance of Model.
- #run ⇒ Object
Constructor Details
#initialize(opts) ⇒ Model
Returns a new instance of Model.
4 5 6 7 8 9 10 11 |
# File 'lib/localtower/generators/model.rb', line 4 def initialize(opts) @opts = JSON[opts.to_json] # stringify keys @model_name = @opts['model_name'] @attributes = @opts['attributes'] raise "No model_name provided" if @model_name.blank? raise "No attributes provided" if @attributes.blank? end |
Instance Method Details
#run ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/localtower/generators/model.rb', line 13 def run attributes_str = parse_attributes.join(" ") cmd = "rails generate model #{model_name.camelize} #{attributes_str}" ::Localtower::Tools.perform_cmd(cmd) insert_non_nullable_values insert_default_values insert_array insert_indexes end |