Class: Xmvc::Generator::Model

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/xmvc/generators/model.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



6
7
8
# File 'lib/xmvc/generators/model.rb', line 6

def self.source_root 
  File.join(Xmvc::TEMPLATE_PATH)
end

Instance Method Details

#generate(name, *fields) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/xmvc/generators/model.rb', line 11

def generate(name, *fields)      
  filename    = Extlib::Inflection.underscore(name)
  
  @var_name   = filename
  @class_name = Extlib::Inflection.camelize(name)
  @fields     = fields.map {|f|
    field = f.split(':')
    {:name => field.shift, :type => field.shift}
  }

  model_filename = "app/models/#{filename}.js"
  spec_filename  = "spec/models/#{filename}.spec.js"
  
  unless File.exists?(model_filename)
    Xmvc::Config.add(:models, filename)
  end
  
  template("Model.js", model_filename)
  template("ModelSpec.js", spec_filename)
  
end