Class: ModelDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/translate2language.rb,
lib/translate2OC.rb,
lib/translate2java.rb

Overview

代码生成器

Direct Known Subclasses

JAVAModelDefinition, OCModelDefinition

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeModelDefinition

Returns a new instance of ModelDefinition.



39
40
41
# File 'lib/translate2language.rb', line 39

def initialize

end

Instance Attribute Details

#configHashObject

Returns the value of attribute configHash.



30
31
32
# File 'lib/translate2language.rb', line 30

def configHash
  @configHash
end

#contextObject (readonly)

Returns the value of attribute context.



57
58
59
# File 'lib/translate2language.rb', line 57

def context
  @context
end

Class Method Details

.getModelDefinition(modelType) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/translate2language.rb', line 31

def self.getModelDefinition(modelType)
    case modelType
    when "oc"
        modelDefinition = OCModelDefinition.new
    when "java"
        modelDefinition = JAVAModelDefinition.new
    end
end

Instance Method Details

#class_nameObject

类名



53
54
55
# File 'lib/translate2language.rb', line 53

def class_name
    context.class_name
end

#finishTranslateObject

结束转换



107
108
109
110
# File 'lib/translate2language.rb', line 107

def finishTranslate


end

#headerObject

头文件生成



43
44
45
46
# File 'lib/translate2language.rb', line 43

def header
    erb_template = ERB.new(header_template, nil, '-')
    erb_template.result(binding)
end

#header_templateObject

头文件模版



77
78
79
# File 'lib/translate2language.rb', line 77

def header_template
    
end

#implementationObject

实现文件生成



48
49
50
51
# File 'lib/translate2language.rb', line 48

def implementation
    erb_template = ERB.new(implementation_template, nil, '-')
    erb_template.result(binding)
end

#implementation_templateObject

实现文件模版



81
82
83
# File 'lib/translate2language.rb', line 81

def implementation_template

end

#processTranslateObject

处理转换



98
99
100
101
102
103
104
105
# File 'lib/translate2language.rb', line 98

def processTranslate
    @configHash.each do |key,value|
        setcontext(Context.new(key,value))
        finishTranslate
    end


end

#property_definition(readonly, args) ⇒ Object

属性模板



63
64
65
# File 'lib/translate2language.rb', line 63

def property_definition(readonly, args)
    
end

#property_type(property) ⇒ Object

属性类型模板



72
73
74
# File 'lib/translate2language.rb', line 72

def property_type(property)

end

#propterty_getterGenerator(args) ⇒ Object

属性访问器模版



67
68
69
# File 'lib/translate2language.rb', line 67

def propterty_getterGenerator(args)

end

#setcontext(context) ⇒ Object

生成器上下文



59
60
61
# File 'lib/translate2language.rb', line 59

def setcontext(context)
    @context = context
end

#startTranslate(jsonFilePath) ⇒ Object

开始转换



87
88
89
90
91
92
93
94
95
96
# File 'lib/translate2language.rb', line 87

def startTranslate(jsonFilePath)
    begin
        jsonData = File.read(jsonFilePath)
        jsonObj = JSON.parse(jsonData)
        @configHash = jsonObj
        processTranslate
    rescue
        puts("配置文件格式出错")
    end
end