Class: MethodGenerator

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command) ⇒ MethodGenerator

Returns a new instance of MethodGenerator.



7
8
9
10
11
12
# File 'lib/ModelGenerator/MethodGenerator.rb', line 7

def initialize(command)
   @commandTask = command
   file_path="#{Dir.pwd}/#{command.entity_name}.m"
   @detector=Detector.new(file_path)
   @detector.detect_method
end

Instance Attribute Details

#commandTaskObject (readonly)

Returns the value of attribute commandTask.



5
6
7
# File 'lib/ModelGenerator/MethodGenerator.rb', line 5

def commandTask
  @commandTask
end

#detectorObject (readonly)

Returns the value of attribute detector.



4
5
6
# File 'lib/ModelGenerator/MethodGenerator.rb', line 4

def detector
  @detector
end

Instance Method Details

#generate_method(method_type, return_type, methond_name, method_content, has_custom_super_class) ⇒ Object



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
39
40
41
42
# File 'lib/ModelGenerator/MethodGenerator.rb', line 14

def generate_method(method_type,return_type,methond_name,method_content,has_custom_super_class)
   if return_type.downcase.include?("dictionary") && has_custom_super_class
      current_content= method_content.gsub(/return/,"NSDictionary *subDictionary=")
      method_content =%Q/NSMutableDictionary * content=[[super #{methond_name}] mutableCopy];
  #{current_content}
  [content addEntriesFromDictionary:subDictionary];
  return content;
                       /

   elsif return_type.downcase.include?("array") && has_custom_super_class
     current_content= method_content.gsub(/return/,"NSArray *subArray=")
     method_content =%Q/NSMutableArray * content=[[super #{methond_name}] mutableCopy];
   #{current_content}
   [content addObjectsFromArray:subArray];
   return content;
                      /

   end
   method_implement =  "#{method_type}(#{return_type})#{methond_name}\n{\n\t#{method_content}\n}\n"
   
   
   if !@commandTask.is_force_reset
     result= @detector.method_implment_same?(method_implement)
     return result ? result : method_implement
   end
   
   return method_implement
   
end