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 <<-EOF
  class #{self.classified}
include Mongoid::Document
include Mongoid::Timestamps

  end
    EOF
  end

  path = app_path("spec", "models", "#{self.underscored}_spec.rb")
  FileUtils.mkdir_p File.dirname(path), verbose: true
  File.open(path, 'w') do |file|
    file.puts <<-EOF
  require 'spec_helper'

  describe #{self.classified} do

it "does something"

  end
    EOF
  end
end