Class: Prepare
- Inherits:
-
Object
- Object
- Prepare
- Defined in:
- lib/prepare.rb
Instance Method Summary collapse
- #generateNow(tpl, dest) ⇒ Object
-
#initialize(nameApp = "", generateTipo = "", modulo = "", opcoes = {}) ⇒ Prepare
constructor
A new instance of Prepare.
- #startGenerate ⇒ Object
- #testController ⇒ Object
- #testModel ⇒ Object
- #testView ⇒ Object
- #verifyArguments ⇒ Object
Constructor Details
#initialize(nameApp = "", generateTipo = "", modulo = "", opcoes = {}) ⇒ Prepare
Returns a new instance of Prepare.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/prepare.rb', line 92 def initialize (nameApp = "", generateTipo = "", modulo = "", opcoes = {}) @nameApp = nameApp @generateTipo = generateTipo @modulo = modulo @opcoes = opcoes @opts = {} @TEMPLATES_DIR = File.(File.join('ruby-extjs','templates'),File.dirname(__FILE__)) @PARAMS = Parametros.new(nameApp, generateTipo, modulo, opcoes, {}) if Dir.exists?("public") == false FileUtils.mkdir 'public', :mode => 0777 end if Dir.exists?("public/app") == false FileUtils.mkdir 'public/app', :mode => 0777 end end |
Instance Method Details
#generateNow(tpl, dest) ⇒ Object
189 190 191 192 193 194 |
# File 'lib/prepare.rb', line 189 def generateNow (tpl, dest) template = ERB.new File.new("#{tpl}").read File.open("#{dest}", 'w') do |f| f.write template.result(@PARAMS.get_binding) end end |
#startGenerate ⇒ Object
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/prepare.rb', line 196 def startGenerate if @generateTipo == "view" if Dir.exists?("public/app/view") == false FileUtils.mkdir 'public/app/view', :mode => 0777 end if Dir.exists?("public/app/view/#{@modulo.downcase}") == false FileUtils.mkdir "public/app/view/#{@modulo.downcase}", :mode => 0777 end self.generateNow("#{@TEMPLATES_DIR}/#{@generateTipo}/list.erb" , "public/app/#{@generateTipo}/#{@modulo.downcase}/List.js") self.generateNow("#{@TEMPLATES_DIR}/#{@generateTipo}/edit.erb" , "public/app/#{@generateTipo}/#{@modulo.downcase}/Edit.js") self.generateNow("#{@TEMPLATES_DIR}/#{@generateTipo}/filtro.erb" , "public/app/#{@generateTipo}/#{@modulo.downcase}/Filtro.js") elsif @generateTipo == "app" self.generateNow("#{@TEMPLATES_DIR}/app.erb" , "public/app.js") else if Dir.exists?("public/app/#{@generateTipo}") == false FileUtils.mkdir "public/app/#{@generateTipo}", :mode => 0777 end self.generateNow("#{@TEMPLATES_DIR}/#{@generateTipo}/#{@generateTipo}.erb", "public/app/#{@generateTipo}/#{@modulo.capitalize}.js") end if Dir.exists?("public/app/util") == false FileUtils.chmod 0777, "#{@TEMPLATES_DIR}/util/" FileUtils.mkdir "public/app/util", :mode => 0777 FileUtils.cp "#{@TEMPLATES_DIR}/util/", "public/app/util" end end |
#testController ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/prepare.rb', line 139 def testController if @opcoes != nil @Chave = false @DelRec = false @Combo = false @opcoes.each do |o,v| if o=='ch' @Chave = true elsif o=='cb' @Combo = true elsif o=='dr' @DelRec = true end end if @Chave==false puts '[ERROR-Controller] chave Nao informada....' elsif @Combo==false puts '[ERROR-Controller] combobox Nao informada....' elsif @Combo==false puts '[ERROR-Controller] deleteRecord Nao informada....' else return true end else puts '[ERROR] Options Incorreto...' end end |
#testModel ⇒ Object
169 170 171 172 173 174 175 176 177 |
# File 'lib/prepare.rb', line 169 def testModel if @opcoes != nil return true else puts '[ERROR-Model] Opcoes Incorreto...' end return false end |
#testView ⇒ Object
179 180 181 182 183 184 185 186 187 |
# File 'lib/prepare.rb', line 179 def testView if @opcoes != nil return true else puts '[ERROR-View] Opcoes Incorreto...' end return false end |
#verifyArguments ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/prepare.rb', line 110 def verifyArguments if @generateTipo === 'controller' if self.testController == true puts 'generate - Controller' self.startGenerate end elsif @generateTipo === 'model' if self.testModel == true puts 'generate - Model' self.startGenerate end elsif @generateTipo === 'store' if @modulo != nil puts 'generate - Store' self.startGenerate end elsif @generateTipo === 'view' if self.testView == true puts 'generate - View' self.startGenerate end elsif @generateTipo === 'app' puts 'generate - App' self.startGenerate else puts "[ERROR] - #{@generateTipo}" end end |