ki_middleman 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,8 @@
1
1
  from :youtrack_issue do |issue|
2
2
  to :pivotal_story do
3
3
  {
4
- "name" => "[#{issue['id']}] #{issue['summary']}",
5
- "description" =>"Youtrack: #{issue['issue_url']}\n#{issue['description']}",
4
+ "name" => "[#{issue.id}] #{issue.summary}",
5
+ "description" =>"Youtrack: #{issue.issue_url}\n#{issue.description}",
6
6
  "requested_by" => "Kiseru",
7
7
  "story_type" => "bug"
8
8
  }
data/bin/ki_middleman CHANGED
@@ -24,13 +24,21 @@ main do |arg|
24
24
  if options[:init]
25
25
  init
26
26
  elsif options[:to]
27
- pretty = $stdout.tty?
27
+ begin
28
+ pretty = $stdout.tty?
28
29
 
29
- output_type = options[:to]
30
- config = KiMiddleman::Config.from_file(Kiseru::ConfigDir.new.file('transforms.rb'))
31
- input = MultiJson.load($stdin.read)
32
- output = config.convert_data_to_format(input, output_type)
33
- $stdout.write MultiJson.dump(output, :pretty => pretty)
30
+ output_type = options[:to]
31
+ config = KiMiddleman::Config.from_file(Kiseru::ConfigDir.new.file('transforms.rb'))
32
+ input = MultiJson.load($stdin.read)
33
+ output = config.convert_data_to_format(input, output_type)
34
+ $stdout.write MultiJson.dump(output, :pretty => pretty)
35
+ rescue MultiJson::DecodeError => e
36
+ $stderr.puts "Invalid JSON"
37
+ exit 1
38
+ rescue KiMiddleman::ConfigError => e
39
+ $stderr.puts e.message
40
+ exit 1
41
+ end
34
42
  end
35
43
  end
36
44
 
data/ki_middleman.gemspec CHANGED
@@ -17,6 +17,7 @@ Gem::Specification.new do |gem|
17
17
 
18
18
  gem.add_dependency 'multi_json'
19
19
  gem.add_dependency('methadone')
20
+ gem.add_dependency('map')
20
21
 
21
22
  gem.add_development_dependency('debugger')
22
23
  gem.add_development_dependency('rake')
@@ -1,5 +1,7 @@
1
1
  module KiMiddleman
2
2
 
3
+ class ConfigError < StandardError; end;
4
+
3
5
  class Config
4
6
 
5
7
  def self.from_file(path)
@@ -13,6 +15,7 @@ module KiMiddleman
13
15
 
14
16
  def detect_from_format(data)
15
17
  @from_format = data['ki_type']
18
+ raise ConfigError, "Cannot convert from unknown type. Include 'ki_type' in JSON" if @from_format.nil?
16
19
  end
17
20
 
18
21
  def set_parsing_context
@@ -27,8 +30,9 @@ module KiMiddleman
27
30
  self.detect_from_format(data)
28
31
  @format_to_evaluate = format
29
32
  self.set_evaluation_context
33
+ raise ConfigError, "No transform from '#{@from_format}' found." unless @mapping.has_key?(@from_format.to_sym)
30
34
  evaluation_context = @mapping[@from_format.to_sym][:outer_block]
31
- converted_data = evaluation_context.call data
35
+ converted_data = evaluation_context.call Map.new(data)
32
36
  converted_data['ki_type'] = format
33
37
 
34
38
  converted_data
@@ -1,3 +1,3 @@
1
1
  module KiMiddleman
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/ki_middleman.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  require "ki_middleman/version"
2
2
  require 'multi_json'
3
+ require 'map'
3
4
 
4
5
  # TODO - refactor
5
6
  autoload :Kiseru, 'ki_middleman/kiseru'
6
7
 
7
-
8
8
  module KiMiddleman
9
9
 
10
10
  autoload :Config, 'ki_middleman/config'
@@ -34,8 +34,28 @@ JSON
34
34
  output['summary'].should == "[123] Something broke"
35
35
  end
36
36
 
37
- it "converts to a subformat" do
38
- pending
37
+ it "can use . syntax" do
38
+ config = KiMiddleman::Config.parse <<-RUBY
39
+ from(:bug) do |bug|
40
+ to(:story) do
41
+ {
42
+ 'summary' => bug.name
43
+ }
44
+ end
45
+ end
46
+ RUBY
47
+ input_json =<<-JSON
48
+ {
49
+ "ki_type" : "bug",
50
+ "name" : "Hello"
51
+ }
52
+ JSON
53
+
54
+ input = MultiJson.load(input_json)
55
+
56
+ output = config.convert_data_to_format(input, 'story')
57
+
58
+ output['summary'].should == "Hello"
39
59
  end
40
60
 
41
61
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ki_middleman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ date: 2012-08-15 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: multi_json
17
- requirement: &70147773323080 !ruby/object:Gem::Requirement
17
+ requirement: &70310574886120 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70147773323080
25
+ version_requirements: *70310574886120
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: methadone
28
- requirement: &70147773322660 !ruby/object:Gem::Requirement
28
+ requirement: &70310574885700 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,21 @@ dependencies:
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70147773322660
36
+ version_requirements: *70310574885700
37
+ - !ruby/object:Gem::Dependency
38
+ name: map
39
+ requirement: &70310574885280 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ type: :runtime
46
+ prerelease: false
47
+ version_requirements: *70310574885280
37
48
  - !ruby/object:Gem::Dependency
38
49
  name: debugger
39
- requirement: &70147773322240 !ruby/object:Gem::Requirement
50
+ requirement: &70310574884860 !ruby/object:Gem::Requirement
40
51
  none: false
41
52
  requirements:
42
53
  - - ! '>='
@@ -44,10 +55,10 @@ dependencies:
44
55
  version: '0'
45
56
  type: :development
46
57
  prerelease: false
47
- version_requirements: *70147773322240
58
+ version_requirements: *70310574884860
48
59
  - !ruby/object:Gem::Dependency
49
60
  name: rake
50
- requirement: &70147773321820 !ruby/object:Gem::Requirement
61
+ requirement: &70310586012480 !ruby/object:Gem::Requirement
51
62
  none: false
52
63
  requirements:
53
64
  - - ! '>='
@@ -55,10 +66,10 @@ dependencies:
55
66
  version: '0'
56
67
  type: :development
57
68
  prerelease: false
58
- version_requirements: *70147773321820
69
+ version_requirements: *70310586012480
59
70
  - !ruby/object:Gem::Dependency
60
71
  name: simplecov
61
- requirement: &70147773321400 !ruby/object:Gem::Requirement
72
+ requirement: &70310586012060 !ruby/object:Gem::Requirement
62
73
  none: false
63
74
  requirements:
64
75
  - - ! '>='
@@ -66,10 +77,10 @@ dependencies:
66
77
  version: '0'
67
78
  type: :development
68
79
  prerelease: false
69
- version_requirements: *70147773321400
80
+ version_requirements: *70310586012060
70
81
  - !ruby/object:Gem::Dependency
71
82
  name: rspec
72
- requirement: &70147773320980 !ruby/object:Gem::Requirement
83
+ requirement: &70310586011640 !ruby/object:Gem::Requirement
73
84
  none: false
74
85
  requirements:
75
86
  - - ! '>='
@@ -77,7 +88,7 @@ dependencies:
77
88
  version: '0'
78
89
  type: :development
79
90
  prerelease: false
80
- version_requirements: *70147773320980
91
+ version_requirements: *70310586011640
81
92
  description: Transforms JSON into other JSON
82
93
  email:
83
94
  - ben@freeagent.com