danarchy_jaml 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ce4f04da1b5c6ded4efa580dea8441866ea18523df0f89c2ca7618fe66ea1729
4
+ data.tar.gz: f3280fbc8e3a6012a8cfcbab61d474f4614250a0b4e0a49ad129f07fb598da62
5
+ SHA512:
6
+ metadata.gz: 692d23051d3d5c222d314f2270c1f264aa48480744e6a6fe615a8a49fa3c0d2102dab33b6b1f6bb0504592bfae9a024913408271e9700aa91f123dc2f3b368c7
7
+ data.tar.gz: 739af02b51eb0e92251b8cc33e14f752d23310869b1d91e694d58f2fd896c3736958e8f5656058ee0aa63fbb6d3399745dd44dd1aa8c09311029923c50da0570
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.4.5
7
+ before_install: gem install bundler -v 1.17.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/danarchy85/danarchy_jaml" }
4
+
5
+ # Specify your gem's dependencies in danarchy_jaml.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Dan James
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # DanarchyJaml
2
+
3
+ dAnarchy Jaml converts YAML files to JSON and JSON files to YAML. This assumes a standard YAML or JSON formatted file and does not accept files containing specialized functions like AWS Cloudformation templates.
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'danarchy_jaml'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install danarchy_jaml
21
+
22
+
23
+ ## Usage
24
+
25
+ ```
26
+ ~$ danarchy_jaml /tmp/file1.yaml /tmp/file2.json
27
+ Converting YAML to JSON...
28
+ File written: /tmp/test1.json
29
+ Converting JSON to YAML...
30
+ File written: /tmp/file2.yaml
31
+ ```
32
+
33
+
34
+ ## License
35
+
36
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -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/bin/jaml ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../lib/danarchy_jaml'
3
+
4
+ if ARGV.empty?
5
+ abort('Need at least one JSON or YAML file (space separated).')
6
+ else
7
+ ARGV.each do |file|
8
+ DanarchyJaml::Convert.new(file)
9
+ end
10
+ end
@@ -0,0 +1,42 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "danarchy_jaml/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "danarchy_jaml"
8
+ spec.version = DanarchyJaml::VERSION
9
+ spec.authors = ["Dan James"]
10
+ spec.email = ["dan@danarchy.me"]
11
+
12
+ spec.summary = %q{A simple gem to convert between JSON and YAML files.}
13
+ spec.description = %q{dAnarchy Jaml converts YAML files to JSON and JSON files to YAML. This assumes a standard YAML or JSON formatted file and does not accept files containing specialized functions like AWS Cloudformation templates.}
14
+ spec.homepage = "https://github.com/danarchy85/danarchy_jaml"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+
22
+ # spec.metadata["homepage_uri"] = spec.homepage
23
+ # spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
24
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
25
+ else
26
+ raise "RubyGems 2.0 or newer is required to protect against " \
27
+ "public gem pushes."
28
+ end
29
+
30
+ # Specify which files should be added to the gem when it is released.
31
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
32
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
33
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
34
+ end
35
+ spec.bindir = "bin"
36
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
37
+ spec.require_paths = ["lib"]
38
+
39
+ spec.add_development_dependency "bundler", "~> 1.17"
40
+ spec.add_development_dependency "rake", "~> 10.0"
41
+ spec.add_development_dependency "rspec", "~> 3.0"
42
+ end
@@ -0,0 +1,47 @@
1
+ require_relative "danarchy_jaml/version"
2
+ require 'json'
3
+ require 'yaml'
4
+
5
+ module DanarchyJaml
6
+ class Convert
7
+ def initialize(file)
8
+ if %w[json jsn].include?(file.split('.').last)
9
+ puts "Converting JSON to YAML..."
10
+ json_to_yaml(file)
11
+ elsif %w[yaml yml].include?(file.split('.').last)
12
+ puts "Converting YAML to JSON..."
13
+ yaml_to_json(file)
14
+ else
15
+ abort("Unknown file extension: #{file}")
16
+ end
17
+ end
18
+
19
+ def json_to_yaml(file)
20
+ outfile = file.gsub(/(json|jsn)/, 'yaml')
21
+ hash = JSON.parse(File.read(file))
22
+
23
+ begin
24
+ File.write(outfile, hash.to_yaml)
25
+ rescue StandardError => e
26
+ puts e.message
27
+ ensure
28
+ File.exist?(outfile)
29
+ puts "File written: #{outfile}"
30
+ end
31
+ end
32
+
33
+ def yaml_to_json(file)
34
+ outfile = file.gsub(/(yaml|yml)/, 'json')
35
+ hash = YAML.load(File.read(file))
36
+
37
+ begin
38
+ File.write(outfile, JSON.pretty_generate(hash))
39
+ rescue StandardError => e
40
+ puts e.message
41
+ ensure
42
+ File.exist?(outfile)
43
+ puts "File written: #{outfile}"
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,3 @@
1
+ module DanarchyJaml
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: danarchy_jaml
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dan James
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-12-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: dAnarchy Jaml converts YAML files to JSON and JSON files to YAML. This
56
+ assumes a standard YAML or JSON formatted file and does not accept files containing
57
+ specialized functions like AWS Cloudformation templates.
58
+ email:
59
+ - dan@danarchy.me
60
+ executables:
61
+ - jaml
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - ".gitignore"
66
+ - ".rspec"
67
+ - ".travis.yml"
68
+ - Gemfile
69
+ - LICENSE.txt
70
+ - README.md
71
+ - Rakefile
72
+ - bin/jaml
73
+ - danarchy_jaml.gemspec
74
+ - lib/danarchy_jaml.rb
75
+ - lib/danarchy_jaml/version.rb
76
+ homepage: https://github.com/danarchy85/danarchy_jaml
77
+ licenses:
78
+ - MIT
79
+ metadata:
80
+ allowed_push_host: https://rubygems.org
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.7.6
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: A simple gem to convert between JSON and YAML files.
101
+ test_files: []