diffable_yaml 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +34 -0
- data/Gemfile +4 -0
- data/LICENSE +28 -0
- data/README.md +2 -0
- data/Rakefile +6 -0
- data/diffable_yaml.gemspec +40 -0
- data/lib/diffable_yaml/version.rb +3 -0
- data/lib/diffable_yaml.rb +105 -0
- metadata +101 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9ede5b1945e4249a0b29dd466e7263ea5feb7b59
|
4
|
+
data.tar.gz: 93551e520ff49a88346cbd946e90a0e835ff5baf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 89562fddf48689216c8345ba7fe9de12561d4192093cc4a48c128092e5f64b7d2a2ad326e3759cd0659b76cb397e8949a0380ed4538874a35d6b8ed2499cde80
|
7
|
+
data.tar.gz: dc21e0b117ba61aecb1b5b8fc8df406e0944a78d5d368d8b733f29e498321e4d1ef2c1219e6e0f228393b9360f7fb7e229d1487fcd0aa8bf4387d15a08cd85c1
|
data/.gitignore
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/lib/bundler/man/
|
26
|
+
|
27
|
+
# for a library or gem, you might want to ignore these files since the code is
|
28
|
+
# intended to run in multiple environments; otherwise, check them in:
|
29
|
+
Gemfile.lock
|
30
|
+
.ruby-version
|
31
|
+
.ruby-gemset
|
32
|
+
|
33
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
34
|
+
.rvmrc
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
Copyright (c) 2015, nrser
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
* Redistributions of source code must retain the above copyright notice, this
|
8
|
+
list of conditions and the following disclaimer.
|
9
|
+
|
10
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
11
|
+
this list of conditions and the following disclaimer in the documentation
|
12
|
+
and/or other materials provided with the distribution.
|
13
|
+
|
14
|
+
* Neither the name of DiffableYAML nor the names of its
|
15
|
+
contributors may be used to endorse or promote products derived from
|
16
|
+
this software without specific prior written permission.
|
17
|
+
|
18
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
19
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
20
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
21
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
22
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
23
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
24
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
25
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
26
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
27
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
28
|
+
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'diffable_yaml/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'diffable_yaml'
|
8
|
+
spec.version = DiffableYAML::VERSION
|
9
|
+
spec.authors = ["nrser"]
|
10
|
+
spec.email = 'neil@ztkae.com'
|
11
|
+
spec.summary = "dump YAML in Ruby with hash keys ordered to make text diffs easier"
|
12
|
+
spec.description = <<-EOS
|
13
|
+
this is a little chunck of code i use to dump Ruby objects to YAML with Hash
|
14
|
+
keys in a some-what consistent order.
|
15
|
+
|
16
|
+
i do this because i often find myself using YAML files as data storage and
|
17
|
+
this makes it a lot easier to compare versions with text-based diff toolspec.
|
18
|
+
|
19
|
+
this lib is horribly alpha and has no tests what-so-ever. i'm sure it's
|
20
|
+
as full or bugs and bad ideas as 100 lines of code can be. i just put it
|
21
|
+
here so it's easier for me to use across projectspec. but you're welcome
|
22
|
+
to take it for a spin too if you really want.
|
23
|
+
|
24
|
+
this relies on Psych internals, so it has a dependency on pysch ~> 2.0.
|
25
|
+
it might work fine with other versions; that's just all i've tested it
|
26
|
+
against at the moment.
|
27
|
+
EOS
|
28
|
+
spec.homepage = 'https://github.com/nrser/DiffableYAML'
|
29
|
+
spec.license = 'BSD'
|
30
|
+
|
31
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
32
|
+
spec.bindir = "exe"
|
33
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
34
|
+
spec.require_paths = ["lib"]
|
35
|
+
|
36
|
+
spec.add_dependency 'psych', '~> 2.0'
|
37
|
+
|
38
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
39
|
+
spec.add_development_dependency "rake"
|
40
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'psych'
|
2
|
+
|
3
|
+
require 'diffable_yaml/version'
|
4
|
+
|
5
|
+
module DiffableYAML
|
6
|
+
# this dumps YAML with hashes / dicts in a consistent order so that
|
7
|
+
# text diffs make more sense
|
8
|
+
class DiffableYAMLTree < Psych::Visitors::YAMLTree
|
9
|
+
def self.create options = {}, emitter = nil
|
10
|
+
preorder = options.delete(:preorder) || []
|
11
|
+
instance = Psych::Visitors::YAMLTree.create options, emitter
|
12
|
+
instance.instance_variable_set '@preorder', preorder
|
13
|
+
instance
|
14
|
+
end
|
15
|
+
|
16
|
+
def visit_Hash o
|
17
|
+
tag = o.class == ::Hash ? nil : "!ruby/hash:#{o.class}"
|
18
|
+
implicit = !tag
|
19
|
+
|
20
|
+
register(o, @emitter.start_mapping( nil,
|
21
|
+
tag,
|
22
|
+
implicit,
|
23
|
+
Psych::Nodes::Mapping::BLOCK))
|
24
|
+
|
25
|
+
@preorder.each do |key|
|
26
|
+
if o.key? key
|
27
|
+
accept key
|
28
|
+
accept o[key]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
o.keys.map {|k|
|
32
|
+
[k, k.to_s]
|
33
|
+
}.sort {|(k_a, s_a), (k_b, s_b)|
|
34
|
+
s_a <=> s_b
|
35
|
+
}.each do |k, s|
|
36
|
+
unless @preorder.include? k
|
37
|
+
accept k
|
38
|
+
accept o[k]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
@emitter.end_mapping
|
43
|
+
end
|
44
|
+
|
45
|
+
def visit_String o
|
46
|
+
plain = false
|
47
|
+
quote = false
|
48
|
+
style = Psych::Nodes::Scalar::ANY
|
49
|
+
|
50
|
+
if binary?(o)
|
51
|
+
str = [o].pack('m').chomp
|
52
|
+
tag = '!binary' # FIXME: change to below when syck is removed
|
53
|
+
#tag = 'tag:yaml.org,2002:binary'
|
54
|
+
style = Psych::Nodes::Scalar::LITERAL
|
55
|
+
else
|
56
|
+
str = o
|
57
|
+
tag = nil
|
58
|
+
quote = !(String === @ss.tokenize(o))
|
59
|
+
plain = !quote
|
60
|
+
if str.index("\n")
|
61
|
+
style = Psych::Nodes::Scalar::LITERAL
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
ivars = find_ivars o
|
66
|
+
|
67
|
+
if ivars.empty?
|
68
|
+
unless o.class == ::String
|
69
|
+
tag = "!ruby/string:#{o.class}"
|
70
|
+
end
|
71
|
+
@emitter.scalar str, nil, tag, plain, quote, style
|
72
|
+
else
|
73
|
+
maptag = '!ruby/string'
|
74
|
+
maptag << ":#{o.class}" unless o.class == ::String
|
75
|
+
|
76
|
+
register o, @emitter.start_mapping( nil,
|
77
|
+
maptag,
|
78
|
+
false,
|
79
|
+
Pysch::Nodes::Mapping::BLOCK)
|
80
|
+
@emitter.scalar 'str',
|
81
|
+
nil,
|
82
|
+
nil,
|
83
|
+
true,
|
84
|
+
false,
|
85
|
+
Psych::Nodes::Scalar::ANY
|
86
|
+
@emitter.scalar str, nil, tag, plain, quote, style
|
87
|
+
|
88
|
+
dump_ivars o
|
89
|
+
|
90
|
+
@emitter.end_mapping
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def self.dump(o, io = nil, options = {})
|
96
|
+
if Hash === io
|
97
|
+
options = io
|
98
|
+
io = nil
|
99
|
+
end
|
100
|
+
|
101
|
+
visitor = DiffableYAMLTree.create options
|
102
|
+
visitor << o
|
103
|
+
visitor.tree.yaml io, options
|
104
|
+
end
|
105
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: diffable_yaml
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- nrser
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: psych
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.5'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: "this is a little chunck of code i use to dump Ruby objects to YAML with
|
56
|
+
Hash\nkeys in a some-what consistent order.\n\ni do this because i often find myself
|
57
|
+
using YAML files as data storage and \nthis makes it a lot easier to compare versions
|
58
|
+
with text-based diff toolspec.\n\nthis lib is horribly alpha and has no tests what-so-ever.
|
59
|
+
i'm sure it's\nas full or bugs and bad ideas as 100 lines of code can be. i just
|
60
|
+
put it\nhere so it's easier for me to use across projectspec. but you're welcome\nto
|
61
|
+
take it for a spin too if you really want.\n\nthis relies on Psych internals, so
|
62
|
+
it has a dependency on pysch ~> 2.0.\nit might work fine with other versions; that's
|
63
|
+
just all i've tested it\nagainst at the moment.\n"
|
64
|
+
email: neil@ztkae.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- ".gitignore"
|
70
|
+
- Gemfile
|
71
|
+
- LICENSE
|
72
|
+
- README.md
|
73
|
+
- Rakefile
|
74
|
+
- diffable_yaml.gemspec
|
75
|
+
- lib/diffable_yaml.rb
|
76
|
+
- lib/diffable_yaml/version.rb
|
77
|
+
homepage: https://github.com/nrser/DiffableYAML
|
78
|
+
licenses:
|
79
|
+
- BSD
|
80
|
+
metadata: {}
|
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.2.2
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: dump YAML in Ruby with hash keys ordered to make text diffs easier
|
101
|
+
test_files: []
|