json2hcl 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ef876985a9c7dce716d757c99506149ae225ecaa
4
+ data.tar.gz: bc9d6e72565d36d42ccc55e3aa3817725fe39874
5
+ SHA512:
6
+ metadata.gz: f0465267c03c2e28f3003d9d5260f1de0ab227522766a6027d0ddcf185e99f98c4e187d5913bdacc6eb9feaad03d8e07c0807559cfb17733b820e7310e9a8a91
7
+ data.tar.gz: 95504c23aa3b8be2eaa9f0d05e2d68982620c8b16fe1ad372f663469e198af93728a25cc03b373d85db78c4877558197e163afff9a252fe17cf69b9921dcf935
@@ -0,0 +1,13 @@
1
+ # RubyGems
2
+ /.bundle/
3
+ /.yardoc
4
+ /_yardoc/
5
+ /coverage/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /vendor/
10
+ **/*.gem
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
@@ -0,0 +1,6 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+
6
+ before_install: gem install bundler -v 1.16.0.pre.2
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in json2hcl.gemspec
6
+ gemspec
@@ -0,0 +1,45 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ json2hcl (0.0.7)
5
+ os (~> 1.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ coderay (1.1.2)
11
+ diff-lcs (1.3)
12
+ method_source (0.9.0)
13
+ os (1.0.0)
14
+ pry (0.11.1)
15
+ coderay (~> 1.1.0)
16
+ method_source (~> 0.9.0)
17
+ rake (12.1.0)
18
+ rspec (3.6.0)
19
+ rspec-core (~> 3.6.0)
20
+ rspec-expectations (~> 3.6.0)
21
+ rspec-mocks (~> 3.6.0)
22
+ rspec-core (3.6.0)
23
+ rspec-support (~> 3.6.0)
24
+ rspec-expectations (3.6.0)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.6.0)
27
+ rspec-json_expectations (2.1.0)
28
+ rspec-mocks (3.6.0)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.6.0)
31
+ rspec-support (3.6.0)
32
+
33
+ PLATFORMS
34
+ ruby
35
+
36
+ DEPENDENCIES
37
+ bundler (~> 1.16.a)
38
+ json2hcl!
39
+ pry (~> 0.10)
40
+ rake (~> 12.0)
41
+ rspec (~> 3.0)
42
+ rspec-json_expectations (~> 2.1.0)
43
+
44
+ BUNDLED WITH
45
+ 1.16.0.pre.2
@@ -0,0 +1,35 @@
1
+ # Json2hcl
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/json2hcl`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'json2hcl'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install json2hcl
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/json2hcl.
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ v0.0.7
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'json2hcl'
5
+
6
+ require 'pry'
7
+ Pry.start
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
@@ -0,0 +1,31 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ require 'json2hcl/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'json2hcl'
8
+ spec.version = Json2hcl::VERSION
9
+ spec.authors = [ 'Igor Gentil' ]
10
+ spec.email = [ 'igor@devops.cool' ]
11
+
12
+ spec.summary = 'Gem wrapper for Json2Hcl'
13
+ spec.description = 'Gem wrapper for Json2Hcl (https://github.com/kvz/json2hcl). It follows the releases of that project'
14
+ spec.homepage = 'https://github.com/igorlg/json2hcl'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = [ 'lib' ]
23
+
24
+ spec.add_dependency 'os', '~> 1.0'
25
+
26
+ spec.add_development_dependency 'rspec-json_expectations', '~> 2.1.0'
27
+ spec.add_development_dependency 'bundler', '~> 1.16.a'
28
+ spec.add_development_dependency 'rake', '~> 12.0'
29
+ spec.add_development_dependency 'rspec', '~> 3.0'
30
+ spec.add_development_dependency 'pry', '~> 0.10'
31
+ end
@@ -0,0 +1,78 @@
1
+ require 'json2hcl/version'
2
+ require 'json2hcl/os'
3
+
4
+ require 'tempfile'
5
+ require 'open3'
6
+
7
+ module Json2hcl
8
+ def self.binfile
9
+ file = "json2hcl_v#{VERSION}_#{OS.os}_#{OS.arch}"
10
+ file += '.exe' if OS.os == 'windows'
11
+ File.expand_path(File.join('json2hcl', 'bin', file), __dir__)
12
+ end
13
+
14
+ def self.to_json(data)
15
+ if File.file?(data)
16
+ begin
17
+ jsonstr = cmd(data, true)
18
+ rescue CommandExecutionError
19
+ raise InvalidHCLError
20
+ end
21
+ else
22
+ # TODO: REFACTOR THIS!
23
+ f = ::Tempfile.new
24
+ f.write(data)
25
+ f.close
26
+
27
+ begin
28
+ jsonstr = cmd(f.path, true)
29
+ rescue CommandExecutionError
30
+ raise InvalidHCLError
31
+ ensure
32
+ f.unlink
33
+ end
34
+ end
35
+
36
+ return jsonstr
37
+ end
38
+
39
+ def self.to_hcl(data)
40
+ if File.file?(data)
41
+ begin
42
+ hclstr = cmd(data, false)
43
+ rescue CommandExecutionError
44
+ raise InvalidJSONError
45
+ end
46
+ else
47
+ f = ::Tempfile.new
48
+ f.write(data)
49
+ f.close
50
+
51
+ begin
52
+ hclstr = cmd(f.path, false)
53
+ rescue CommandExecutionError
54
+ raise InvalidJSONError
55
+ ensure
56
+ f.unlink
57
+ end
58
+ end
59
+
60
+ return hclstr
61
+ end
62
+
63
+ def self.cmd(data, reverse=false)
64
+ raise ArgumentError unless [true, false].include? reverse
65
+ raise InvalidFileError unless Pathname.new(data).absolute?
66
+
67
+ cmd = binfile
68
+ cmd += ' -reverse' if reverse
69
+ cmd += ' 2>&1'
70
+ cmd += " < #{data}"
71
+
72
+ stdout = `#{cmd}`
73
+ # puts cmd
74
+ raise CommandExecutionError unless $?.exitstatus == 0
75
+
76
+ return stdout
77
+ end
78
+ end
@@ -0,0 +1,28 @@
1
+ # Exceptions
2
+
3
+ module Json2hcl
4
+ class InvalidHCLError < StandardError
5
+ def initialize(msg='Invalid HCL')
6
+ super
7
+ end
8
+ end
9
+
10
+ class InvalidJSONError < StandardError
11
+ def initialize(msg='Invalid JSON')
12
+ super
13
+ end
14
+ end
15
+
16
+ class InvalidFileError < StandardError
17
+ def initialize(msg='Invalid path to file')
18
+ super
19
+ end
20
+ end
21
+
22
+ class CommandExecutionError < StandardError
23
+ # TODO: Add extra parameters for stdout, stderr and exitstatus
24
+ def initialize(msg='Command returned a non-zero status')
25
+ super
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,16 @@
1
+ require 'os'
2
+
3
+ module Json2hcl
4
+ module OS
5
+ def self.os
6
+ return 'linux' if ::OS.linux?
7
+ return 'darwin' if ::OS.mac?
8
+ return 'windows' if ::OS.windows?
9
+ end
10
+
11
+ def self.arch
12
+ return '386' if ::OS.bits == 32
13
+ return 'amd64' if ::OS.bits == 64
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module Json2hcl
2
+ VERSION = File.read(File.expand_path(File.join('..', '..', 'VERSION'), __dir__)).sub(/v/, '').strip
3
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: json2hcl
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.7
5
+ platform: ruby
6
+ authors:
7
+ - Igor Gentil
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-10-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: os
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec-json_expectations
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.1.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.1.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.16.a
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.16.a
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '12.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '12.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.10'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.10'
97
+ description: Gem wrapper for Json2Hcl (https://github.com/kvz/json2hcl). It follows
98
+ the releases of that project
99
+ email:
100
+ - igor@devops.cool
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - Gemfile.lock
109
+ - README.md
110
+ - Rakefile
111
+ - VERSION
112
+ - bin/console
113
+ - bin/setup
114
+ - json2hcl.gemspec
115
+ - lib/json2hcl.rb
116
+ - lib/json2hcl/bin/json2hcl_v0.0.7_darwin_386
117
+ - lib/json2hcl/bin/json2hcl_v0.0.7_darwin_amd64
118
+ - lib/json2hcl/bin/json2hcl_v0.0.7_linux_386
119
+ - lib/json2hcl/bin/json2hcl_v0.0.7_linux_amd64
120
+ - lib/json2hcl/bin/json2hcl_v0.0.7_windows_386.exe
121
+ - lib/json2hcl/bin/json2hcl_v0.0.7_windows_amd64.exe
122
+ - lib/json2hcl/exceptions.rb
123
+ - lib/json2hcl/os.rb
124
+ - lib/json2hcl/version.rb
125
+ homepage: https://github.com/igorlg/json2hcl
126
+ licenses:
127
+ - MIT
128
+ metadata: {}
129
+ post_install_message:
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ requirements: []
144
+ rubyforge_project:
145
+ rubygems_version: 2.6.12
146
+ signing_key:
147
+ specification_version: 4
148
+ summary: Gem wrapper for Json2Hcl
149
+ test_files: []