maml 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/lib/maml/maml.rb +188 -185
  3. data/maml.gemspec +1 -1
  4. metadata +1 -1
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.1.5
@@ -10,17 +10,7 @@
10
10
  require "yaml"
11
11
  require "logger"
12
12
 
13
- # I love logging
14
- $logger=Logger.new('maml.log')
15
- $logger.level=Logger::INFO
16
- $logger.info "PLATFORM=#{PLATFORM}"
17
-
18
- # look user and project configuration file
19
- user_config_file=ENV['HOME'] + "/.mamlrc"
20
- project_config_file=".mamlrc"
21
- $logger.info("user .mamlrc #{File.exist? user_config_file ? 'found' : 'not found'}")
22
- $logger.info("project .mamlrc #{File.exist? project_config_file ? 'found' : 'not found'}")
23
-
13
+ # mechanism to get current method name..don't really need for current implementation..was for writing handlers that could write their own name
24
14
  module CurrentMethodName
25
15
  def this_method
26
16
  caller[0]=~/`(.*?)'/
@@ -30,215 +20,228 @@ end
30
20
 
31
21
  include CurrentMethodName
32
22
 
33
- # simple test fixture
34
- def test
35
- string_arg
36
- end
23
+ module Maml
24
+ $logger=Logger.new('maml.log')
25
+ $logger.level=Logger::INFO
26
+ $logger.info "PLATFORM=#{PLATFORM}"
37
27
 
38
- def extract_arg maml_field
39
- maml_arg=nil
40
- field=nil
41
- type=nil
28
+ # look user and project configuration file
29
+ user_config_file=ENV['HOME'] + "/.mamlrc"
30
+ project_config_file=".mamlrc"
31
+ $logger.info("user .mamlrc #{File.exist? user_config_file ? 'found' : 'not found'}")
32
+ $logger.info("project .mamlrc #{File.exist? project_config_file ? 'found' : 'not found'}")
33
+
34
+ module_function
35
+
36
+ # simple test fixture
37
+ def test
38
+ string_arg
39
+ end
40
+
41
+ def extract_arg maml_field
42
+ maml_arg=nil
43
+ field=nil
44
+ type=nil
42
45
 
43
- $logger.info this_method + "=> maml_field=#{maml_field}"
44
- type=case maml_field
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"
57
- else raise "Invalid field type";
58
- end
59
- field=Regexp.last_match(1)
60
- options=Regexp.last_match(2)
61
- maml_arg= "#{field}:#{type}"
62
- maml_options= "#{options}"
63
- return maml_arg, maml_options
64
- end
46
+ $logger.info this_method + "=> maml_field=#{maml_field}"
47
+ type=case maml_field
48
+ when /^::(\w*)\b[,]?(.*)/; "text"
49
+ when /^:(\w*)\b[,]?(.*)/; "string"
50
+ when /^\.\.(\w*)\b[,]?(.*)/; "float"
51
+ when /^\.(\w*)\b[,]?(.*)/; "integer"
52
+ when /(\w*_id)\b[,]?(.*)/; "integer"
53
+ when /^=(\w*)\b[,]?(.*)/; "boolean"
54
+ when /^%%(\w*)\b[,]?(.*)/; "datetime"
55
+ when /^%(\w*)\b[,]?(.*)/; "date"
56
+ when /^@@(\w*)\b[,]?(.*)/; "timestamp"
57
+ when /^@(\w*)\b[,]?(.*)/; "time"
58
+ when /^&(\w*)\b[,]?(.*)/; "binary"
59
+ when /(\w*)\b[,]?(.*)/; "string"
60
+ else raise "Invalid field type";
61
+ end
62
+ field=Regexp.last_match(1)
63
+ options=Regexp.last_match(2)
64
+ maml_arg= "#{field}:#{type}"
65
+ maml_options= "#{options}"
66
+ return maml_arg, maml_options
67
+ end
65
68
 
66
- # build script/generate model arguments from yaml info
67
- def build_model_args maml
68
- model_args={}
69
- model_options={}
70
- maml.each do |app|
71
- puts "\napplication:#{app[0]}"
72
- print "models: "
73
- app[1].each do |model|
74
- current_model_args=[]
75
- current_model_options=[]
76
- model_name=model[0]
77
- print "#{model_name} "
78
- model[1].each do |field|
79
- arg, options=extract_arg field
80
- $logger.debug "Extract Arg #{field} ===> #{arg}"
81
- $logger.debug "Extract Options #{field} ===> #{options}"
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]
69
+ # build script/generate model arguments from yaml info
70
+ def build_model_args maml
71
+ model_args={}
72
+ model_options={}
73
+ maml.each do |app|
74
+ puts "\napplication:#{app[0]}"
75
+ print "models: "
76
+ app[1].each do |model|
77
+ current_model_args=[]
78
+ current_model_options=[]
79
+ model_name=model[0]
80
+ print "#{model_name} "
81
+ model[1].each do |field|
82
+ arg, options=extract_arg field
83
+ $logger.debug "Extract Arg #{field} ===> #{arg}"
84
+ $logger.debug "Extract Options #{field} ===> #{options}"
85
+ current_model_args << arg
86
+ field_name, field_type=arg.split(":")
87
+ puts "field_name=#{field_name}, field_type=#{field_type}"
88
+ current_model_options << [field_name, options]
89
+ end
90
+ model_args[model_name]=current_model_args
91
+ model_options[model_name]=current_model_options
86
92
  end
87
- model_args[model_name]=current_model_args
88
- model_options[model_name]=current_model_options
93
+ puts
89
94
  end
90
- puts
95
+ return model_args, model_options
91
96
  end
92
- return model_args, model_options
93
- end
94
97
 
95
- # todo: add support for multiple files
96
- # todo: add generate command override options to maml.yml for model specific generations.
97
- def process_args args
98
- file, go=nil
99
- generate_command=[]
98
+ # todo: add support for multiple files
99
+ # todo: add generate command override options to maml.yml for model specific generations.
100
+ def process_args args
101
+ file, go=nil
102
+ generate_command=[]
100
103
 
101
- args.each do |arg|
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
104
+ args.each do |arg|
105
+ if arg[0,1] == "-" then
106
+ command=arg[1,arg.length]
107
+ if command == "go"
108
+ go=true
109
+ else
110
+ generate_command << command
111
+ end
112
+ else
113
+ file=arg
114
+ end
115
+ end
116
+ if generate_command.empty?
117
+ generate_command=nil
109
118
  else
110
- file=arg
119
+ generate_command = generate_command.join(" ")
111
120
  end
121
+ puts "**** generate_command=#{generate_command}"
122
+ return generate_command,file, go
112
123
  end
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
120
- end
121
124
 
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
125
+ def post_process_migrations model, result
126
+ model_name=model[0]
127
+ puts "model_name: #{model_name}"
128
+ model_fields=model[1] # join(" ") to create args for generator ..e.g. fieldname1:string fieldname2:integer
126
129
 
127
- # create app/models/user_group.rb
128
- model_file_regex="create app/models/(.*).rb"
129
- # model_file_name=user_group
130
+ # create app/models/user_group.rb
131
+ model_file_regex="create app/models/(.*).rb"
132
+ # model_file_name=user_group
130
133
 
131
- # 20090731211953_create_user_groups.rb
132
- # find migration with same but plural
133
- # migration_file=
134
+ # 20090731211953_create_user_groups.rb
135
+ # find migration with same but plural
136
+ # migration_file=
134
137
 
135
- # open file
136
- # find text field
137
- # append options
138
- #
139
- end
138
+ # open file
139
+ # find text field
140
+ # append options
141
+ #
142
+ end
140
143
 
141
144
 
142
- # main function
143
- def main
144
- puts "\nMAML=Migration Apathy Markup Language"
145
- puts "======================================"
146
- puts "Visit http://lazymaml.org for more details"
147
- puts "Copyright 2009 Zigelo and Nick Van Weerdenburg, Licensed under MIT License\n\n"
148
- puts "usage: maml.rb <filename> [-generate_command]"
149
- puts "runs trial by default, add -go for rails generation"
150
- puts "e.g. maml.rb blog.yml -scaffold"
151
- puts "OR"
152
- puts "e.g. maml.rb blog.yml -scaffold -go"
153
- puts "OR"
154
- puts "usage: maml.rb"
155
- puts "(defaults to 'maml.yml' file and generating the model)\n\n"
156
- puts "use ---haml or similar for adding extra commands. -<anything> is passed to the command-line minus the -"
157
- puts "maml supports one file at time"
158
- puts "generated files are in <rails_root>/maml"
159
- puts "\nSpecify field type by symbol prefix as follows:"
160
- puts "no prefix=string ; no prefix and _id suffix = integer ; override _id by adding prefix"
161
- puts "examples: string, integer_id, .integer, ..float, %date, %%datetime, @time, @@timestamp, :string, ::text, =boolean, &binary"
162
- puts "------------------------------------------------------------------------\n"
163
- puts ""
145
+ # main function
146
+ def main
147
+ puts "\nMAML=Migration Apathy Markup Language"
148
+ puts "======================================"
149
+ puts "Visit http://lazymaml.org for more details"
150
+ puts "Copyright 2009 Zigelo and Nick Van Weerdenburg, Licensed under MIT License\n\n"
151
+ puts "usage: maml.rb <filename> [-generate_command]"
152
+ puts "runs trial by default, add -go for rails generation"
153
+ puts "e.g. maml.rb blog.yml -scaffold"
154
+ puts "OR"
155
+ puts "e.g. maml.rb blog.yml -scaffold -go"
156
+ puts "OR"
157
+ puts "usage: maml.rb"
158
+ puts "(defaults to 'maml.yml' file and generating the model)\n\n"
159
+ puts "use ---haml or similar for adding extra commands. -<anything> is passed to the command-line minus the -"
160
+ puts "maml supports one file at time"
161
+ puts "generated files are in <rails_root>/maml"
162
+ puts "\nSpecify field type by symbol prefix as follows:"
163
+ puts "no prefix=string ; no prefix and _id suffix = integer ; override _id by adding prefix"
164
+ puts "examples: string, integer_id, .integer, ..float, %date, %%datetime, @time, @@timestamp, :string, ::text, =boolean, &binary"
165
+ puts "------------------------------------------------------------------------\n"
166
+ puts ""
164
167
 
165
- generate_command, file, go = process_args ARGV
166
- $logger.info "\ngenerate_command=#{generate_command}, file=#{file}"
167
- @file_provided=true if file
168
- $logger.info "@file_provided=#{@file_provided}"
168
+ generate_command, file, go = process_args ARGV
169
+ $logger.info "\ngenerate_command=#{generate_command}, file=#{file}"
170
+ @file_provided=true if file
171
+ $logger.info "@file_provided=#{@file_provided}"
169
172
 
170
- file="maml.yml" unless file
171
- generate_command="model" unless generate_command
172
- puts "generate_command=#{generate_command}, file=#{file}"
173
+ file="maml.yml" unless file
174
+ generate_command="model" unless generate_command
175
+ puts "generate_command=#{generate_command}, file=#{file}"
173
176
 
174
- maml=nil
175
- begin
176
- maml=YAML::load(File.open(file))
177
- $logger.info "YAML loaded file"
178
- rescue
179
- $logger.debug "Unable to load #{file}"
180
- puts "Unable to load file #{file}"
181
- exit
182
- end
177
+ maml=nil
178
+ begin
179
+ maml=YAML::load(File.open(file))
180
+ $logger.info "YAML loaded file"
181
+ rescue
182
+ $logger.debug "Unable to load #{file}"
183
+ puts "Unable to load file #{file}"
184
+ exit
185
+ end
183
186
 
184
- model_args, model_options = build_model_args maml
187
+ model_args, model_options = build_model_args maml
185
188
 
186
- puts
189
+ puts
187
190
 
188
- # now execute each model
189
- model_args.each do |model|
190
- model_name=model[0]
191
- puts "model_name: #{model_name}"
192
- model_fields=model[1].join " "
193
- # File.open("maml.log", "a") { |file| file.write "---- model: #{model_name} (#{model_fields}) ---\n\n" }
194
- # File.open("maml.log", "a") { |file| file.write
195
- $logger.info "---- model: #{model_name} \n\t\t\t#{model_fields.split(" ").join("\n\t\t\t")}\n---\n\n"
196
- # command="ruby script/generate #{generate_command} #{model_name} #{model_fields} >> maml.log"
197
- command="ruby script/generate #{generate_command} #{model_name} #{model_fields}"
198
- puts "command: #{command}\n\n"
199
- if @file_provided == true
200
- if go
201
- puts "=== calling system command ==="
202
- result=%x[#{command}]
203
- puts "RESULT ====>\n #{result}"
204
- post_process_migrations model, result
191
+ # now execute each model
192
+ model_args.each do |model|
193
+ model_name=model[0]
194
+ puts "model_name: #{model_name}"
195
+ model_fields=model[1].join " "
196
+ # File.open("maml.log", "a") { |file| file.write "---- model: #{model_name} (#{model_fields}) ---\n\n" }
197
+ # File.open("maml.log", "a") { |file| file.write
198
+ $logger.info "---- model: #{model_name} \n\t\t\t#{model_fields.split(" ").join("\n\t\t\t")}\n---\n\n"
199
+ # command="ruby script/generate #{generate_command} #{model_name} #{model_fields} >> maml.log"
200
+ command="ruby script/generate #{generate_command} #{model_name} #{model_fields}"
201
+ puts "command: #{command}\n\n"
202
+ if @file_provided == true
203
+ if go
204
+ puts "=== calling system command ==="
205
+ result=%x[#{command}]
206
+ puts "RESULT ====>\n #{result}"
207
+ post_process_migrations model, result
205
208
 
206
- $logger.info "\n\n#{result}\n\n"
209
+ $logger.info "\n\n#{result}\n\n"
210
+ else
211
+ puts "=== trial run...run with '-go' to generated files ==="
212
+ end
207
213
  else
208
- puts "=== trial run...run with '-go' to generated files ==="
209
- end
210
- else
211
- puts "=== no file provided ==="
212
- end
213
- end
214
+ puts "=== no file provided ==="
215
+ end
216
+ end
214
217
 
215
- model_options.each do |model|
216
- model_name=model[0]
217
- puts "options model_name: #{model_name}"
218
+ model_options.each do |model|
219
+ model_name=model[0]
220
+ puts "options model_name: #{model_name}"
218
221
 
219
- model[1].each do |options|
220
- field_name=options[0]
221
- option_list=options[1]
222
- options_list_message=""
223
- if option_list !=nil && option_list.size > 0
224
- options_list_message="| options => #{option_list}"
222
+ model[1].each do |options|
223
+ field_name=options[0]
224
+ option_list=options[1]
225
+ options_list_message=""
226
+ if option_list !=nil && option_list.size > 0
227
+ options_list_message="| options => #{option_list}"
228
+ end
229
+ puts "options logic: field_name=#{field_name} #{options_list_message}"
225
230
  end
226
- puts "options logic: field_name=#{field_name} #{options_list_message}"
227
231
  end
228
- end
229
- # todo: parse generated migrations and add options
230
- # todo: add index logic
232
+ # todo: parse generated migrations and add options
233
+ # todo: add index logic
231
234
 
232
- 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)"
233
- unless ARGV[0]
234
- puts "\n\nUse 'maml.rb maml.yml' (or other file arg) to actuallly run generators. Running with default maml.yml does test run only."
235
+ 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)"
236
+ unless ARGV[0]
237
+ puts "\n\nUse 'maml.rb maml.yml' (or other file arg) to actuallly run generators. Running with default maml.yml does test run only."
238
+ end
235
239
  end
236
240
  end
237
241
 
238
-
239
242
  # only run main if run standalone (e.g. not via ruby require)
240
243
  if __FILE__ == $0
241
244
  # puts "***** #{File.basename($0)} ran from file *****"
242
245
 
243
- main
246
+ Maml.main
244
247
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{maml}
8
- s.version = "0.1.4"
8
+ s.version = "0.1.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Nick Van Weerdenburg"]
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
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Van Weerdenburg