yamlm 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ece904c3f4b309a81ca596757d954d1e40b0efb1a592603f88d7a3f9045f90c8
4
+ data.tar.gz: e9d80456fbc3897aa7d3a0cd78912d25467c6219a63696c64818d8df770eecb0
5
+ SHA512:
6
+ metadata.gz: f8c013f707403d1ab51a6deaffd1eee59506d9c78d3677907b6e379235e2c593681fd10bcf1cf0c4529d9fbb1f3a05a57c76839edeab44637be67e2571657e3a
7
+ data.tar.gz: cfc8cf5ce079fb695a30ff1d46fa491630e21574db55a55c6910f6e18452659ace68dc1266be3665b1f5b0eb4b889938677127892ed95ef57e5c150813a1d938
@@ -0,0 +1,13 @@
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
12
+
13
+ /Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,14 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.7.0
3
+ Metrics/BlockLength:
4
+ Exclude:
5
+ - spec/**/*
6
+ Layout/LineLength:
7
+ Max: 80
8
+ IgnoredPatterns: ['(\A|\s+)#']
9
+ Style/HashEachMethods:
10
+ Enabled: true
11
+ Style/HashTransformKeys:
12
+ Enabled: true
13
+ Style/HashTransformValues:
14
+ Enabled: true
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.0
6
+ before_install: gem install bundler -v 2.1.2
@@ -0,0 +1,5 @@
1
+ # CHANGELOG
2
+
3
+ ## 0.1.0 / 2020-03-24
4
+ ### New features
5
+ - create gem
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in yamlm.gemspec
6
+ gemspec
7
+
8
+ gem 'rake', '~> 12.0'
9
+ gem 'rspec', '~> 3.0'
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 shoma07
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.
@@ -0,0 +1,67 @@
1
+ # YAMLM
2
+
3
+ Tool to merge multiple YAML files.
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ $ gem install yamlm
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```
14
+ # yamlm <file1.yml> <file2.yml> ...<filen.yml>
15
+ $ yamlm original.yml extended.yml
16
+ ```
17
+
18
+ original.yml
19
+
20
+ ```
21
+ record:
22
+ hoge: &hoge
23
+ id: 1
24
+ name: hoge
25
+ age: 20
26
+ ```
27
+
28
+ extended.yml
29
+
30
+ ```
31
+ record:
32
+ fuga:
33
+ <<: *hoge
34
+ name: fuga
35
+ ```
36
+
37
+ output
38
+
39
+ ```
40
+ ---
41
+ record:
42
+ hoge:
43
+ id: 1
44
+ name: hoge
45
+ age: 20
46
+ fuga:
47
+ id: 1
48
+ name: fuga
49
+ age: 20
50
+ ```
51
+
52
+ It must be recognized as a single document when the files are combined.
53
+
54
+ ## Development
55
+
56
+ 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.
57
+
58
+ 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).
59
+
60
+ ## Contributing
61
+
62
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/yamlm.
63
+
64
+
65
+ ## License
66
+
67
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'yamlm'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'yamlm'
5
+
6
+ YAMLM::CLI.new(ARGV).execute
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+ require 'yamlm/version'
5
+ require 'yamlm/cli'
6
+
7
+ module YAMLM
8
+ class Error < StandardError; end
9
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ module YAMLM
4
+ # YAMLM::CLI
5
+ class CLI
6
+ # @param argv [Array]
7
+ def initialize(argv = [])
8
+ @files = argv
9
+ end
10
+
11
+ # @return [void]
12
+ def execute
13
+ puts dump_yaml(
14
+ merge_hash_array(load_texts(merge_texts(read_files(@files))))
15
+ )
16
+ end
17
+
18
+ private
19
+
20
+ # @param files [Array]
21
+ # @return [Array]
22
+ def read_files(files)
23
+ files.map { |f| File.read(f) }
24
+ end
25
+
26
+ # @param texts [Array]
27
+ # @return [Array]
28
+ def merge_texts(texts)
29
+ texts.each_with_object([]) { |t, r| r << r.last.to_s + t }
30
+ end
31
+
32
+ # @param texts [Array]
33
+ # @return [Array]
34
+ def load_texts(texts)
35
+ texts.map { |t| YAML.safe_load(t, [], [], true) }
36
+ end
37
+
38
+ # @param array [Array]
39
+ # @return [Hash]
40
+ def merge_hash_array(array)
41
+ array.each_with_object({}) { |h, r| deep_merge_hash(r, h) }
42
+ end
43
+
44
+ # @param origin_hash [Hash]
45
+ # @param other_hash [Hash]
46
+ # @return [Hash]
47
+ def deep_merge_hash(origin_hash, other_hash)
48
+ origin_hash.merge!(other_hash) do |_key, this_val, other_val|
49
+ if this_val.is_a?(Hash) && other_val.is_a?(Hash)
50
+ deep_merge_hash(this_val.dup, other_val)
51
+ else
52
+ other_val
53
+ end
54
+ end
55
+ end
56
+
57
+ # @param hash [Hash]
58
+ # @return [String]
59
+ def dump_yaml(hash)
60
+ YAML.dump(hash.empty? ? nil : hash)
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module YAMLM
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/yamlm/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'yamlm'
7
+ spec.version = YAMLM::VERSION
8
+ spec.authors = ['shoma07']
9
+ spec.email = ['23730734+shoma07@users.noreply.github.com']
10
+
11
+ spec.summary = 'Tool to merge multiple YAML files'
12
+ spec.description = 'Tool to merge multiple YAML files'
13
+ spec.homepage = 'https://github.com/shoma07/yamlm'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
16
+
17
+ spec.metadata['homepage_uri'] = spec.homepage
18
+ spec.metadata['source_code_uri'] = spec.homepage
19
+ spec.metadata['changelog_uri'] =
20
+ "#{spec.homepage}/blob/v#{spec.version}/CHANGELOG.md"
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ end
29
+ spec.bindir = 'exe'
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ['lib']
32
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yamlm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - shoma07
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-03-23 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Tool to merge multiple YAML files
14
+ email:
15
+ - 23730734+shoma07@users.noreply.github.com
16
+ executables:
17
+ - yamlm
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".gitignore"
22
+ - ".rspec"
23
+ - ".rubocop.yml"
24
+ - ".travis.yml"
25
+ - CHANGELOG.md
26
+ - Gemfile
27
+ - LICENSE.txt
28
+ - README.md
29
+ - Rakefile
30
+ - bin/console
31
+ - bin/setup
32
+ - exe/yamlm
33
+ - lib/yamlm.rb
34
+ - lib/yamlm/cli.rb
35
+ - lib/yamlm/version.rb
36
+ - yamlm.gemspec
37
+ homepage: https://github.com/shoma07/yamlm
38
+ licenses:
39
+ - MIT
40
+ metadata:
41
+ homepage_uri: https://github.com/shoma07/yamlm
42
+ source_code_uri: https://github.com/shoma07/yamlm
43
+ changelog_uri: https://github.com/shoma07/yamlm/blob/v0.1.0/CHANGELOG.md
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 2.3.0
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubygems_version: 3.1.2
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: Tool to merge multiple YAML files
63
+ test_files: []