Module: RedPotion::Generators::ModelGeneratorMethods

Included in:
CDQModel, Scaffold
Defined in:
lib/redpotion/generators/shared/model_generator_methods.rb

Instance Method Summary collapse

Instance Method Details

#check_for_previous_schema!Object



5
6
7
8
9
10
# File 'lib/redpotion/generators/shared/model_generator_methods.rb', line 5

def check_for_previous_schema!
  Dir["schemas/*.rb"].each do |filename|
    @previous_schema_filename = File.basename(filename)
    @previous_schema_number = @previous_schema_filename.to_i # automatically trims off non-integer characters
  end
end

#new_schema_numberObject



20
21
22
23
24
# File 'lib/redpotion/generators/shared/model_generator_methods.rb', line 20

def new_schema_number
  number = previous_schema_number || 0
  number += 1
  sprintf("%04d", number)
end

#previous_schema_contentObject



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/redpotion/generators/shared/model_generator_methods.rb', line 26

def previous_schema_content
  if previous_schema_number
    previous_schema_content = ""
    File.open("schemas/#{previous_schema_filename}") do |file|
      file.each_line do |line|
        unless line =~ /schema/ or line =~ /^end$/
          previous_schema_content += line
        end
      end
    end
    previous_schema_content
  end
end

#previous_schema_filenameObject



12
13
14
# File 'lib/redpotion/generators/shared/model_generator_methods.rb', line 12

def previous_schema_filename
  @previous_schema_filename
end

#previous_schema_numberObject



16
17
18
# File 'lib/redpotion/generators/shared/model_generator_methods.rb', line 16

def previous_schema_number
  @previous_schema_number
end