zandu 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/zandu.rb +78 -5
- metadata +1 -1
data/lib/zandu.rb
CHANGED
@@ -1,6 +1,79 @@
|
|
1
|
-
class MyZanduGenerator < Rails::Generators::NamedBase
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
# class MyZanduGenerator < Rails::Generators::NamedBase
|
2
|
+
# def add_my_crazy_routes
|
3
|
+
# my_route = "match '/news', :to => 'bar_controller#foo_action'"
|
4
|
+
# route my_route
|
5
|
+
# end
|
6
|
+
# end
|
7
|
+
|
8
|
+
#require "net/http"
|
9
|
+
|
10
|
+
# class MyZanduGenerator
|
11
|
+
|
12
|
+
# @data_tables = ActiveRecord::Base.connection.tables
|
13
|
+
# @posts = Post.all
|
14
|
+
# puts @posts.inspect
|
15
|
+
|
16
|
+
|
17
|
+
# end
|
18
|
+
|
19
|
+
class ZanduInsertion
|
20
|
+
|
21
|
+
# File.open("app/controllers/dbs_controller.rb","w") do |f|
|
22
|
+
# f.puts "class DbsController < ApplicationController"
|
23
|
+
# f.puts
|
24
|
+
# f.puts " def show"
|
25
|
+
# f.puts
|
26
|
+
# f.puts ' puts "Hello"'
|
27
|
+
# f.puts ' @name = params[:id]'
|
28
|
+
# f.puts ' @model_name = @name.camelize'
|
29
|
+
# f.puts ' puts @model_name'
|
30
|
+
# f.puts ' @content = eval(@model_name).all'
|
31
|
+
# f.puts ' puts @content.inspect'
|
32
|
+
# f.puts
|
33
|
+
# f.puts ' respond_to do |format|'
|
34
|
+
# f.puts ' format.html # show.html.erb'
|
35
|
+
# f.puts ' format.json { render json: @content }'
|
36
|
+
# f.puts ' end'
|
37
|
+
# f.puts
|
38
|
+
# f.puts " end"
|
39
|
+
# f.puts
|
40
|
+
# f.puts "end"
|
41
|
+
# end
|
42
|
+
|
43
|
+
File.new("app/controllers/dbs_controller.rb")
|
44
|
+
#File.open("app/controllers/dbs_controller.rb","w") do |f|
|
45
|
+
|
46
|
+
srcFile = File.dirname(__FILE__) + "/tamplates/dbs_controller.rb"
|
47
|
+
src = File.open(srcFile)
|
48
|
+
dest = File.open("app/controllers/dbs_controller.rb", "w")
|
49
|
+
IO.copy_stream(src, dest)
|
50
|
+
|
51
|
+
#end
|
52
|
+
|
53
|
+
File.open( 'config/routes.rb' ) do |io|
|
54
|
+
io.each {
|
55
|
+
|line| line.chomp! ;
|
56
|
+
io.each {|line| line.chomp! ; @present = true if line.include? 'resources :dbs'}
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
60
|
+
File.open('config/routes.rb','r+') do |f|
|
61
|
+
|
62
|
+
if !@present
|
63
|
+
#f.rewind
|
64
|
+
at_line = 2
|
65
|
+
|
66
|
+
while (at_line-=1) > 0 # read up to the line you want to write after
|
67
|
+
f.readline
|
68
|
+
end
|
69
|
+
|
70
|
+
pos = f.pos # save your position in the file
|
71
|
+
rest = f.read # save the rest of the file
|
72
|
+
f.seek pos # go back to the old position
|
73
|
+
f.puts 'resources :dbs'
|
74
|
+
f.puts rest # write new data & rest of file
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
6
79
|
end
|