yerbish 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a9f4156bbef5616be4f951d0d7a0c1fad4684183
4
+ data.tar.gz: e9099ece42113b2c23b372ba914b55ddd075ab6e
5
+ SHA512:
6
+ metadata.gz: 699b0fdd7585a6fe096291097d573ddeefdfec903fb997d5e9a03dc847ef86d320ad63bb865e3eec56edb34c3e2a71905382aafd34268fae6ebf5bea8f0de2e5
7
+ data.tar.gz: 0603ad7278aa9ef808cd3ecf4fc3ad9ffebe36cd585a3b0f4929399872b7fef827d2af33a25c86a2ffdb4afa36bc7c550ae394720f5ac3999d23dc1c60f14030
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
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/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.2
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Dave Willkomm
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Yerbish [![Build Status](https://travis-ci.org/dinosaurjr10/yerbish.svg?branch=master)](http://travis-ci.org/dinosaurjr10/yerbish) [![Coverage Status](https://img.shields.io/coveralls/dinosaurjr10/yerbish.svg)](https://coveralls.io/r/dinosaurjr10/yerbish?branch=master)
2
+
3
+ YAML with embedded Ruby
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'yerbish'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install yerbish
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/yerbish/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
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
@@ -0,0 +1,3 @@
1
+ module Yerbish
2
+ VERSION = "0.0.1"
3
+ end
data/lib/yerbish.rb ADDED
@@ -0,0 +1,49 @@
1
+ require 'erb'
2
+ require 'json'
3
+ require 'yaml'
4
+ require 'yerbish/version'
5
+
6
+ module Yerbish
7
+ FILE_EXTENSION = '.yml.erb'
8
+
9
+ attr_accessor :base_path
10
+
11
+ def create_binding(base_path, local_variables = {})
12
+ b = TOPLEVEL_BINDING.dup
13
+ b.eval 'include Yerbish'
14
+ local_variables.each { |k,v| b.local_variable_set k, v }
15
+ b.eval "self.base_path = '#{base_path}'"
16
+ b
17
+ end
18
+
19
+ # Interprets the specified file's embedded Ruby, parsing the result as YAML and returning the resulting data
20
+ # structure.
21
+ def load(file_path, local_variables = {})
22
+ yaml = render file_path, local_variables
23
+ YAML.load yaml
24
+ end
25
+
26
+ # Interprets the specified file's embedded Ruby and returns the resulting (YAML) string.
27
+ def render(file_path, local_variables = {})
28
+ absolute_path = File.expand_path file_path, base_path
29
+ absolute_path += FILE_EXTENSION unless absolute_path.end_with?(FILE_EXTENSION)
30
+ file_content = File.read absolute_path
31
+ erb = ERB.new file_content
32
+ erb.result create_binding(base_path, local_variables)
33
+ end
34
+
35
+ # Interprets the specified file's embedded Ruby, parsing the result as YAML and returning it formatted as JSON.
36
+ def render_json(file_path, local_variables = {})
37
+ object = load file_path, local_variables
38
+ JSON.pretty_generate object
39
+ end
40
+
41
+ module_function(
42
+ :base_path,
43
+ :base_path=,
44
+ :create_binding,
45
+ :load,
46
+ :render,
47
+ :render_json,
48
+ )
49
+ end
@@ -0,0 +1,87 @@
1
+ require 'spec_helper'
2
+ require 'yerbish'
3
+
4
+ describe Yerbish do
5
+ let(:test_local_variables) { { test_local_variable: 'test-local-variable-value' } }
6
+
7
+ describe '#create_binding' do
8
+ subject { described_class.create_binding 'test-base-path', test_local_variable: 'test-local-variable-value' }
9
+
10
+ it 'should mix in Yerbish' do
11
+ expect(subject.eval 'self.private_methods').to include :base_path
12
+ expect(subject.eval 'self.private_methods').to include :base_path=
13
+ expect(subject.eval 'self.private_methods').to include :create_binding
14
+ expect(subject.eval 'self.private_methods').to include :load
15
+ expect(subject.eval 'self.private_methods').to include :render
16
+ expect(subject.eval 'self.private_methods').to include :render_json
17
+ end
18
+
19
+ it 'should set the specified local variables' do
20
+ expect(subject.eval 'test_local_variable').to eq 'test-local-variable-value'
21
+ end
22
+
23
+ it 'should set base_path' do
24
+ expect(subject.eval 'base_path').to eq 'test-base-path'
25
+ end
26
+ end
27
+
28
+ describe '#load' do
29
+ subject { described_class.load File.expand_path('../resources/load_test', __dir__) }
30
+
31
+ it { is_expected.to include 'key' => 'value' }
32
+ end
33
+
34
+ describe '#render' do
35
+ subject { described_class.render file_path, test_local_variables }
36
+
37
+ context 'given an absolute file path' do
38
+ let(:file_path) { File.expand_path '../resources/render_test', __dir__ }
39
+
40
+ it { is_expected.to match /key: test-local-variable-value/ }
41
+ end
42
+
43
+ context 'given a base path and a relative file path' do
44
+ let(:file_path) { 'render_test' }
45
+
46
+ before { described_class.base_path = File.expand_path '../resources', __dir__ }
47
+ # As base_path is set on the module, we need to reset it as other tests expext it to be nil.
48
+ after { described_class.base_path = nil }
49
+
50
+ it { is_expected.to match /key: test-local-variable-value/ }
51
+ end
52
+
53
+ context 'given a file path with a .yml.erb extension' do
54
+ let(:file_path) { File.expand_path '../resources/render_test.yml.erb', __dir__ }
55
+
56
+ it { is_expected.to match /key: test-local-variable-value/ }
57
+ end
58
+ end
59
+
60
+ describe '#render_json' do
61
+ subject { described_class.render_json File.expand_path('../resources/render_json_test', __dir__) }
62
+
63
+ it { is_expected.to match /"key": "value"/ }
64
+
65
+ it 'should render valid JSON' do
66
+ expect { JSON.parse subject }.to_not raise_error
67
+ end
68
+ end
69
+
70
+ describe 'nested rendering' do
71
+ subject do
72
+ json = described_class.render_json(
73
+ File.expand_path('../resources/nested_render_test', __dir__),
74
+ test_local_variables
75
+ )
76
+ JSON.parse json
77
+ end
78
+
79
+ before { described_class.base_path = File.expand_path '../resources', __dir__ }
80
+
81
+ it 'should render three nested files' do
82
+ expect(subject['key1']).to eq 'test-local-variable-value'
83
+ expect(subject['key2']).to eq 'test-local-variable2-value'
84
+ expect(subject['key3']).to eq File.expand_path('../resources', __dir__)
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,2 @@
1
+ ---
2
+ key: value
@@ -0,0 +1,3 @@
1
+ ---
2
+ key1: <%= test_local_variable %>
3
+ <%= render 'subdirectory/nested_render_test2', test_local_variable2: 'test-local-variable2-value' %>
@@ -0,0 +1,2 @@
1
+ ---
2
+ key: value
@@ -0,0 +1,2 @@
1
+ ---
2
+ key: <%= test_local_variable %>
@@ -0,0 +1,2 @@
1
+ key2: <%= test_local_variable2 %>
2
+ <%= render 'subdirectory/nested_render_test3' %>
@@ -0,0 +1 @@
1
+ key3: <%= base_path %>
@@ -0,0 +1,9 @@
1
+ require 'simplecov'
2
+ require 'coveralls'
3
+
4
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
5
+ SimpleCov::Formatter::HTMLFormatter,
6
+ Coveralls::SimpleCov::Formatter
7
+ ]
8
+
9
+ SimpleCov.start
data/yerbish.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'yerbish/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'yerbish'
8
+ spec.version = Yerbish::VERSION
9
+ spec.authors = ['Dave Willkomm']
10
+ spec.email = ['dinosaurjr10@gmail.com']
11
+ spec.summary = 'YAML with embedded Ruby'
12
+ spec.description = 'Yerbish enables embedding Ruby in YAML files, as well as composing a YAML file from other partial YAML files.'
13
+ spec.homepage = 'https://github.com/dinosaurjr10/yerbish'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.6'
22
+ spec.add_development_dependency 'coveralls', '~> 0.7'
23
+ spec.add_development_dependency 'rake', '~> 10.3'
24
+ spec.add_development_dependency 'rspec', '~> 3.0'
25
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yerbish
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dave Willkomm
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-09 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.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: coveralls
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.3'
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: Yerbish enables embedding Ruby in YAML files, as well as composing a
70
+ YAML file from other partial YAML files.
71
+ email:
72
+ - dinosaurjr10@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".coveralls.yml"
78
+ - ".gitignore"
79
+ - ".travis.yml"
80
+ - Gemfile
81
+ - LICENSE
82
+ - README.md
83
+ - Rakefile
84
+ - lib/yerbish.rb
85
+ - lib/yerbish/version.rb
86
+ - spec/lib/yerbish_spec.rb
87
+ - spec/resources/load_test.yml.erb
88
+ - spec/resources/nested_render_test.yml.erb
89
+ - spec/resources/render_json_test.yml.erb
90
+ - spec/resources/render_test.yml.erb
91
+ - spec/resources/subdirectory/nested_render_test2.yml.erb
92
+ - spec/resources/subdirectory/nested_render_test3.yml.erb
93
+ - spec/spec_helper.rb
94
+ - yerbish.gemspec
95
+ homepage: https://github.com/dinosaurjr10/yerbish
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.3.0
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: YAML with embedded Ruby
119
+ test_files:
120
+ - spec/lib/yerbish_spec.rb
121
+ - spec/resources/load_test.yml.erb
122
+ - spec/resources/nested_render_test.yml.erb
123
+ - spec/resources/render_json_test.yml.erb
124
+ - spec/resources/render_test.yml.erb
125
+ - spec/resources/subdirectory/nested_render_test2.yml.erb
126
+ - spec/resources/subdirectory/nested_render_test3.yml.erb
127
+ - spec/spec_helper.rb