Class: Jazz::Generators::Model

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



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

def attributes
  @attributes
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

Class Method Details

.source_rootObject



8
9
10
# File 'lib/jazz/generators/model/model.rb', line 8

def self.source_root
  File.join(File.dirname(__FILE__))
end

Instance Method Details

#convert_attributesObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/jazz/generators/model/model.rb', line 31

def convert_attributes
  @attribute_hash = Hash.new
  
  attributes.each do |attribute|
    val = attribute.split(':')
    if val[0] && val[1]
      @attribute_hash[val[0]] = val[1]
    end
    
  end
  
  self.attributes = {}
  self.attributes = @attribute_hash
end

#createObject



12
13
14
15
16
17
# File 'lib/jazz/generators/model/model.rb', line 12

def create
  convert_attributes        
  create_model
  create_database
  create_fixture
end

#create_databaseObject



23
24
25
# File 'lib/jazz/generators/model/model.rb', line 23

def create_database
  template  "templates/database.js", "db/create/create_#{name.pluralize.downcase}.js"
end

#create_fixtureObject



27
28
29
# File 'lib/jazz/generators/model/model.rb', line 27

def create_fixture
  template  "templates/fixture.js", "db/fixtures/#{name.pluralize.downcase}.js"
end

#create_modelObject



19
20
21
# File 'lib/jazz/generators/model/model.rb', line 19

def create_model
  template  "templates/model.js", "app/models/#{name.singularize.downcase}.js"
end