Class: DBGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/ModelGenerator/DBGenerator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command) ⇒ DBGenerator

Returns a new instance of DBGenerator.



9
10
11
12
13
14
15
# File 'lib/ModelGenerator/DBGenerator.rb', line 9

def initialize(command)
  @commandTask=command
  @method_generator=MethodGenerator.new(command)
  if !@commandTask.primary_key && @commandTask.flags.join.include?("d")
     raise "error : you must set table primary key"
  end
end

Instance Attribute Details

#commandTaskObject (readonly)

Returns the value of attribute commandTask.



7
8
9
# File 'lib/ModelGenerator/DBGenerator.rb', line 7

def commandTask
  @commandTask
end

Instance Method Details

#generate_primary_keyObject



48
49
50
51
52
53
54
55
56
# File 'lib/ModelGenerator/DBGenerator.rb', line 48

def generate_primary_key
  if @commandTask.flags.join.include?("d")
      has_super=@commandTask.parent_class
      primary_key = @commandTask.primary_key.slice(0,1).capitalize + @commandTask.primary_key.slice(1..-1)
      content =@method_generator.generate_method("+","NSString *","getPrimaryKey","return #{primary_key}TableKey;",has_super)
      return content
  end
  return ""
end

#generate_table_column_declareObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ModelGenerator/DBGenerator.rb', line 17

def generate_table_column_declare
  if @commandTask.flags.join.include?("d")
    db_column_mappings_content=""
    @commandTask.property_name_db_hash.keys.each do |name|
        column=@commandTask.property_name_db_hash[name]
        name = name.slice(0,1).capitalize + name.slice(1..-1)
        if(column)
          db_column_mappings_content << "static NSString * #{name}TableKey = @\"#{column}\";\n"
        end
    end
    if db_column_mappings_content.length > 0
        annotation = AnnotationGenerator.generate_single_annotation("table column declare")
        db_column_mappings_content = annotation + db_column_mappings_content
    end
    return db_column_mappings_content
  end
  
  return ""
end

#generate_table_mappingObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/ModelGenerator/DBGenerator.rb', line 58

def generate_table_mapping
  if @commandTask.flags.join.include?("d")
  
      hasDBColumn=false
      long_space="           "
      property_mapping_content="return @{\n"
       @commandTask.property_name_db_hash.each do |key , value|
           if value
             hasDBColumn=true
             cap_key = key.slice(0,1).capitalize + key.slice(1..-1)
             property_mapping_content << "#{long_space} @\"#{key}\":#{cap_key}TableKey,\n"
           end
       end

       property_mapping_content=property_mapping_content.chomp(",\n")
       property_mapping_content << "\n"
       property_mapping_content << "#{long_space}};"

       if hasDBColumn
         has_super=@commandTask.parent_class
         content =@method_generator.generate_method("+","NSDictionary *","getTableMapping",property_mapping_content,has_super)
         return content
       else
         return ""
       end
       
  end
  
  return ""
  
end

#generate_table_nameObject



37
38
39
40
41
42
43
44
45
46
# File 'lib/ModelGenerator/DBGenerator.rb', line 37

def generate_table_name
  if @commandTask.flags.join.include?("d")
      annotation = AnnotationGenerator.generate_mark_annotation("DB method")
      has_super=@commandTask.parent_class
      content =@method_generator.generate_method("+","NSString *","getTableName","return @\"tb_#{@commandTask.command[0].downcase}\";",has_super)
      return (annotation + content)
  end
  
  return ""
end