Class: Cubic::Generator::Model
- Defined in:
- lib/cubic/generators/model.rb
Overview
Model fulfils the M in the MVC pattern. Files the Model generator creates will include a class inheriting from the class your ORM suggests.
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#add(*code) ⇒ Object
Allows user to specify code that should be included in generated model file.
-
#callback ⇒ Object
Called after a file is successfully generated from hash created by design method.
-
#design(name, options = {}) ⇒ Object
Creates a hash that will be used for file generation purposes.
-
#initialize ⇒ Model
constructor
A new instance of Model.
Methods inherited from Base
Constructor Details
#initialize ⇒ Model
Returns a new instance of Model.
8 9 10 11 |
# File 'lib/cubic/generators/model.rb', line 8 def initialize @migration = Migrations.new super() end |
Instance Method Details
#add(*code) ⇒ Object
Allows user to specify code that should be included in generated model file. Example: add(‘has_many :users’)
32 33 34 35 |
# File 'lib/cubic/generators/model.rb', line 32 def add(*code) code *= "\n" @files.last[:content] = insert_code(@files.last[:content], code) end |
#callback ⇒ Object
Called after a file is successfully generated from hash created by design method.
25 26 27 |
# File 'lib/cubic/generators/model.rb', line 25 def callback @migration.generate end |
#design(name, options = {}) ⇒ Object
Creates a hash that will be used for file generation purposes
14 15 16 17 18 19 20 21 |
# File 'lib/cubic/generators/model.rb', line 14 def design(name, = {}) @migration.design(name, ) @files << { name: "#{name}.rb", path: '/app/models', content: format_model(name) } self end |