Class: POJOCLI::Pojo

Inherits:
Thor::Group
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/playmvc.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.getPackType(type) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/playmvc.rb', line 120

def self.getPackType(type)
  
  type_hash = {
    'char'       => 'Character',
    'byte'       => 'Byte',
    'short'      => 'Short',
    'int'        => 'Integer', 
    'long'       => 'Long', 
    'float'      => 'Float', 
    'double'     => 'Double',
    'boolean'    => 'Boolean'
    }

    return type_hash[type] if(type_hash.has_key? type)
    type

end

.source_rootObject



15
16
17
# File 'lib/playmvc.rb', line 15

def self.source_root
  File.dirname(__FILE__)
end

Instance Method Details

#add_routeObject



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/playmvc.rb', line 97

def add_route
  if(options[:action].length > 0)
    routes = ["\n# #{name}"]
    options[:action].each do |a|
      p_array = []
      ap = a.split(',')
      actionName = ap.shift
      action = packgePath("controllers") + "." + name.capitalize + 'Controller.' +  actionName + "("
      action += ap.join(", ").gsub(/\:(\w)+/){|s| 
        ":" + POJOCLI::Pojo.getPackType(s[1..-1]) 
      } if ap.length > 0
      action += ")"
      
      route = "/" + name+"/" + actionName
      route = "/" + options[:namespace].gsub(/\./, "\/") + "/" + name + "/" +actionName if(options[:namespace])
      
      routes.push("GET     #{route}         #{action}")
    end
    append_to_file "conf/routes", routes.join("\n");
  end  
end

#create_controller_fileObject



69
70
71
72
73
74
# File 'lib/playmvc.rb', line 69

def create_controller_file
  if(options[:action].length > 0)
    path = folderPath("app/controllers") + "/#{name.capitalize}Controller.java"
    template('templates/controller.erb', path)
  end    
end

#create_helper_fileObject



76
77
78
79
80
81
82
# File 'lib/playmvc.rb', line 76

def create_helper_file
  
  if(options[:action].length > 0)
    path = folderPath("app/helpers") + "/#{name.capitalize}Helper.java"
    template('templates/helper.erb', path)
  end  
end

#create_model_fileObject



62
63
64
65
66
67
# File 'lib/playmvc.rb', line 62

def create_model_file
  #path = "models/"
  #path += options[:namespace].gsub(/\./, "\/") if(options[:namespace])
  path = folderPath("app/models") + "/#{name.capitalize}ViewModel.java"
  template('templates/model.erb', path)
end

#create_view_fileObject



84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/playmvc.rb', line 84

def create_view_file
  
  path = folderPath("app/views") + "/"
  
  if(options[:action].length > 0)
    options[:action].each do |a|
      actionname = a.split(',').first
      #create_file(path + actionname + ".scala.html")
      template('templates/view.erb', path + actionname + ".scala.html")
    end
  end
end

#exist_play_projectObject



19
20
21
22
23
24
25
# File 'lib/playmvc.rb', line 19

def exist_play_project
  
  if(!File.exist?(File.expand_path("conf/application.conf")))
    puts "Can't auto generate code without in  the directory of play project's root directory, please change to a play project 's root directory first.\n"
    raise Error, "This command must be run in a play project's root direcotry!!"
  end
end

#parse_argument_optionObject

Raises:

  • (ArgumentError)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/playmvc.rb', line 28

def parse_argument_option
  
  errors = [];
  
  #parseName
  name_reg = /^[a-z]+[_a-zA-Z0-9]*$/
  errors.push("NAME is not valid!  #{name}") if(!name.match name_reg )
  
  #property
  property_reg = /^[a-z]+[_a-zA-Z0-9]*\:[a-zA-Z]+[_a-zA-Z0-9]*$/
  properties.each do | property |
    errors.push("Property is not valid!  #{property}") if(!property.match property_reg)
  end
  
  #package
  pkg_reg = /^[a-zA-Z]+[_a-zA-Z0-9]+(\.[a-z][_a-zA-Z0-9]+)*$/
  errors.push("Property is not valid!  #{property}") if(!options[:namespace].match pkg_reg) if(options[:namespace])
  
  #super class
  super_reg = /^[A-Z]+[_a-zA-Z0-9]*$/
  errors.push("Property is not valid!  #{property}") if(!options[:super].match super_reg ) if(options[:super])
  
  #actions
  action_reg = /^[a-z]+[_a-zA-Z0-9]*(\,[a-z]+[_a-zA-Z0-9]*:[a-zA-Z]+[_a-zA-Z0-9])*$/
  if(options[:action].length > 0)
    options[:action].each do | a |
      errors.push() if(!a.match action_reg)
    end
  end
  
  raise ArgumentError, errors.join("\n") if errors.length > 0 
  
end