differz 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +39 -0
- data/Rakefile +1 -0
- data/bin/differz +37 -0
- data/differz.gemspec +26 -0
- data/lib/differz.rb +3 -0
- data/lib/differz/comparer.rb +44 -0
- data/lib/differz/version.rb +3 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7db15e63c95269378a9984ae2680a4e81062e9d1
|
4
|
+
data.tar.gz: d13f4d2a3689a823d3af071be00008b8e0067bcc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 24351214a597c9745ec3fbc0218e1833b5898187a63a449bcb925fba1eb37a32af9d0abfa390ced3cec519287136ac25f80aa096985bc381ac3591bc1bb67af6
|
7
|
+
data.tar.gz: c27f2f7a885a37aa078e3b52c1337811598844dc26f6242023450e795714434244f3328b53d8efa692e1c022fc339504f6f4d95df701cd34c015b99aea94aa9d
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 HeeL
|
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,39 @@
|
|
1
|
+
This is a simple but sometimes very useful tool. If you pass 2 yaml files it will compare them and show the keys of the first file that the second file is missing.
|
2
|
+
|
3
|
+
That can be handy if you develop a multilingual application and your translations are stored in yaml files. An example is a Rails framework with yaml files for every language (em.yml, ru.yml...). Many other apps use this approach too.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
You can use it from the command line:
|
8
|
+
```
|
9
|
+
differz --help
|
10
|
+
```
|
11
|
+
|
12
|
+
GLOBAL OPTIONS
|
13
|
+
|
14
|
+
`--help` - Show all the arguments and commands
|
15
|
+
|
16
|
+
`--version` - Display the program version
|
17
|
+
|
18
|
+
|
19
|
+
COMMANDS
|
20
|
+
|
21
|
+
`edit` - Allows you to fill missing keys in yaml file
|
22
|
+
|
23
|
+
`help` - Shows a list of commands or help for one command
|
24
|
+
|
25
|
+
`show` - Only show the difference between yaml-files without editing them
|
26
|
+
|
27
|
+
|
28
|
+
For the `show` and `edit` commands you have to pass at least two arguments: paths for yaml files that should be compared. Here is an example of usage:
|
29
|
+
```
|
30
|
+
differz show file1.yml file2.yml
|
31
|
+
```
|
32
|
+
|
33
|
+
As a result, you will see all the keys from file1.yml that are missing in file2.yml. The result will be shown in format like this:
|
34
|
+
```
|
35
|
+
en -> main -> label
|
36
|
+
en -> main -> text
|
37
|
+
...
|
38
|
+
level1 -> level2 -> level3...
|
39
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/differz
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'gli'
|
4
|
+
require 'differz'
|
5
|
+
|
6
|
+
include GLI::App
|
7
|
+
|
8
|
+
program_desc 'Compare two yaml-files and show the missing keys.'
|
9
|
+
|
10
|
+
version Differz::VERSION
|
11
|
+
|
12
|
+
desc 'Only show the difference between yaml-files without editing them'
|
13
|
+
command :show do |c|
|
14
|
+
c.action do |global_options, options, args|
|
15
|
+
puts Differz::Comparer.new(args[0], args[1]).show_diff
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
desc 'Allows you to fill missing keys in yaml file'
|
20
|
+
command :edit do |c|
|
21
|
+
c.action do |global_options, options, args|
|
22
|
+
puts "edit command"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
pre do |global,command,options,args|
|
27
|
+
true
|
28
|
+
end
|
29
|
+
|
30
|
+
post do |global,command,options,args|
|
31
|
+
end
|
32
|
+
|
33
|
+
on_error do |exception|
|
34
|
+
true
|
35
|
+
end
|
36
|
+
|
37
|
+
exit run(ARGV)
|
data/differz.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
require 'differz/version'
|
7
|
+
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = "differz"
|
10
|
+
spec.version = Differz::VERSION
|
11
|
+
spec.authors = ["HeeL"]
|
12
|
+
spec.email = ["parizhskiy@gmail.com"]
|
13
|
+
spec.description = %q{Compare two yaml-files and show the missing keys.}
|
14
|
+
spec.summary = %q{It shows the differences in keys of passed yaml-files.}
|
15
|
+
spec.homepage = "https://github.com/heel/differz"
|
16
|
+
spec.license = "MIT"
|
17
|
+
spec.files = `git ls-files`.split($/)
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_runtime_dependency('gli','2.8.1')
|
24
|
+
spec.bindir = 'bin'
|
25
|
+
spec.executables << 'differz'
|
26
|
+
end
|
data/lib/differz.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
module Differz
|
2
|
+
|
3
|
+
class Comparer
|
4
|
+
|
5
|
+
def initialize(file1, file2)
|
6
|
+
@file1 = file1
|
7
|
+
@file2 = file2
|
8
|
+
end
|
9
|
+
|
10
|
+
def show_diff
|
11
|
+
get_diffs.each do |diff|
|
12
|
+
puts diff.join(' -> ')
|
13
|
+
end
|
14
|
+
nil
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def get_diffs
|
20
|
+
hash_diff(read_yaml(@file1), read_yaml(@file2))
|
21
|
+
end
|
22
|
+
|
23
|
+
def read_yaml(file_path)
|
24
|
+
YAML.load(File.read(file_path))
|
25
|
+
end
|
26
|
+
|
27
|
+
def hash_diff(h1, h2, path = [])
|
28
|
+
diff = []
|
29
|
+
h1.each do |k, v|
|
30
|
+
if hash?(v)
|
31
|
+
diff += hash_diff(v, hash?(h2[k]) ? h2[k] : {}, path + [k])
|
32
|
+
elsif !h2.key?(k)
|
33
|
+
diff << path + [k]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
diff
|
37
|
+
end
|
38
|
+
|
39
|
+
def hash?(var)
|
40
|
+
var.is_a?(Hash)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: differz
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- HeeL
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-01 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.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: gli
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.8.1
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.8.1
|
55
|
+
description: Compare two yaml-files and show the missing keys.
|
56
|
+
email:
|
57
|
+
- parizhskiy@gmail.com
|
58
|
+
executables:
|
59
|
+
- differz
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/differz
|
69
|
+
- differz.gemspec
|
70
|
+
- lib/differz.rb
|
71
|
+
- lib/differz/comparer.rb
|
72
|
+
- lib/differz/version.rb
|
73
|
+
homepage: https://github.com/heel/differz
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.0.3
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: It shows the differences in keys of passed yaml-files.
|
97
|
+
test_files: []
|
98
|
+
has_rdoc:
|