ki_middleman 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/ki_middleman +9 -4
- data/lib/ki_middleman/config.rb +2 -1
- data/lib/ki_middleman/version.rb +1 -1
- data/spec/integration/convert_spec.rb +32 -2
- metadata +1 -1
data/bin/ki_middleman
CHANGED
@@ -41,16 +41,21 @@ module KiMiddleman
|
|
41
41
|
else
|
42
42
|
input = MultiJson.load($stdin.read)
|
43
43
|
end
|
44
|
-
|
44
|
+
patch = Hash.new
|
45
|
+
constants = ""
|
45
46
|
if options[:set]
|
46
47
|
assignments = Array(options[:set].split(','))
|
47
|
-
patch = Hash.new
|
48
48
|
assignments.each do |assignment|
|
49
49
|
key,value = assignment.split('=')
|
50
|
-
|
50
|
+
if (key != key.upcase)
|
51
|
+
patch[key] = value
|
52
|
+
else
|
53
|
+
constants << "#{key} = \"#{value}\"; "
|
54
|
+
end
|
51
55
|
end
|
52
|
-
output.merge!(patch)
|
53
56
|
end
|
57
|
+
output = config.convert_data_to_format(input, output_type, constants)
|
58
|
+
output.merge!(patch)
|
54
59
|
$stdout.write MultiJson.dump(output, :pretty => pretty)
|
55
60
|
rescue MultiJson::DecodeError => e
|
56
61
|
$stderr.puts "Invalid JSON"
|
data/lib/ki_middleman/config.rb
CHANGED
@@ -44,7 +44,7 @@ module KiMiddleman
|
|
44
44
|
@parsing = false
|
45
45
|
end
|
46
46
|
|
47
|
-
def convert_data_to_format(data, format)
|
47
|
+
def convert_data_to_format(data, format, constants)
|
48
48
|
self.detect_from_format(data)
|
49
49
|
|
50
50
|
raise ConfigError, "No transform from '#{@from_format}' found." unless @mapping.has_key?(@from_format.to_sym)
|
@@ -62,6 +62,7 @@ module KiMiddleman
|
|
62
62
|
@format_to_evaluate = best_to_format
|
63
63
|
self.set_evaluation_context
|
64
64
|
evaluation_context = @mapping[@from_format.to_sym][:outer_block]
|
65
|
+
instance_eval constants
|
65
66
|
converted_data = evaluation_context.call Map.new(data)
|
66
67
|
converted_data['ki_type'] = best_to_format
|
67
68
|
|
data/lib/ki_middleman/version.rb
CHANGED
@@ -28,7 +28,7 @@ JSON
|
|
28
28
|
|
29
29
|
input = MultiJson.load(input_json)
|
30
30
|
|
31
|
-
output = config.convert_data_to_format(input, 'story')
|
31
|
+
output = config.convert_data_to_format(input, 'story', '')
|
32
32
|
|
33
33
|
output['ki_type'].should == 'story'
|
34
34
|
output['summary'].should == "[123] Something broke"
|
@@ -53,9 +53,39 @@ JSON
|
|
53
53
|
|
54
54
|
input = MultiJson.load(input_json)
|
55
55
|
|
56
|
-
output = config.convert_data_to_format(input, 'story')
|
56
|
+
output = config.convert_data_to_format(input, 'story', '')
|
57
57
|
|
58
58
|
output['summary'].should == "Hello"
|
59
59
|
end
|
60
60
|
|
61
|
+
it "can subsitute in constants" do
|
62
|
+
config = KiMiddleman::Config.parse <<-RUBY
|
63
|
+
CONSTANT = "first"
|
64
|
+
from(:bug) do |bug|
|
65
|
+
to(:story) do
|
66
|
+
{
|
67
|
+
'summary' => CONSTANT
|
68
|
+
}
|
69
|
+
end
|
70
|
+
end
|
71
|
+
RUBY
|
72
|
+
input_json =<<-JSON
|
73
|
+
{
|
74
|
+
"ki_type" : "bug",
|
75
|
+
"name" : "Hello"
|
76
|
+
}
|
77
|
+
JSON
|
78
|
+
|
79
|
+
input = MultiJson.load(input_json)
|
80
|
+
|
81
|
+
output = config.convert_data_to_format(input, 'story', '')
|
82
|
+
|
83
|
+
output['summary'].should == "first"
|
84
|
+
|
85
|
+
output = config.convert_data_to_format(input, 'story', 'CONSTANT = "second";')
|
86
|
+
|
87
|
+
output['summary'].should == "second"
|
88
|
+
|
89
|
+
end
|
90
|
+
|
61
91
|
end
|