to_simple_yaml 1.0.0
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 +8 -0
- data/.idea/.gitignore +2 -0
- data/.idea/.rakeTasks +7 -0
- data/.idea/inspectionProfiles/Project_Default.xml +6 -0
- data/.idea/misc.xml +7 -0
- data/.idea/modules.xml +8 -0
- data/.idea/to_simple_yaml.iml +14 -0
- data/.idea/vcs.xml +6 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +22 -0
- data/README.md +42 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/to_simple_yaml.rb +7 -0
- data/lib/to_simple_yaml/core.rb +67 -0
- data/lib/to_simple_yaml/version.rb +3 -0
- data/to_simple_yaml.gemspec +28 -0
- metadata +102 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: a67ff8dffb254b4d21e6768287ebd5130c35bbbe29182895f2a5661fe398aad5
|
|
4
|
+
data.tar.gz: 6ceb3aeb2a1126cdd56c6985e02bb90c7ad6d07d12b35eab9a0a1b8db86ec35f
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 26cf40a6980ef39d117e0f76c9b886e7825a14710ba89a13cebfd3136054a32e03b56a55a1d0a8a1a8b03e75c40e96509f9ee391e214274a112c4329236bad17
|
|
7
|
+
data.tar.gz: 936fce28ebe2e34d343fd9dde5aeee8aa3233c4355e8b7a2a6a5c4083a46d1b29b77edc742513292b137a82bea5c89e12171b8c2fab963252c1cd90eaa34f6bc
|
data/.gitignore
ADDED
data/.idea/.gitignore
ADDED
data/.idea/.rakeTasks
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<Settings><!--This file was automatically generated by Ruby plugin.
|
|
3
|
+
You are allowed to:
|
|
4
|
+
1. Remove rake task
|
|
5
|
+
2. Add existing rake tasks
|
|
6
|
+
To add existing rake tasks automatically delete this file and reload the project.
|
|
7
|
+
--><RakeGroup description="" fullCmd="" taksId="rake"><RakeTask description="Build to_simple_yaml-0.1.0.gem into the pkg directory" fullCmd="build" taksId="build" /><RakeTask description="Remove any temporary products" fullCmd="clean" taksId="clean" /><RakeTask description="Remove any generated files" fullCmd="clobber" taksId="clobber" /><RakeTask description="Build and install to_simple_yaml-0.1.0.gem into system gems" fullCmd="install" taksId="install" /><RakeGroup description="" fullCmd="" taksId="install"><RakeTask description="Build and install to_simple_yaml-0.1.0.gem into system gems without network access" fullCmd="install:local" taksId="local" /></RakeGroup><RakeTask description="Create tag v0.1.0 and build and push to_simple_yaml-0.1.0.gem to TODO: Set to 'http://mygemserver.com'" fullCmd="release[remote]" taksId="release[remote]" /><RakeTask description="Run tests" fullCmd="test" taksId="test" /><RakeTask description="" fullCmd="default" taksId="default" /><RakeTask description="" fullCmd="release" taksId="release" /><RakeGroup description="" fullCmd="" taksId="release"><RakeTask description="" fullCmd="release:guard_clean" taksId="guard_clean" /><RakeTask description="" fullCmd="release:rubygem_push" taksId="rubygem_push" /><RakeTask description="" fullCmd="release:source_control_push" taksId="source_control_push" /></RakeGroup></RakeGroup></Settings>
|
data/.idea/misc.xml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="JavaScriptSettings">
|
|
4
|
+
<option name="languageLevel" value="ES6" />
|
|
5
|
+
</component>
|
|
6
|
+
<component name="ProjectRootManager" version="2" project-jdk-name="rbenv: 2.6.2" project-jdk-type="RUBY_SDK" />
|
|
7
|
+
</project>
|
data/.idea/modules.xml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="ProjectModuleManager">
|
|
4
|
+
<modules>
|
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/to_simple_yaml.iml" filepath="$PROJECT_DIR$/.idea/to_simple_yaml.iml" />
|
|
6
|
+
</modules>
|
|
7
|
+
</component>
|
|
8
|
+
</project>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<module type="RUBY_MODULE" version="4">
|
|
3
|
+
<component name="ModuleRunConfigurationManager">
|
|
4
|
+
<shared />
|
|
5
|
+
</component>
|
|
6
|
+
<component name="NewModuleRootManager">
|
|
7
|
+
<content url="file://$MODULE_DIR$" />
|
|
8
|
+
<orderEntry type="inheritedJdk" />
|
|
9
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
|
10
|
+
<orderEntry type="library" scope="PROVIDED" name="bundler (v1.17.2, rbenv: 2.6.2) [gem]" level="application" />
|
|
11
|
+
<orderEntry type="library" scope="PROVIDED" name="minitest (v5.12.2, rbenv: 2.6.2) [gem]" level="application" />
|
|
12
|
+
<orderEntry type="library" scope="PROVIDED" name="rake (v10.5.0, rbenv: 2.6.2) [gem]" level="application" />
|
|
13
|
+
</component>
|
|
14
|
+
</module>
|
data/.idea/vcs.xml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
to_simple_yaml (0.1.0)
|
|
5
|
+
|
|
6
|
+
GEM
|
|
7
|
+
remote: https://rubygems.org/
|
|
8
|
+
specs:
|
|
9
|
+
minitest (5.12.2)
|
|
10
|
+
rake (10.5.0)
|
|
11
|
+
|
|
12
|
+
PLATFORMS
|
|
13
|
+
ruby
|
|
14
|
+
|
|
15
|
+
DEPENDENCIES
|
|
16
|
+
bundler (~> 1.17)
|
|
17
|
+
minitest (~> 5.0)
|
|
18
|
+
rake (~> 10.0)
|
|
19
|
+
to_simple_yaml!
|
|
20
|
+
|
|
21
|
+
BUNDLED WITH
|
|
22
|
+
1.17.2
|
data/README.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# ToSimpleYaml
|
|
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/to_simple_yaml`. 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 'to_simple_yaml'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
And then execute:
|
|
16
|
+
|
|
17
|
+
$ bundle
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
|
|
21
|
+
$ gem install to_simple_yaml
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
Can use method to to_simple_yaml in Hash,Struct and Array class.
|
|
25
|
+
```ruby
|
|
26
|
+
hash.to_simple_yaml
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
```ruby
|
|
30
|
+
{a: 'b'}.to_simple_yaml
|
|
31
|
+
# a: b
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Development
|
|
35
|
+
|
|
36
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
37
|
+
|
|
38
|
+
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).
|
|
39
|
+
|
|
40
|
+
## Contributing
|
|
41
|
+
|
|
42
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/tanmen/to_simple_yaml.
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "to_simple_yaml"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
class Struct
|
|
2
|
+
def to_simple_yaml(options = {})
|
|
3
|
+
generate_yaml(self, options)
|
|
4
|
+
end
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
class Array
|
|
8
|
+
def to_simple_yaml(options = {})
|
|
9
|
+
generate_yaml(self, options)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class Hash
|
|
14
|
+
def to_simple_yaml(options = {})
|
|
15
|
+
generate_yaml(self, options)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
class Object
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
def generate_yaml(obj, indent: 0, array: false)
|
|
23
|
+
if obj.is_a?(Hash)
|
|
24
|
+
yaml = ''
|
|
25
|
+
obj.keys.each_with_index do |key, index|
|
|
26
|
+
array_first = array && index == 0
|
|
27
|
+
array_inline = array && index != 0
|
|
28
|
+
if obj[key].is_a?(String) || obj[key].is_a?(Numeric)
|
|
29
|
+
yaml << template("#{array_first ? '- ' : ''}#{key}: #{obj[key]}", array_inline ? indent + 1 : indent)
|
|
30
|
+
elsif obj[key].is_a?(Symbol)
|
|
31
|
+
yaml << template("#{array_first ? '- ' : ''}#{key}: #{obj[key].to_s}", array_inline ? indent + 1 : indent)
|
|
32
|
+
elsif obj[key].is_a?(Array)
|
|
33
|
+
yaml << template("#{array_first ? '- ' : ''}#{key}:", array_inline ? indent + 1 : indent)
|
|
34
|
+
yaml << generate_yaml(obj[key], indent: array_inline ? indent + 2 : indent + 1)
|
|
35
|
+
else
|
|
36
|
+
yaml << template("#{array_first ? '- ' : ''}#{key}:", array_inline ? indent + 1 : indent)
|
|
37
|
+
yaml << generate_yaml(obj[key], indent: array_inline || array_first ? indent + 2 : indent + 1)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
yaml
|
|
41
|
+
elsif obj.is_a?(Array)
|
|
42
|
+
yaml = ''
|
|
43
|
+
obj.each do |value|
|
|
44
|
+
if value.is_a?(String) || value.is_a?(Numeric)
|
|
45
|
+
yaml << template("- #{value}", indent)
|
|
46
|
+
elsif value.is_a?(Symbol)
|
|
47
|
+
yaml << template("- #{value.to_s}", indent)
|
|
48
|
+
elsif value.is_a?(Array)
|
|
49
|
+
yaml << template('-', indent)
|
|
50
|
+
yaml << generate_yaml(value, indent: indent + 1)
|
|
51
|
+
else
|
|
52
|
+
yaml << generate_yaml(value, indent: indent, array: true)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
yaml
|
|
56
|
+
elsif obj.is_a?(Struct)
|
|
57
|
+
generate_yaml(Hash[obj.each_pair.to_a], indent: indent, array: array)
|
|
58
|
+
else
|
|
59
|
+
raise SimpleYaml::NoImplementError.new('have no implement to_simple_yaml error')
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def template(value, indent)
|
|
64
|
+
"#{[].fill(' ', 0...indent).join('')}#{value}\n"
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
|
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require "to_simple_yaml/version"
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "to_simple_yaml"
|
|
8
|
+
spec.version = ToSimpleYaml::VERSION
|
|
9
|
+
spec.authors = ["tanmen"]
|
|
10
|
+
spec.email = ["yt.prog@gmail.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = "simpler output than to_yaml"
|
|
13
|
+
spec.description = "simpler output than to_yaml"
|
|
14
|
+
spec.homepage = "https://github.com/tanmen/to_simple_yaml"
|
|
15
|
+
|
|
16
|
+
# Specify which files should be added to the gem when it is released.
|
|
17
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
18
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
|
19
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
20
|
+
end
|
|
21
|
+
spec.bindir = "exe"
|
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
23
|
+
spec.require_paths = ["lib"]
|
|
24
|
+
|
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
27
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
|
28
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: to_simple_yaml
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- tanmen
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2019-11-05 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: minitest
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '5.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '5.0'
|
|
55
|
+
description: simpler output than to_yaml
|
|
56
|
+
email:
|
|
57
|
+
- yt.prog@gmail.com
|
|
58
|
+
executables: []
|
|
59
|
+
extensions: []
|
|
60
|
+
extra_rdoc_files: []
|
|
61
|
+
files:
|
|
62
|
+
- ".gitignore"
|
|
63
|
+
- ".idea/.gitignore"
|
|
64
|
+
- ".idea/.rakeTasks"
|
|
65
|
+
- ".idea/inspectionProfiles/Project_Default.xml"
|
|
66
|
+
- ".idea/misc.xml"
|
|
67
|
+
- ".idea/modules.xml"
|
|
68
|
+
- ".idea/to_simple_yaml.iml"
|
|
69
|
+
- ".idea/vcs.xml"
|
|
70
|
+
- Gemfile
|
|
71
|
+
- Gemfile.lock
|
|
72
|
+
- README.md
|
|
73
|
+
- Rakefile
|
|
74
|
+
- bin/console
|
|
75
|
+
- bin/setup
|
|
76
|
+
- lib/to_simple_yaml.rb
|
|
77
|
+
- lib/to_simple_yaml/core.rb
|
|
78
|
+
- lib/to_simple_yaml/version.rb
|
|
79
|
+
- to_simple_yaml.gemspec
|
|
80
|
+
homepage: https://github.com/tanmen/to_simple_yaml
|
|
81
|
+
licenses: []
|
|
82
|
+
metadata: {}
|
|
83
|
+
post_install_message:
|
|
84
|
+
rdoc_options: []
|
|
85
|
+
require_paths:
|
|
86
|
+
- lib
|
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
88
|
+
requirements:
|
|
89
|
+
- - ">="
|
|
90
|
+
- !ruby/object:Gem::Version
|
|
91
|
+
version: '0'
|
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - ">="
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '0'
|
|
97
|
+
requirements: []
|
|
98
|
+
rubygems_version: 3.0.3
|
|
99
|
+
signing_key:
|
|
100
|
+
specification_version: 4
|
|
101
|
+
summary: simpler output than to_yaml
|
|
102
|
+
test_files: []
|