Class: Deano::ModelGenerator

Inherits:
NameCommand show all
Defined in:
lib/deano/commands/model_generator_command.rb

Instance Attribute Summary

Attributes inherited from NameCommand

#args, #name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from NameCommand

#classified, #clean_string, inherited, #initialize, #underscored

Methods inherited from Command

#app_path, #cmd, commands, inherited, #rm, #rm_r, #template_path

Constructor Details

This class inherits a constructor from Deano::NameCommand

Class Method Details

.commandObject



4
5
6
# File 'lib/deano/commands/model_generator_command.rb', line 4

def self.command
  "generate:model"
end

.helpObject



8
9
10
# File 'lib/deano/commands/model_generator_command.rb', line 8

def self.help
  "model_name"
end

Instance Method Details

#callObject



12
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
38
# File 'lib/deano/commands/model_generator_command.rb', line 12

def call
  path = app_path("models", "#{self.underscored}.rb")
  FileUtils.mkdir_p File.dirname(path), verbose: true
  File.open(path, 'w') do |file|
    file.puts "  class \#{self.classified}\ninclude Mongoid::Document\ninclude Mongoid::Timestamps\n\n  end\n    EOF\n  end\n\n  path = app_path(\"spec\", \"models\", \"\#{self.underscored}_spec.rb\")\n  FileUtils.mkdir_p File.dirname(path), verbose: true\n  File.open(path, 'w') do |file|\n    file.puts <<-EOF\n  require 'spec_helper'\n\n  describe \#{self.classified} do\n\nit \"does something\"\n\n  end\n    EOF\n  end\nend\n"