Class: Raxe::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/raxe/generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(raxe) ⇒ Generator



6
7
8
# File 'lib/raxe/generator.rb', line 6

def initialize( raxe )
  @raxe = raxe
end

Instance Method Details

#generate(generate_data) ⇒ Object

initialize



10
11
12
13
14
15
16
17
18
19
# File 'lib/raxe/generator.rb', line 10

def generate(generate_data)
  case generate_data[:req]
    when :generate
      make_packages( generate_data[:package] )
      make_files( generate_data[:package], generate_data[:file] )
    when :ungenerate
      kill_files( generate_data[:package], generate_data[:file] ) 
      kill_packages( generate_data[:package] )
  end # case req
end

#kill_files(package, file) ⇒ Object

generate



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/raxe/generator.rb', line 21

def kill_files( package, file )
  # Step 1 : Check existence
  flags = p_check_file_existence( package, file )
  
  # Step 2 : Remove the ones who exist
  flags.each do | path, status |
    if status
      File.delete( path ) 
      puts " Deleted file " + path
    else # status
      puts " File " + path + " does not exist"
    end # status
  end # flags.each
end

#kill_packages(who) ⇒ Object

make_files



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/raxe/generator.rb', line 56

def kill_packages( who )
  # Step 1: Check existence
  flags = p_check_package_existence( who )
  
  # Step 2: Kill the ones who exist (if dir is empty)
  flags.each do |path, status|
    if status
      if Dir.entries( path ).length < 3
        Dir.delete( path ) 
        puts "  Deleted directory " + path 
      else # has stuff
        puts "  Directory " + path + " cannot be delete because it has stuff in it"
      end # if
    else # status
      puts " Directory " + path + " does not exist"
    end # status
  end # flags.each
end

#make_files(package, file) ⇒ Object

kill_files



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/raxe/generator.rb', line 36

def make_files( package, file )
  # Step 1 : Check existence
  flags = p_check_file_existence( package, file )
  
  # Step 1.5 : Generate file content
  contents = p_generate_file_content( package, file )
  
  # Step 2: Make the ones who do not exist
  flags.each do | path, status |
    if status
      puts " File " + path + " already exists..."
    else # status
      File.open( path, "w+" ) do |f|
        f.puts contents[path]
      end # File.open
      puts " Created file " + path
    end # if status
  end # flags each
end

#make_packages(who) ⇒ Object

kill_packages



75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/raxe/generator.rb', line 75

def make_packages( who )
  # Step 1: Check existence
  flags = p_check_package_existence( who )
  
  # Step 2: Create the ones who do not exist
  flags.each do | path, status |
    if status
      puts " Directory " + path + " already exists"
    else # status
      Dir.mkdir( path )
      puts " Created directory " + path
    end # status
  end # flags each
end