nx-yaml 1.0.3

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: ef34a5526be2214ea4461bc0ebd557d8a31756c5978556ce816c67cd4f8bb711
4
+ data.tar.gz: 4452033b85c4160165a3fbe02140a5595f0d360b1b239337e1da27c8b1b36bb1
5
+ SHA512:
6
+ metadata.gz: 420e36d7e6990f962dd0bbee26b417ac02e382f54addd0b356214c11eae31ee6f28de3331dcfe848d6daeef4c9906b36bd6e741ca3923d70d70b2e51f89e1784
7
+ data.tar.gz: 9be5529f2ef7d9aa7d7e1469585e3d83c6fd1aee97d0750548ea026ddfce0f68be8ccb94ad1cc578478ef96a9c3f28a64bb190cc2a6c9e6dc9af605103be9dad
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
data/.npmrc ADDED
@@ -0,0 +1,2 @@
1
+ sass_binary_site=https://npm.taobao.org/mirrors/node-sass/
2
+ package-lock=false
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in templates.gemspec
4
+ gemspec
5
+ gem "yaml"
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # nx-yaml
2
+ > Nx yaml tools.
3
+
4
+ ## installation
5
+ ```rb
6
+ # from gem
7
+ gem 'nx-yaml'
8
+ # from git
9
+ gem 'nx-yaml', git: 'git@github.com:afeiship/nx-yaml.git'
10
+ ```
11
+
12
+ ## usage
13
+ ```rb
14
+ Nx::Yaml.load('./template.yml', { name: 'my-template', description: 'Awesome template'})
15
+ ```
16
+
17
+ ## template.yml
18
+ ```yml
19
+ name: <%= name %>
20
+ description: <%= description %>
21
+ version: 1.0.0
22
+ ```
23
+
24
+ <!-- After load -->
25
+ ```yml
26
+ name: my-template
27
+ description: Awesome template
28
+ version: 1.0.0
29
+ ```
30
+
31
+ ## build/publish
32
+ ```shell
33
+ # build
34
+ gem build nx-yaml.gemspec
35
+
36
+ # publish
37
+ gem push nx-yaml-0.1.0.gem
38
+ ```
39
+
40
+ ## rspec
41
+ - https://rspec.info/
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,25 @@
1
+ require_relative "../lib/nx-yaml"
2
+
3
+ RSpec.describe Nx do
4
+ describe "# basic test" do
5
+ it "load yml with hash data" do
6
+ path = File.join(File.dirname(__FILE__), "template_with_var.yml")
7
+ res = Nx::Yaml.load(path, { host: "0.0.0.0" })
8
+ expect(res).to eq(
9
+ "name" => "nx-yml",
10
+ "version" => "0.1.0",
11
+ "env" => { "home" => ENV["HOME"] },
12
+ "host" => "0.0.0.0",
13
+ )
14
+ end
15
+
16
+ it "load yml without data" do
17
+ path = File.join(File.dirname(__FILE__), "template_pure.yml")
18
+ res = Nx::Yaml.load(path)
19
+ expect(res).to eq(
20
+ "name" => "nx-yml",
21
+ "version" => "0.1.0",
22
+ )
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,93 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
16
+ RSpec.configure do |config|
17
+ # rspec-expectations config goes here. You can use an alternate
18
+ # assertion/expectation library such as wrong or the stdlib/minitest
19
+ # assertions if you prefer.
20
+ config.expect_with :rspec do |expectations|
21
+ # This option will default to `true` in RSpec 4. It makes the `description`
22
+ # and `failure_message` of custom matchers include text for helper methods
23
+ # defined using `chain`, e.g.:
24
+ # be_bigger_than(2).and_smaller_than(4).description
25
+ # # => "be bigger than 2 and smaller than 4"
26
+ # ...rather than:
27
+ # # => "be bigger than 2"
28
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
29
+ end
30
+
31
+ # rspec-mocks config goes here. You can use an alternate test double
32
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
33
+ config.mock_with :rspec do |mocks|
34
+ # Prevents you from mocking or stubbing a method that does not exist on
35
+ # a real object. This is generally recommended, and will default to
36
+ # `true` in RSpec 4.
37
+ mocks.verify_partial_doubles = true
38
+ end
39
+
40
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
41
+ # have no way to turn it off -- the option exists only for backwards
42
+ # compatibility in RSpec 3). It causes shared context metadata to be
43
+ # inherited by the metadata hash of host groups and examples, rather than
44
+ # triggering implicit auto-inclusion in groups with matching metadata.
45
+ config.shared_context_metadata_behavior = :apply_to_host_groups
46
+
47
+ # The settings below are suggested to provide a good initial experience
48
+ # with RSpec, but feel free to customize to your heart's content.
49
+ =begin
50
+ # This allows you to limit a spec run to individual examples or groups
51
+ # you care about by tagging them with `:focus` metadata. When nothing
52
+ # is tagged with `:focus`, all examples get run. RSpec also provides
53
+ # aliases for `it`, `describe`, and `context` that include `:focus`
54
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
55
+ config.filter_run_when_matching :focus
56
+ # Allows RSpec to persist some state between runs in order to support
57
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
58
+ # you configure your source control system to ignore this file.
59
+ config.example_status_persistence_file_path = "spec/examples.txt"
60
+ # Limits the available syntax to the non-monkey patched syntax that is
61
+ # recommended. For more details, see:
62
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
63
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
64
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
65
+ config.disable_monkey_patching!
66
+ # This setting enables warnings. It's recommended, but in some cases may
67
+ # be too noisy due to issues in dependencies.
68
+ config.warnings = true
69
+ # Many RSpec users commonly either run the entire suite or an individual
70
+ # file, and it's useful to allow more verbose output when running an
71
+ # individual spec file.
72
+ if config.files_to_run.one?
73
+ # Use the documentation formatter for detailed output,
74
+ # unless a formatter has already been configured
75
+ # (e.g. via a command-line flag).
76
+ config.default_formatter = "doc"
77
+ end
78
+ # Print the 10 slowest examples and example groups at the
79
+ # end of the spec run, to help surface which specs are running
80
+ # particularly slow.
81
+ config.profile_examples = 10
82
+ # Run specs in random order to surface order dependencies. If you find an
83
+ # order dependency and want to debug it, you can fix the order by providing
84
+ # the seed, which is printed after each run.
85
+ # --seed 1234
86
+ config.order = :random
87
+ # Seed global randomization in this process using the `--seed` CLI option.
88
+ # Setting this allows you to use `--seed` to deterministically reproduce
89
+ # test failures related to randomization by passing the same `--seed` value
90
+ # as the one that triggered the failure.
91
+ Kernel.srand config.seed
92
+ =end
93
+ end
@@ -0,0 +1,2 @@
1
+ name: nx-yml
2
+ version: 0.1.0
@@ -0,0 +1,5 @@
1
+ name: nx-yml
2
+ version: 0.1.0
3
+ env:
4
+ home: <%= ENV["HOME"] %>
5
+ host: <%= host %>
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "nx-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,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
data/lib/nx-yaml.rb ADDED
@@ -0,0 +1,2 @@
1
+ require_relative "./nx/version"
2
+ require_relative "./nx/yaml"
data/lib/nx/version.rb ADDED
@@ -0,0 +1,5 @@
1
+ module Nx
2
+ class Yaml
3
+ VERSION = "1.0.3"
4
+ end
5
+ end
data/lib/nx/yaml.rb ADDED
@@ -0,0 +1,25 @@
1
+ require "yaml"
2
+ require "erb"
3
+ require "ostruct"
4
+
5
+ # https://stackoverflow.com/questions/8954706/render-an-erb-template-with-values-from-a-hash
6
+
7
+ module Nx
8
+ class ErbalT < OpenStruct
9
+ def render(template)
10
+ ERB.new(template).result(binding)
11
+ end
12
+
13
+ def self.render_from_hash(template, hash)
14
+ ErbalT.new(hash).render(template)
15
+ end
16
+ end
17
+
18
+ class Yaml
19
+ def self.load(in_path, in_data = nil)
20
+ raw_content = File.read(in_path)
21
+ str = in_data.nil? ? raw_content : ErbalT::render_from_hash(raw_content, in_data)
22
+ YAML::load str
23
+ end
24
+ end
25
+ end
data/nx-yaml.gemspec ADDED
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "nx/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "nx-yaml"
8
+ spec.version = Nx::Yaml::VERSION
9
+ spec.licenses = ["MIT"]
10
+ spec.authors = ["afeiship"]
11
+ spec.email = ["1290657123@qq.com"]
12
+
13
+ spec.summary = %q{Nx yaml tools.}
14
+ spec.description = %q{Nx yaml tools.}
15
+ spec.homepage = "https://github.com/afeiship/nx-yaml"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bump"
34
+ spec.add_development_dependency "bundler", "~> 1.14"
35
+ spec.add_development_dependency "rake", "~> 12.3", ">= 12.3.3"
36
+ end
data/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "nx-yaml",
3
+ "version": "1.0.3",
4
+ "description": "Nx yaml tools.",
5
+ "directories": {
6
+ "lib": "lib"
7
+ },
8
+ "scripts": {
9
+ "clean": "rm -rf *.gem",
10
+ "test": "rspec __tests__",
11
+ "patch": "yarn version --patch --no-git-tag-version",
12
+ "build": "gem build *.gemspec",
13
+ "pubpush": "gem push *.gem",
14
+ "unpublish": "gem yank nx-yaml -v '0.1.3'"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/afeiship/nx-yaml.git"
19
+ },
20
+ "author": "afei",
21
+ "license": "MIT",
22
+ "bugs": {
23
+ "url": "https://github.com/afeiship/nx-yaml/issues"
24
+ },
25
+ "homepage": "https://github.com/afeiship/nx-yaml#readme"
26
+ }
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nx-yaml
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.3
5
+ platform: ruby
6
+ authors:
7
+ - afeiship
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-04-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bump
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: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.14'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.14'
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.3'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 12.3.3
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '12.3'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 12.3.3
61
+ description: Nx yaml tools.
62
+ email:
63
+ - 1290657123@qq.com
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - ".gitignore"
69
+ - ".npmrc"
70
+ - Gemfile
71
+ - README.md
72
+ - Rakefile
73
+ - __tests__/nx_yaml_spec.rb
74
+ - __tests__/spec_helper.rb
75
+ - __tests__/template_pure.yml
76
+ - __tests__/template_with_var.yml
77
+ - bin/console
78
+ - bin/setup
79
+ - lib/nx-yaml.rb
80
+ - lib/nx/version.rb
81
+ - lib/nx/yaml.rb
82
+ - nx-yaml-0.1.0.gem
83
+ - nx-yaml.gemspec
84
+ - package.json
85
+ homepage: https://github.com/afeiship/nx-yaml
86
+ licenses:
87
+ - MIT
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubygems_version: 3.0.3
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: Nx yaml tools.
108
+ test_files: []