-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
71 lines (60 loc) · 1.98 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
require 'rubygems'
require 'activesupport'
require 'ptolemy'
Ptolemy::Mapper.map_directory = File.dirname(__FILE__) + "/tmp"
namespace :mappings do
def format_mapping(length, source, target)
"\t%-#{length}s => %s" % [source, target]
end
desc "compare the source rules of a specific map definition with the target rules of another"
task :compare do
s_key = ARGV[1]
t_key = ARGV[2]
Ptolemy::Mapper.load_maps
Ptolemy::Tools.compare(s_key, t_key) do |length, source, target|
puts format_mapping(length, source, target)
end
end
desc "iterate through a specific map definition and spit out mapping rules"
task :definition do
key = ARGV[1]
puts "Map definition for: '#{key.to_s}'\n\n"
Ptolemy::Mapper.load_maps
Ptolemy::Tools.list_definition(key) do |length, source, target|
puts format_mapping(length, source, target)
end
puts "\n\n"
end
desc "list all map definition keys"
task :keys do
Ptolemy::Mapper.load_maps
Ptolemy::Tools.keys
end
desc "iterate through a specific map definition and spit out source rules"
task :sources do
key = ARGV[1]
puts "Map definition sources: '#{key.to_s}'\n\n"
Ptolemy::Mapper.load_maps
Ptolemy::Tools.list_sources(key) do |source|
puts source
end
end
desc "iterate through a specific map definition and spit out target rules\tparam: target key"
task :targets do
key = ARGV[1]
puts "Map definition targets: '#{key.to_s}'\n\n"
Ptolemy::Mapper.load_maps
Ptolemy::Tools.list_targets(key) do |target|
puts target
end
end
desc "translate a single mapping rule for a specific definition"
task :translate_rule do
definition = ARGV[1]
source_path = ARGV[2]
source = (ARGV[3] =~ /^\{/) ? ActiveSupport::JSON.decode(ARGV[3]) : ARGV[3]
puts "Map translation of rule '#{rule}' for definition '#{definition}'\n\n"
Ptolemy::Mapper.load_maps
puts Ptolemy::Tools.translate(definition, source_path, source)
end
end