yaml_ref 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: ad52297c8836ced1bb7313a83cf608d79de8a441d624cecb3c15ee415040c73b
4
+ data.tar.gz: 7aa1fd3d1bc58b4e7a785d5995ec8047feb14835c4fe1d8d32376b8502a91045
5
+ SHA512:
6
+ metadata.gz: f11e54c4c6937f0451f2d8c4cf722552d9c85e2383e54177da055334823ed9e9b8f01fd44edaf9b18160694f39c84490793e8da84874182ccd20a57df1dea9ee
7
+ data.tar.gz: 17e0633f6956ad24aaf0939a2e1f619a2677b53d9955b87b5305b0645b69aa52b0460e4cc2d4a4ea1c5f14a01916908434957f5eed78741ba42e5872f50680f5
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /vendor/bundle
3
+ /.yardoc
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .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,8 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.0
6
+ before_install: gem install bundler -v 2.1.2
7
+ script:
8
+ - bundle exec rspec
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at tomisuker16@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in yaml_ref.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,45 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ yaml_ref (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ byebug (11.1.1)
10
+ coderay (1.1.2)
11
+ diff-lcs (1.3)
12
+ method_source (0.9.2)
13
+ pry (0.12.2)
14
+ coderay (~> 1.1.0)
15
+ method_source (~> 0.9.0)
16
+ pry-byebug (3.8.0)
17
+ byebug (~> 11.0)
18
+ pry (~> 0.10)
19
+ rake (12.3.3)
20
+ rspec (3.9.0)
21
+ rspec-core (~> 3.9.0)
22
+ rspec-expectations (~> 3.9.0)
23
+ rspec-mocks (~> 3.9.0)
24
+ rspec-core (3.9.1)
25
+ rspec-support (~> 3.9.1)
26
+ rspec-expectations (3.9.0)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.9.0)
29
+ rspec-mocks (3.9.1)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.9.0)
32
+ rspec-support (3.9.2)
33
+
34
+ PLATFORMS
35
+ ruby
36
+
37
+ DEPENDENCIES
38
+ pry
39
+ pry-byebug
40
+ rake (~> 12.0)
41
+ rspec (~> 3.0)
42
+ yaml_ref!
43
+
44
+ BUNDLED WITH
45
+ 2.1.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 atomiyama
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,97 @@
1
+ [![Build Status](https://travis-ci.org/atomiyama/yaml_ref.svg?branch=master)](https://travis-ci.org/atomiyama/yaml_ref)
2
+
3
+ # YamlRef
4
+
5
+ YamlRef allows you to define $ref that refers file with relative path.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'yaml_ref'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install yaml_ref
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ require 'yaml_ref'
27
+
28
+ YamlRef.load_file("/path/to/yaml")
29
+ ```
30
+
31
+ It has the following effects:
32
+
33
+ ```yaml
34
+ gem:
35
+ name: YamlRef
36
+ information:
37
+ $ref: '../information.yml'
38
+ license:
39
+ $ref: '#/schema/MIT'
40
+ releases:
41
+ - $ref: '../releases/0_0_1.yml'
42
+ ```
43
+
44
+ ```yaml
45
+ gem:
46
+ name: YamlRef
47
+ information:
48
+ # contents of information.yaml
49
+ summary: "YAML file ref resolver"
50
+ description: "Expand the $ref that refers to the file in the yaml file."
51
+ license:
52
+ $ref: '#/schema/MIT'
53
+ releases:
54
+ # contents of realeases/0_0_1.yaml
55
+ - version: "0.0.1"
56
+ features:
57
+ vision: 'Allow file $ref with relative path.'
58
+ authors:
59
+ - 'atomiyama'
60
+
61
+ ```
62
+
63
+ ### Relative path home.
64
+ If ref path(e.g. `$ref: 'path/to/file/from/specific/location'`) is defined as a relative path from a specific location.
65
+ Pass `ref_home` keyword argument or define ref_home on root level in YAML file it works fine.
66
+
67
+ ```ruby
68
+ # ref_home argument
69
+ YamlRef.load_file("/path/to/yaml", ref_home: "/path/to/ref_home")
70
+ ```
71
+
72
+ ```yaml
73
+ # ~/home.yml
74
+ ref_home: "~"
75
+ yaml_ref:
76
+ # This $ref will expand ~/reference.yml
77
+ $ref: 'reference.yml'
78
+ ```
79
+
80
+ ## Development
81
+
82
+ 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.
83
+
84
+ 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).
85
+
86
+ ## Contributing
87
+
88
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/yaml_ref_resolver. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/yaml_ref_resolver/blob/master/CODE_OF_CONDUCT.md).
89
+
90
+
91
+ ## License
92
+
93
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
94
+
95
+ ## Code of Conduct
96
+
97
+ Everyone interacting in the YamlRefResolver project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/yaml_ref_resolver/blob/master/CODE_OF_CONDUCT.md).
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/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "yaml_ref"
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
+ require "pry"
10
+ Pry.start
data/bin/setup ADDED
@@ -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,3 @@
1
+ module YamlRef
2
+ VERSION = "0.1.0"
3
+ end
data/lib/yaml_ref.rb ADDED
@@ -0,0 +1,94 @@
1
+ require "yaml_ref/version"
2
+ require "yaml"
3
+
4
+ module YamlRef
5
+ class Error < StandardError; end
6
+
7
+ class << self
8
+ #
9
+ # @params [String] path
10
+ # @return [Object]
11
+ #
12
+ # If ref path is defined as a relative path from a specific location,
13
+ # pass ref_home argument or define ref_home on root level in YAML file.
14
+ #
15
+ def load_file(path, ref_home: nil)
16
+ schema = YAML.load_file(path)
17
+ @ref_home = ref_home || schema["ref_home"]
18
+ parse_schema(schema, path)
19
+ end
20
+
21
+ private
22
+
23
+ #
24
+ # @private
25
+ #
26
+ # @params [Array | Hash] schema
27
+ # @params [String] path]
28
+ #
29
+ # @return [Array | hash]
30
+ #
31
+ def parse_schema(schema, path)
32
+ case
33
+ when schema.is_a?(Hash)
34
+ parse_hash_schema(schema, path)
35
+ when schema.is_a?(Array)
36
+ parse_array_schema(schema, path)
37
+ else
38
+ schema
39
+ end
40
+ end
41
+
42
+ #
43
+ # @private
44
+ #
45
+ # @params [Hash] schema
46
+ # @params [String] path
47
+ #
48
+ # @return [hash]
49
+ #
50
+ def parse_hash_schema(schema, path)
51
+ schema.inject({}) do |hash, (key, value)|
52
+ # in this case, value must be String.
53
+ if key == "$ref"
54
+ if value.start_with?("#")
55
+ # It does not be resolved because
56
+ # Most Services, such as swaggerUI,
57
+ # provide the feature to resolve json key references.
58
+ # e.g.
59
+ # $ref: "#/components/schemas/User"
60
+ break { key => value }
61
+ else
62
+ # Value can be file path.
63
+ # e.g.
64
+ # $ref: "../reference.yml"
65
+ break parse_schema(*file_ref(path, value))
66
+ end
67
+ else
68
+ hash[key] = parse_schema(value, path)
69
+ hash
70
+ end
71
+ end
72
+ end
73
+
74
+ #
75
+ # @private
76
+ #
77
+ # @params [Array] schema
78
+ # @params [String] path
79
+ #
80
+ # @return [Array]
81
+ #
82
+ def parse_array_schema(schema, path)
83
+ schema.inject([]) do |array, element|
84
+ array << parse_schema(element, path)
85
+ array
86
+ end
87
+ end
88
+
89
+ def file_ref(filepath, refpath)
90
+ path = File.expand_path(File.join(@ref_home || filepath, refpath))
91
+ [YAML.load_file(path), path]
92
+ end
93
+ end
94
+ end
data/yaml_ref.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ require_relative 'lib/yaml_ref/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "yaml_ref"
5
+ spec.version = YamlRef::VERSION
6
+ spec.authors = ["atomiyama"]
7
+ spec.email = ["tomisuker16@gmail.com"]
8
+
9
+ spec.summary = "YAML file ref resolver"
10
+ spec.description = "Allow file $ref with relative path"
11
+ spec.homepage = "https://github.com/atomiyama/yaml_ref"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ # Specify which files should be added to the gem when it is released.
16
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
17
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
18
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "pry"
25
+ spec.add_development_dependency "pry-byebug"
26
+ spec.add_development_dependency "rake", "~> 12.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yaml_ref
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - atomiyama
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-02-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pry
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry-byebug
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: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '12.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '12.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: Allow file $ref with relative path
70
+ email:
71
+ - tomisuker16@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - Gemfile.lock
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/setup
87
+ - lib/yaml_ref.rb
88
+ - lib/yaml_ref/version.rb
89
+ - yaml_ref.gemspec
90
+ homepage: https://github.com/atomiyama/yaml_ref
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 2.3.0
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubygems_version: 3.1.2
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: YAML file ref resolver
113
+ test_files: []