maml 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +0 -0
- data/LICENSE +22 -0
- data/Manifest +12 -0
- data/README.rdoc +5 -0
- data/Rakefile +14 -0
- data/gem_notes +22 -0
- data/init.rb +1 -0
- data/lib/maml.rb +159 -0
- data/maml +1 -0
- data/maml.gemspec +31 -0
- data/maml.yml +80 -0
- data/maml_spec.txt +56 -0
- metadata +74 -0
data/CHANGELOG
ADDED
File without changes
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2009 Nick Van Weerdenburg
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest
ADDED
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
|
5
|
+
Echoe.new("maml", "0.1.1") do |p|
|
6
|
+
p.description = "Modeling Apathy Markup Language"
|
7
|
+
p.url = "http://github.com/vanweerd/maml"
|
8
|
+
p.author = "Nick Van Weerdenburg"
|
9
|
+
p.email = "nick@gmail.com"
|
10
|
+
p.ignore_pattern = ["tmp/*", "script/*"]
|
11
|
+
p.development_dependencies = []
|
12
|
+
end
|
13
|
+
|
14
|
+
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each{|ext| load ext}
|
data/gem_notes
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
= MAML Gem
|
2
|
+
Gemcutter
|
3
|
+
|
4
|
+
== Initial gem
|
5
|
+
|
6
|
+
|
7
|
+
== Build new gems
|
8
|
+
|
9
|
+
# modify version in gemspec
|
10
|
+
rake manifest
|
11
|
+
rake build_gemspec
|
12
|
+
|
13
|
+
# upload to gemspect again
|
14
|
+
|
15
|
+
|
16
|
+
== Using as a Plugin
|
17
|
+
|
18
|
+
add init.rb to include maml.rb
|
19
|
+
script/install <github_path>
|
20
|
+
# to install as a plugin into a project.
|
21
|
+
|
22
|
+
# users have option of using gem or plugin.
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'maml'
|
data/lib/maml.rb
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# maml.rb - Model and Migration Apathy Markup Language
|
3
|
+
# there is only 1 m in maml because I'm lazy.
|
4
|
+
# Copyright 2009 Zigleo, Inc.
|
5
|
+
# Author: Nick Van Weerdenburg
|
6
|
+
# todo: switch all puts to logger
|
7
|
+
# todo: remove some excess logging
|
8
|
+
# todo: create a gem
|
9
|
+
require "yaml"
|
10
|
+
require "logger"
|
11
|
+
|
12
|
+
# I love logging
|
13
|
+
$logger=Logger.new('maml.log')
|
14
|
+
$logger.level=Logger::INFO
|
15
|
+
$logger.info "PLATFORM=#{PLATFORM}"
|
16
|
+
|
17
|
+
# look user and project configuration file
|
18
|
+
user_config_file=ENV['HOME'] + "/.mamlrc"
|
19
|
+
project_config_file=".mamlrc"
|
20
|
+
$logger.info("user .mamlrc #{File.exist? user_config_file ? 'found' : 'not found'}")
|
21
|
+
$logger.info("project .mamlrc #{File.exist? project_config_file ? 'found' : 'not found'}")
|
22
|
+
|
23
|
+
module CurrentMethodName
|
24
|
+
def this_method
|
25
|
+
caller[0]=~/`(.*?)'/
|
26
|
+
$1
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
include CurrentMethodName
|
31
|
+
|
32
|
+
# simple test fixture
|
33
|
+
def test
|
34
|
+
string_arg
|
35
|
+
end
|
36
|
+
|
37
|
+
def extract_arg maml_field
|
38
|
+
maml_arg=nil
|
39
|
+
field=nil
|
40
|
+
type=nil
|
41
|
+
|
42
|
+
$logger.info this_method + "=> maml_field=#{maml_field}"
|
43
|
+
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"
|
56
|
+
else raise "Invalid field type";
|
57
|
+
end
|
58
|
+
field=Regexp.last_match(1)
|
59
|
+
maml_arg= "#{field}:#{type}"
|
60
|
+
end
|
61
|
+
|
62
|
+
# build script/generate model arguments from yaml info
|
63
|
+
def build_model_args maml
|
64
|
+
model_args={}
|
65
|
+
maml.each do |app|
|
66
|
+
puts "\napplication:#{app[0]}"
|
67
|
+
print "models: "
|
68
|
+
app[1].each do |model|
|
69
|
+
current_model_args=[]
|
70
|
+
model_name=model[0]
|
71
|
+
print "#{model_name} "
|
72
|
+
model[1].each do |field|
|
73
|
+
arg=extract_arg field
|
74
|
+
$logger.debug "Extract #{field} ===> #{arg}"
|
75
|
+
current_model_args << arg
|
76
|
+
end
|
77
|
+
model_args[model_name]=current_model_args
|
78
|
+
end
|
79
|
+
puts
|
80
|
+
end
|
81
|
+
model_args
|
82
|
+
end
|
83
|
+
|
84
|
+
# todo: add support for multiple files
|
85
|
+
# todo: add generate command override options to maml.yml for model specific generations.
|
86
|
+
def process_args args
|
87
|
+
generate_command,file=nil
|
88
|
+
|
89
|
+
args.each do |arg|
|
90
|
+
if arg[0,1] == "-" then
|
91
|
+
generate_command=arg[1,arg.length]
|
92
|
+
else
|
93
|
+
file=arg
|
94
|
+
end
|
95
|
+
end
|
96
|
+
return generate_command,file
|
97
|
+
end
|
98
|
+
|
99
|
+
# main function
|
100
|
+
def main
|
101
|
+
puts "\nMAML=Migration Apathy Markup Language"
|
102
|
+
puts "======================================"
|
103
|
+
puts "Visit http://lazymaml.org for more details"
|
104
|
+
puts "Copyright 2009 Zigelo and Nick Van Weerdenburg, Licensed under MIT License\n\n"
|
105
|
+
puts "usage: maml.rb <filename> [-generate_command]"
|
106
|
+
puts "e.g. maml.rb blog.yml -scaffold"
|
107
|
+
puts "OR"
|
108
|
+
puts "usage: maml.rb"
|
109
|
+
puts "(defaults to 'maml.yml' file and generating the model)\n\n"
|
110
|
+
puts "maml supports one file at time"
|
111
|
+
puts "generated files are in <rails_root>/maml"
|
112
|
+
puts "\nSpecify field type by symbol prefix as follows:"
|
113
|
+
puts "no prefix=string ; no prefix and _id suffix = integer ; override _id by adding prefix"
|
114
|
+
puts "examples: string, integer_id, .integer, ..float, %date, %%datetime, @time, @@timestamp, :string, ::text, =boolean, &binary"
|
115
|
+
puts "------------------------------------------------------------------------\n"
|
116
|
+
puts ""
|
117
|
+
|
118
|
+
generate_command, file = process_args ARGV
|
119
|
+
$logger.info "\ngenerate_command=#{generate_command}, file=#{file}"
|
120
|
+
@file_provided=true if file
|
121
|
+
$logger.info "@file_provided=#{@file_provided}"
|
122
|
+
|
123
|
+
file="maml.yml" unless file
|
124
|
+
generate_command="model" unless generate_command
|
125
|
+
puts "generate_command=#{generate_command}, file=#{file}"
|
126
|
+
|
127
|
+
maml=YAML::load(File.open(file))
|
128
|
+
|
129
|
+
model_args=build_model_args maml
|
130
|
+
|
131
|
+
puts
|
132
|
+
|
133
|
+
# now execute each model
|
134
|
+
model_args.each do |model|
|
135
|
+
model_name=model[0]
|
136
|
+
puts "model_name: #{model_name}"
|
137
|
+
model_fields=model[1].join " "
|
138
|
+
# File.open("maml.log", "a") { |file| file.write "---- model: #{model_name} (#{model_fields}) ---\n\n" }
|
139
|
+
File.open("maml.log", "a") { |file| file.write "---- model: #{model_name} \n\t\t\t#{model_fields.split(" ").join("\n\t\t\t")}\n---\n\n" }
|
140
|
+
command="ruby script/generate #{generate_command} #{model_name} #{model_fields} >> maml.log"
|
141
|
+
puts "command: #{command}\n\n"
|
142
|
+
if @file_provided == true
|
143
|
+
puts "=== calling system command ==="
|
144
|
+
system command
|
145
|
+
end
|
146
|
+
end
|
147
|
+
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
|
+
unless ARGV[0]
|
149
|
+
puts "\n\nUse 'maml.rb maml.yml' (or other file arg) to actuallly run generators. Running with default maml.yml does test run only."
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
|
154
|
+
# only run main if run standalone (e.g. not via ruby require)
|
155
|
+
if __FILE__ == $0
|
156
|
+
# puts "***** #{File.basename($0)} ran from file *****"
|
157
|
+
|
158
|
+
main
|
159
|
+
end
|
data/maml.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{maml}
|
5
|
+
s.version = "0.1.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Nick Van Weerdenburg"]
|
9
|
+
s.date = %q{2009-12-03}
|
10
|
+
s.description = %q{Modeling Apathy Markup Language}
|
11
|
+
s.email = %q{nick@gmail.com}
|
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", "maml.gemspec", "maml.yml", "maml_spec.txt", "Manifest", "Rakefile", "README.rdoc"]
|
14
|
+
s.has_rdoc = true
|
15
|
+
s.homepage = %q{http://github.com/vanweerd/maml}
|
16
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Maml", "--main", "README.rdoc"]
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
s.rubyforge_project = %q{maml}
|
19
|
+
s.rubygems_version = %q{1.3.1}
|
20
|
+
s.summary = %q{Modeling Apathy Markup Language}
|
21
|
+
|
22
|
+
if s.respond_to? :specification_version then
|
23
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
24
|
+
s.specification_version = 2
|
25
|
+
|
26
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
27
|
+
else
|
28
|
+
end
|
29
|
+
else
|
30
|
+
end
|
31
|
+
end
|
data/maml.yml
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
# maml- migration apathy markup lanaguage
|
2
|
+
# integer, float, date, datetime, timestamp, time, text, string, binary, boolean
|
3
|
+
#
|
4
|
+
# specify field type by symbol prefix as follows
|
5
|
+
# default type is string, except where field has _id suffice- then it's integer (override by adding prefix as shown below)
|
6
|
+
# .integer, ..float, %date, %%datetime, @time, @@timestamp, :string, ::text, =boolean, &binary
|
7
|
+
#
|
8
|
+
# level 1: module, level 2: class, level 3: field
|
9
|
+
|
10
|
+
innerplate:
|
11
|
+
Plate:
|
12
|
+
- day_id # any _id defaults to integer
|
13
|
+
- meal_id 50 true
|
14
|
+
- notes
|
15
|
+
- status
|
16
|
+
- completeness
|
17
|
+
- .calories
|
18
|
+
- title
|
19
|
+
|
20
|
+
Plate_Item:
|
21
|
+
- plate_id
|
22
|
+
- item_id
|
23
|
+
- uofm_id
|
24
|
+
- .units
|
25
|
+
- .calories
|
26
|
+
- notes
|
27
|
+
|
28
|
+
Conversion:
|
29
|
+
- item_id
|
30
|
+
- base_uofm_id
|
31
|
+
- uofm_id
|
32
|
+
- ratio
|
33
|
+
|
34
|
+
UnitOfMeasure:
|
35
|
+
- name
|
36
|
+
- system
|
37
|
+
- .related_measures
|
38
|
+
- ..ratio
|
39
|
+
- =is_base
|
40
|
+
|
41
|
+
Meal:
|
42
|
+
- name
|
43
|
+
- .proportion
|
44
|
+
- type %w[Meal Snack]
|
45
|
+
|
46
|
+
# loaded as my test case...
|
47
|
+
# Commitment:
|
48
|
+
# - %start_date
|
49
|
+
# - %end_date
|
50
|
+
# - ..goal_weight
|
51
|
+
# - ..start_weight
|
52
|
+
# - ..end_weight
|
53
|
+
# - ..current_weight
|
54
|
+
# - .stable_daily_calories
|
55
|
+
# - .goal_daily_calories
|
56
|
+
# - .calorie_margin
|
57
|
+
|
58
|
+
Item:
|
59
|
+
- =in_library
|
60
|
+
- =is_abstract
|
61
|
+
- .level
|
62
|
+
- name
|
63
|
+
- description
|
64
|
+
- category_id
|
65
|
+
- .calories
|
66
|
+
- uofm_id
|
67
|
+
- information_source
|
68
|
+
- accuracy %w[Draft Good Certain]
|
69
|
+
- category %w[Grains Protein Dairy Fruit Vegetables]
|
70
|
+
|
71
|
+
Day:
|
72
|
+
- %date
|
73
|
+
- plan
|
74
|
+
- .goal_calories
|
75
|
+
- .meals_expected
|
76
|
+
- .meals_completed
|
77
|
+
- .current_calories
|
78
|
+
- =is_complete
|
79
|
+
- summary
|
80
|
+
|
data/maml_spec.txt
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
== Maml
|
2
|
+
@ lazymaml.org
|
3
|
+
|
4
|
+
Maml= migration apathy markup language
|
5
|
+
|
6
|
+
|
7
|
+
== Spec
|
8
|
+
-minimal text to define fields
|
9
|
+
-strings (plain text) and ids (anything with _id) are defaults
|
10
|
+
-: and . id strings and integers explicitly. e.g. :myid_id (a string) or .funnyid (an integer)
|
11
|
+
-text: ::text
|
12
|
+
-float: ..float
|
13
|
+
-boolean: =boolean
|
14
|
+
-dates: %date
|
15
|
+
-datetime: %%
|
16
|
+
-time: @
|
17
|
+
-timestamp: @@
|
18
|
+
-binary: &
|
19
|
+
-alternatively, suffixes can be used (later version):
|
20
|
+
mystring:string or mystring:s
|
21
|
+
myint:integer/i
|
22
|
+
myfloat:float/f
|
23
|
+
mydate:date/d
|
24
|
+
mytimestamp:time/t
|
25
|
+
|
26
|
+
-full list of suffixes:
|
27
|
+
i,f,d,dt,ts,ti,t,s,bi,b
|
28
|
+
|
29
|
+
-yaml levls:
|
30
|
+
level 1: module or application
|
31
|
+
level 2: class
|
32
|
+
level 3: field
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
== To Do
|
37
|
+
release 0.1:
|
38
|
+
-DONE! support defaults and funny characters only
|
39
|
+
-DONE! log results to maml.log
|
40
|
+
-option to run against model or scaffold
|
41
|
+
-base on a one-time only run CHANGE: check for model and only run if no model
|
42
|
+
-save generated commands to maml subdirectory for later review
|
43
|
+
|
44
|
+
release 0.2:
|
45
|
+
-add full text descriptions
|
46
|
+
-multiple runs (only run items after last blank newline..could have generated migration inserted, removing new line?)
|
47
|
+
-add migration indicators:
|
48
|
+
-parse maml directory for files and find highs mamal number
|
49
|
+
-?insert number into ALL mamal files (i like above idea of adding migration to file)
|
50
|
+
-add new items afer.
|
51
|
+
|
52
|
+
release 0.3:
|
53
|
+
-add enumerations
|
54
|
+
e.g. %w[Meal Snack]
|
55
|
+
-add code
|
56
|
+
-add model relationships
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: maml
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nick Van Weerdenburg
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-12-03 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Modeling Apathy Markup Language
|
17
|
+
email: nick@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- CHANGELOG
|
24
|
+
- lib/maml.rb
|
25
|
+
- LICENSE
|
26
|
+
- README.rdoc
|
27
|
+
files:
|
28
|
+
- CHANGELOG
|
29
|
+
- gem_notes
|
30
|
+
- init.rb
|
31
|
+
- lib/maml.rb
|
32
|
+
- LICENSE
|
33
|
+
- maml
|
34
|
+
- maml.gemspec
|
35
|
+
- maml.yml
|
36
|
+
- maml_spec.txt
|
37
|
+
- Manifest
|
38
|
+
- Rakefile
|
39
|
+
- README.rdoc
|
40
|
+
has_rdoc: true
|
41
|
+
homepage: http://github.com/vanweerd/maml
|
42
|
+
licenses: []
|
43
|
+
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options:
|
46
|
+
- --line-numbers
|
47
|
+
- --inline-source
|
48
|
+
- --title
|
49
|
+
- Maml
|
50
|
+
- --main
|
51
|
+
- README.rdoc
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "0"
|
59
|
+
version:
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: "1.2"
|
65
|
+
version:
|
66
|
+
requirements: []
|
67
|
+
|
68
|
+
rubyforge_project: maml
|
69
|
+
rubygems_version: 1.3.5
|
70
|
+
signing_key:
|
71
|
+
specification_version: 2
|
72
|
+
summary: Modeling Apathy Markup Language
|
73
|
+
test_files: []
|
74
|
+
|