maml 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +2 -0
- data/bin/maml +5 -0
- data/init.rb +6 -1
- data/lib/maml.rb +108 -27
- data/maml.gemspec +13 -3
- metadata +11 -3
- data/maml +0 -1
data/LICENSE
CHANGED
data/bin/maml
ADDED
data/init.rb
CHANGED
data/lib/maml.rb
CHANGED
@@ -6,6 +6,7 @@
|
|
6
6
|
# todo: switch all puts to logger
|
7
7
|
# todo: remove some excess logging
|
8
8
|
# todo: create a gem
|
9
|
+
# todo:
|
9
10
|
require "yaml"
|
10
11
|
require "logger"
|
11
12
|
|
@@ -41,61 +42,103 @@ def extract_arg maml_field
|
|
41
42
|
|
42
43
|
$logger.info this_method + "=> maml_field=#{maml_field}"
|
43
44
|
type=case maml_field
|
44
|
-
when /^::(\w*)\b/; "text"
|
45
|
-
when /^:(\w*)\b/; "string"
|
46
|
-
when /^\.\.(\w*)\b/; "float"
|
47
|
-
when /^\.(\w*)\b/; "integer"
|
48
|
-
when /(\w*_id)\b/; "integer"
|
49
|
-
when /^=(\w*)\b/; "boolean"
|
50
|
-
when /^%%(\w*)\b/; "datetime"
|
51
|
-
when /^%(\w*)\b/; "date"
|
52
|
-
when /^@@(\w*)\b/; "timestamp"
|
53
|
-
when /^@(\w*)\b/; "time"
|
54
|
-
when /^&(\w*)\b/; "binary"
|
55
|
-
when /(\w*)\b/; "string"
|
45
|
+
when /^::(\w*)\b[,]?(.*)/; "text"
|
46
|
+
when /^:(\w*)\b[,]?(.*)/; "string"
|
47
|
+
when /^\.\.(\w*)\b[,]?(.*)/; "float"
|
48
|
+
when /^\.(\w*)\b[,]?(.*)/; "integer"
|
49
|
+
when /(\w*_id)\b[,]?(.*)/; "integer"
|
50
|
+
when /^=(\w*)\b[,]?(.*)/; "boolean"
|
51
|
+
when /^%%(\w*)\b[,]?(.*)/; "datetime"
|
52
|
+
when /^%(\w*)\b[,]?(.*)/; "date"
|
53
|
+
when /^@@(\w*)\b[,]?(.*)/; "timestamp"
|
54
|
+
when /^@(\w*)\b[,]?(.*)/; "time"
|
55
|
+
when /^&(\w*)\b[,]?(.*)/; "binary"
|
56
|
+
when /(\w*)\b[,]?(.*)/; "string"
|
56
57
|
else raise "Invalid field type";
|
57
58
|
end
|
58
59
|
field=Regexp.last_match(1)
|
60
|
+
options=Regexp.last_match(2)
|
59
61
|
maml_arg= "#{field}:#{type}"
|
62
|
+
maml_options= "#{options}"
|
63
|
+
return maml_arg, maml_options
|
60
64
|
end
|
61
65
|
|
62
66
|
# build script/generate model arguments from yaml info
|
63
67
|
def build_model_args maml
|
64
68
|
model_args={}
|
69
|
+
model_options={}
|
65
70
|
maml.each do |app|
|
66
71
|
puts "\napplication:#{app[0]}"
|
67
72
|
print "models: "
|
68
73
|
app[1].each do |model|
|
69
74
|
current_model_args=[]
|
75
|
+
current_model_options=[]
|
70
76
|
model_name=model[0]
|
71
77
|
print "#{model_name} "
|
72
78
|
model[1].each do |field|
|
73
|
-
arg=extract_arg field
|
74
|
-
$logger.debug "Extract #{field} ===> #{arg}"
|
79
|
+
arg, options=extract_arg field
|
80
|
+
$logger.debug "Extract Arg #{field} ===> #{arg}"
|
81
|
+
$logger.debug "Extract Options #{field} ===> #{options}"
|
75
82
|
current_model_args << arg
|
83
|
+
field_name, field_type=arg.split(":")
|
84
|
+
puts "field_name=#{field_name}, field_type=#{field_type}"
|
85
|
+
current_model_options << [field_name, options]
|
76
86
|
end
|
77
87
|
model_args[model_name]=current_model_args
|
88
|
+
model_options[model_name]=current_model_options
|
78
89
|
end
|
79
90
|
puts
|
80
91
|
end
|
81
|
-
model_args
|
92
|
+
return model_args, model_options
|
82
93
|
end
|
83
94
|
|
84
95
|
# todo: add support for multiple files
|
85
96
|
# todo: add generate command override options to maml.yml for model specific generations.
|
86
97
|
def process_args args
|
87
|
-
|
98
|
+
file, go=nil
|
99
|
+
generate_command=[]
|
88
100
|
|
89
101
|
args.each do |arg|
|
90
|
-
if arg[0,1] == "-" then
|
91
|
-
|
102
|
+
if arg[0,1] == "-" then
|
103
|
+
command=arg[1,arg.length]
|
104
|
+
if command == "go"
|
105
|
+
go=true
|
106
|
+
else
|
107
|
+
generate_command << command
|
108
|
+
end
|
92
109
|
else
|
93
110
|
file=arg
|
94
111
|
end
|
95
112
|
end
|
96
|
-
|
113
|
+
if generate_command.empty?
|
114
|
+
generate_command=nil
|
115
|
+
else
|
116
|
+
generate_command = generate_command.join(" ")
|
117
|
+
end
|
118
|
+
puts "**** generate_command=#{generate_command}"
|
119
|
+
return generate_command,file, go
|
97
120
|
end
|
98
121
|
|
122
|
+
def post_process_migrations model, result
|
123
|
+
model_name=model[0]
|
124
|
+
puts "model_name: #{model_name}"
|
125
|
+
model_fields=model[1] # join(" ") to create args for generator ..e.g. fieldname1:string fieldname2:integer
|
126
|
+
|
127
|
+
# create app/models/user_group.rb
|
128
|
+
model_file_regex="create app/models/(.*).rb"
|
129
|
+
# model_file_name=user_group
|
130
|
+
|
131
|
+
# 20090731211953_create_user_groups.rb
|
132
|
+
# find migration with same but plural
|
133
|
+
# migration_file=
|
134
|
+
|
135
|
+
# open file
|
136
|
+
# find text field
|
137
|
+
# append options
|
138
|
+
#
|
139
|
+
end
|
140
|
+
|
141
|
+
|
99
142
|
# main function
|
100
143
|
def main
|
101
144
|
puts "\nMAML=Migration Apathy Markup Language"
|
@@ -115,7 +158,7 @@ def main
|
|
115
158
|
puts "------------------------------------------------------------------------\n"
|
116
159
|
puts ""
|
117
160
|
|
118
|
-
generate_command, file = process_args ARGV
|
161
|
+
generate_command, file, go = process_args ARGV
|
119
162
|
$logger.info "\ngenerate_command=#{generate_command}, file=#{file}"
|
120
163
|
@file_provided=true if file
|
121
164
|
$logger.info "@file_provided=#{@file_provided}"
|
@@ -124,9 +167,17 @@ def main
|
|
124
167
|
generate_command="model" unless generate_command
|
125
168
|
puts "generate_command=#{generate_command}, file=#{file}"
|
126
169
|
|
127
|
-
maml=
|
128
|
-
|
129
|
-
|
170
|
+
maml=nil
|
171
|
+
begin
|
172
|
+
maml=YAML::load(File.open(file))
|
173
|
+
$logger.info "YAML loaded file"
|
174
|
+
rescue
|
175
|
+
$logger.debug "Unable to load #{file}"
|
176
|
+
puts "Unable to load file #{file}"
|
177
|
+
exit
|
178
|
+
end
|
179
|
+
|
180
|
+
model_args, model_options = build_model_args maml
|
130
181
|
|
131
182
|
puts
|
132
183
|
|
@@ -136,14 +187,44 @@ def main
|
|
136
187
|
puts "model_name: #{model_name}"
|
137
188
|
model_fields=model[1].join " "
|
138
189
|
# File.open("maml.log", "a") { |file| file.write "---- model: #{model_name} (#{model_fields}) ---\n\n" }
|
139
|
-
File.open("maml.log", "a") { |file| file.write
|
140
|
-
|
190
|
+
# File.open("maml.log", "a") { |file| file.write
|
191
|
+
$logger.info "---- model: #{model_name} \n\t\t\t#{model_fields.split(" ").join("\n\t\t\t")}\n---\n\n"
|
192
|
+
# command="ruby script/generate #{generate_command} #{model_name} #{model_fields} >> maml.log"
|
193
|
+
command="ruby script/generate #{generate_command} #{model_name} #{model_fields}"
|
141
194
|
puts "command: #{command}\n\n"
|
142
195
|
if @file_provided == true
|
143
|
-
|
144
|
-
|
196
|
+
if go
|
197
|
+
puts "=== calling system command ==="
|
198
|
+
result=%x[#{command}]
|
199
|
+
puts "RESULT ====>\n #{result}"
|
200
|
+
post_process_migrations model, result
|
201
|
+
|
202
|
+
$logger.info "\n\n#{result}\n\n"
|
203
|
+
else
|
204
|
+
puts "=== trial run...run with '-go' to generated files ==="
|
205
|
+
end
|
206
|
+
else
|
207
|
+
puts "=== no file provided ==="
|
145
208
|
end
|
146
209
|
end
|
210
|
+
|
211
|
+
model_options.each do |model|
|
212
|
+
model_name=model[0]
|
213
|
+
puts "options model_name: #{model_name}"
|
214
|
+
|
215
|
+
model[1].each do |options|
|
216
|
+
field_name=options[0]
|
217
|
+
option_list=options[1]
|
218
|
+
options_list_message=""
|
219
|
+
if option_list !=nil && option_list.size > 0
|
220
|
+
options_list_message="| options => #{option_list}"
|
221
|
+
end
|
222
|
+
puts "options logic: field_name=#{field_name} #{options_list_message}"
|
223
|
+
end
|
224
|
+
end
|
225
|
+
# todo: parse generated migrations and add options
|
226
|
+
# todo: add index logic
|
227
|
+
|
147
228
|
puts "\n\nDONE! Look at maml.log for script results, and in app/models, db/migrations, test/fixtures and test/unit for generated code (if you ran maml.rb with a command line arg)"
|
148
229
|
unless ARGV[0]
|
149
230
|
puts "\n\nUse 'maml.rb maml.yml' (or other file arg) to actuallly run generators. Running with default maml.yml does test run only."
|
data/maml.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{maml}
|
5
|
-
s.version = "0.1.
|
5
|
+
s.version = "0.1.2"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Nick Van Weerdenburg"]
|
@@ -10,13 +10,23 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.description = %q{Modeling Apathy Markup Language}
|
11
11
|
s.email = %q{nick@gmail.com}
|
12
12
|
s.extra_rdoc_files = ["CHANGELOG", "lib/maml.rb", "LICENSE", "README.rdoc"]
|
13
|
-
s.files = ["CHANGELOG", "gem_notes", "init.rb", "lib/maml.rb", "LICENSE", "maml
|
13
|
+
s.files = ["CHANGELOG", "gem_notes", "init.rb", "bin/maml", "lib/maml.rb", "LICENSE", "maml.gemspec", "maml.yml", "maml_spec.txt", "Manifest", "Rakefile", "README.rdoc"]
|
14
14
|
s.has_rdoc = true
|
15
15
|
s.homepage = %q{http://github.com/vanweerd/maml}
|
16
|
+
|
17
|
+
s.post_install_message = %q{**************************************************
|
18
|
+
|
19
|
+
Thank you for installing maml-0.1.1
|
20
|
+
|
21
|
+
Run "maml" by itself on the command line for documentation.
|
22
|
+
|
23
|
+
**************************************************
|
24
|
+
}
|
25
|
+
|
16
26
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Maml", "--main", "README.rdoc"]
|
17
27
|
s.require_paths = ["lib"]
|
18
28
|
s.rubyforge_project = %q{maml}
|
19
|
-
s.rubygems_version = %q{1.3.
|
29
|
+
s.rubygems_version = %q{1.3.5}
|
20
30
|
s.summary = %q{Modeling Apathy Markup Language}
|
21
31
|
|
22
32
|
if s.respond_to? :specification_version then
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: maml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Van Weerdenburg
|
@@ -28,9 +28,9 @@ files:
|
|
28
28
|
- CHANGELOG
|
29
29
|
- gem_notes
|
30
30
|
- init.rb
|
31
|
+
- bin/maml
|
31
32
|
- lib/maml.rb
|
32
33
|
- LICENSE
|
33
|
-
- maml
|
34
34
|
- maml.gemspec
|
35
35
|
- maml.yml
|
36
36
|
- maml_spec.txt
|
@@ -41,7 +41,15 @@ has_rdoc: true
|
|
41
41
|
homepage: http://github.com/vanweerd/maml
|
42
42
|
licenses: []
|
43
43
|
|
44
|
-
post_install_message:
|
44
|
+
post_install_message: |
|
45
|
+
**************************************************
|
46
|
+
|
47
|
+
Thank you for installing maml-0.1.1
|
48
|
+
|
49
|
+
Run "maml" by itself on the command line for documentation.
|
50
|
+
|
51
|
+
**************************************************
|
52
|
+
|
45
53
|
rdoc_options:
|
46
54
|
- --line-numbers
|
47
55
|
- --inline-source
|