ki_middleman 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ki_middleman.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Ben Brinckerhoff
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ ki_middleman
2
+ ============
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ desc 'Default: run specs.'
6
+ task :default => :spec
7
+
8
+ desc "Run specs"
9
+ RSpec::Core::RakeTask.new do |t|
10
+ t.pattern = "./spec/**/*_spec.rb"
11
+ end
12
+
13
+ desc "Generate code coverage"
14
+ RSpec::Core::RakeTask.new("spec:coverage") do |t|
15
+ ENV['COVERAGE'] = "true"
16
+ end
data/bin/ki_middleman ADDED
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+ require 'methadone'
3
+ require 'ki_middleman'
4
+
5
+ include Methadone::Main
6
+ include Methadone::CLILogging
7
+
8
+ main do |arg|
9
+ if options[:to]
10
+ pretty = $stdout.tty?
11
+
12
+ output_type = options[:to]
13
+ config = KiMiddleman::Config.from_file('transform.rb')
14
+ input = MultiJson.load($stdin.read)
15
+ output = config.convert_data_to_format(input, output_type)
16
+ $stdout.write MultiJson.dump(output, :pretty => pretty)
17
+ end
18
+ end
19
+
20
+ version KiMiddleman::VERSION
21
+ description 'Transforms JSON into other JSON'
22
+
23
+ on("--to FORMAT", "The output JSON format")
24
+
25
+ go!
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/ki_middleman/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Ben Brinckerhoff", "Aaron Cronin"]
6
+ gem.email = ["ben@freeagent.com", "aaron@freeagent.com"]
7
+ gem.description = %q{Transforms JSON into other JSON}
8
+ gem.summary = %q{Transforms JSON into other JSON}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "ki_middleman"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = KiMiddleman::VERSION
17
+
18
+ gem.add_dependency 'multi_json'
19
+ gem.add_dependency('methadone')
20
+
21
+ gem.add_development_dependency('debugger')
22
+ gem.add_development_dependency('simpelcov')
23
+ gem.add_development_dependency('rspec')
24
+ end
@@ -0,0 +1,8 @@
1
+ require "ki_middleman/version"
2
+ require 'multi_json'
3
+
4
+ module KiMiddleman
5
+
6
+ autoload :Config, 'ki_middleman/config'
7
+
8
+ end
@@ -0,0 +1,65 @@
1
+ module KiMiddleman
2
+
3
+ class Config
4
+
5
+ def self.from_file(path)
6
+ code = File.read(path)
7
+ parse(code)
8
+ end
9
+
10
+ def self.parse(code)
11
+ Config.new(code)
12
+ end
13
+
14
+ def detect_from_format(data)
15
+ @from_format = data['ki_type']
16
+ end
17
+
18
+ def set_parsing_context
19
+ @parsing = true
20
+ end
21
+
22
+ def set_evaluation_context
23
+ @parsing = false
24
+ end
25
+
26
+ def convert_data_to_format(data, format)
27
+ self.detect_from_format(data)
28
+ @format_to_evaluate = format
29
+ self.set_evaluation_context
30
+ evaluation_context = @mapping[@from_format.to_sym][:outer_block]
31
+ converted_data = evaluation_context.call data
32
+ converted_data['ki_type'] = format
33
+
34
+ converted_data
35
+ end
36
+
37
+ def initialize(code)
38
+ self.set_parsing_context
39
+ @mapping = {}
40
+ instance_eval code
41
+ end
42
+
43
+ def from(from_format, &block)
44
+ @current_from = from_format
45
+ @mapping[@current_from] = {
46
+ :outer_block => block
47
+ }
48
+ yield
49
+ end
50
+
51
+ def to(to_format, &block)
52
+ # If 'parsing' then add the block to our lookup table, otherwise
53
+ # call the appropriate block (evaluation)
54
+ if @parsing
55
+ @mapping[@current_from][to_format] = block
56
+ else
57
+ if @format_to_evaluate.to_s == to_format.to_s
58
+ @evaluation = block.call
59
+ @format_to_evaluate = nil
60
+ end
61
+ @evaluation
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,3 @@
1
+ module KiMiddleman
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ include KiMiddleman
4
+
5
+ describe "converting JSON" do
6
+
7
+ it "converts to a base format" do
8
+ config = KiMiddleman::Config.parse <<-RUBY
9
+ from(:bug) do |bug|
10
+ to(:story) do
11
+ {
12
+ 'summary' => "[\#{bug['id']}] \#{bug['name']}"
13
+ }
14
+ end
15
+ to(:something_else) do
16
+ {
17
+ }
18
+ end
19
+ end
20
+ RUBY
21
+ input_json =<<-JSON
22
+ {
23
+ "ki_type" : "bug",
24
+ "name" : "Something broke",
25
+ "id" : "123"
26
+ }
27
+ JSON
28
+
29
+ input = MultiJson.load(input_json)
30
+
31
+ output = config.convert_data_to_format(input, 'story')
32
+
33
+ output['ki_type'].should == 'story'
34
+ output['summary'].should == "[123] Something broke"
35
+ end
36
+
37
+ it "converts to a subformat" do
38
+ pending
39
+ end
40
+
41
+ end
@@ -0,0 +1,25 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+
8
+ require 'ki_middleman'
9
+
10
+ RSpec.configure do |config|
11
+ config.treat_symbols_as_metadata_keys_with_true_values = true
12
+ config.run_all_when_everything_filtered = true
13
+ config.filter_run :focus
14
+
15
+ # Run specs in random order to surface order dependencies. If you find an
16
+ # order dependency and want to debug it, you can fix the order by providing
17
+ # the seed, which is printed after each run.
18
+ # --seed 1234
19
+ config.order = 'random'
20
+ end
21
+
22
+ if ENV['COVERAGE']
23
+ require 'simplecov'
24
+ SimpleCov.start
25
+ end
data/transform.rb ADDED
@@ -0,0 +1,14 @@
1
+ from :youtrack_issue do |issue|
2
+ to :pivotal_story do
3
+ {
4
+ "name" => "[#{issue['id']}] #{issue['summary']}",
5
+ "description" =>"Youtrack: #{issue['issue_url']}\n#{issue['description']}",
6
+ "requested_by" => "Kiseru",
7
+ "story_type" => "bug"
8
+ }
9
+ end
10
+ to :something_not_implemented_yet do
11
+ {
12
+ }
13
+ end
14
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ki_middleman
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ben Brinckerhoff
9
+ - Aaron Cronin
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-08-14 00:00:00.000000000Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: multi_json
17
+ requirement: &70107847687620 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *70107847687620
26
+ - !ruby/object:Gem::Dependency
27
+ name: methadone
28
+ requirement: &70107847687200 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *70107847687200
37
+ - !ruby/object:Gem::Dependency
38
+ name: debugger
39
+ requirement: &70107847686780 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *70107847686780
48
+ - !ruby/object:Gem::Dependency
49
+ name: simpelcov
50
+ requirement: &70107847686360 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *70107847686360
59
+ - !ruby/object:Gem::Dependency
60
+ name: rspec
61
+ requirement: &70107847685940 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: *70107847685940
70
+ description: Transforms JSON into other JSON
71
+ email:
72
+ - ben@freeagent.com
73
+ - aaron@freeagent.com
74
+ executables:
75
+ - ki_middleman
76
+ extensions: []
77
+ extra_rdoc_files: []
78
+ files:
79
+ - .gitignore
80
+ - .rspec
81
+ - Gemfile
82
+ - LICENSE
83
+ - README.md
84
+ - Rakefile
85
+ - bin/ki_middleman
86
+ - ki_middleman.gemspec
87
+ - lib/ki_middleman.rb
88
+ - lib/ki_middleman/config.rb
89
+ - lib/ki_middleman/version.rb
90
+ - spec/integration/convert_spec.rb
91
+ - spec/spec_helper.rb
92
+ - transform.rb
93
+ homepage: ''
94
+ licenses: []
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 1.8.10
114
+ signing_key:
115
+ specification_version: 3
116
+ summary: Transforms JSON into other JSON
117
+ test_files:
118
+ - spec/integration/convert_spec.rb
119
+ - spec/spec_helper.rb