Skip to content

Commit

Permalink
Merge 4a5ff1b into b72282d
Browse files Browse the repository at this point in the history
  • Loading branch information
jmortlock committed Jan 9, 2022
2 parents b72282d + 4a5ff1b commit dc9f736
Show file tree
Hide file tree
Showing 24 changed files with 212 additions and 178 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- run: bundle exec standardrb
- run: bundle exec rake

release:
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: ["2.6", "2.7", "3.0"]
ruby: ["2.6", "2.7", "3.0", "3.1"]
runs-on: ubuntu-latest
env:
AWS_REGION: us-east-1
Expand All @@ -15,4 +15,10 @@ jobs:
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- run: bundle exec standardrb
- run: bundle exec rake
- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: coverage/lcov.info
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.0
3.1.0
1 change: 1 addition & 0 deletions .standard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby_version: 2.6
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Unreleased

- [PLAT-186] Add support for Ruby 3.1

## 0.6.0

- [TT-8616] Update to build with github actions / ruby 3.0 / rails 6.1
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source 'https://rubygems.org'
source "https://rubygems.org"

# Specify your gem's dependencies in yamload.gemspec
gemspec
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Yamload

[![Ruby Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/testdouble/standard)
[![Gem Version](https://badge.fury.io/rb/yamload.svg)](http://badge.fury.io/rb/yamload)
[![Build Status](https://github.com/sealink/yamload/workflows/Build%20and%20Test/badge.svg?branch=master)](https://github.com/sealink/yamload/actions)
[![Coverage Status](https://coveralls.io/repos/sealink/yamload/badge.svg)](https://coveralls.io/r/sealink/yamload)
[![Code Climate](https://codeclimate.com/github/sealink/yamload/badges/gpa.svg)](https://codeclimate.com/github/sealink/yamload)

- YAML files loading
- Recursive conversion to immutable objects
Expand Down
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require "bundler/gem_tasks"
require "rspec/core/rake_task"

RSpec::Core::RakeTask.new(:spec)

Expand Down
4 changes: 2 additions & 2 deletions lib/yamload.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require 'yamload/version'
require "yamload/version"

module Yamload
class << self
attr_accessor :dir
end
end

require 'yamload/loader'
require "yamload/loader"
6 changes: 3 additions & 3 deletions lib/yamload/conversion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module Conversion
end
end

require 'yamload/conversion/array'
require 'yamload/conversion/hash'
require 'yamload/conversion/object'
require "yamload/conversion/array"
require "yamload/conversion/hash"
require "yamload/conversion/object"
4 changes: 2 additions & 2 deletions lib/yamload/conversion/hash.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'facets/hash/rekey'
require 'anima'
require "facets/hash/rekey"
require "anima"

module Yamload
module Conversion
Expand Down
4 changes: 2 additions & 2 deletions lib/yamload/conversion/object.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'facets/object/dup'
require 'ice_nine'
require "facets/object/dup"
require "ice_nine"

module Yamload
module Conversion
Expand Down
2 changes: 1 addition & 1 deletion lib/yamload/defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ module Defaults
end
end

require 'yamload/defaults/hash'
require "yamload/defaults/hash"
2 changes: 1 addition & 1 deletion lib/yamload/defaults/hash.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'facets/hash/deep_merge'
require "facets/hash/deep_merge"

module Yamload
module Defaults
Expand Down
16 changes: 8 additions & 8 deletions lib/yamload/loader.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
require 'yaml'
require 'ice_nine'
require 'aws-sdk-secretsmanager'
require 'aws-sdk-ssm'

require 'yamload/loading'
require 'yamload/conversion'
require 'yamload/defaults'
require "yaml"
require "ice_nine"
require "aws-sdk-secretsmanager"
require "aws-sdk-ssm"

require "yamload/loading"
require "yamload/conversion"
require "yamload/defaults"

module Yamload
class Loader
Expand Down
2 changes: 1 addition & 1 deletion lib/yamload/loading.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ module Loading
end
end

require 'yamload/loading/yaml'
require "yamload/loading/yaml"
25 changes: 16 additions & 9 deletions lib/yamload/loading/yaml.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
require 'facets/kernel/blank'
require 'ice_nine'
require "facets/kernel/blank"
require "ice_nine"

module Yamload
module Loading
class Yaml
def initialize(file, dir)
@file = file
@dir = dir
@dir = dir
end

def exist?
Expand All @@ -26,25 +26,32 @@ def reload

def load
fail IOError, "#{@file}.yml could not be found" unless exist?
YAML.load(erb_parsed_content).tap do |content|
fail IOError, "#{@file}.yml is blank" if content.blank?
source = erb_parsed_content
content = if YAML.respond_to?(:unsafe_load)
YAML.unsafe_load(source)
else
# rubocop:disable Security::YAMLLoad
YAML.load(source)
# rubocop:enable Security::YAMLLoad
end
fail IOError, "#{@file}.yml is blank" if content.blank?
content
end

def erb_parsed_content
raw_content = File.read(filepath, encoding: 'bom|utf-8', mode: 'r')
raw_content = File.read(filepath, encoding: "bom|utf-8", mode: "r")
ERB.new(raw_content).result(binding)
end

def filepath
fail IOError, 'No yml files directory specified' if @dir.nil?
fail IOError, "No yml files directory specified" if @dir.nil?
fail IOError, "#{@dir} is not a valid directory" unless File.directory?(@dir)
File.join(@dir, "#{@file}.yml")
end

def secrets_client
options = {}
options[:endpoint] = ENV['AWS_SECRETS_MANAGER_ENDPOINT'] if ENV.has_key?('AWS_SECRETS_MANAGER_ENDPOINT')
options[:endpoint] = ENV["AWS_SECRETS_MANAGER_ENDPOINT"] if ENV.has_key?("AWS_SECRETS_MANAGER_ENDPOINT")
@secrets_client ||= Aws::SecretsManager::Client.new(options)
end

Expand All @@ -54,7 +61,7 @@ def get_secret(key)

def ssm_client
options = {}
options[:endpoint] = ENV['AWS_SSM_ENDPOINT'] if ENV.has_key?('AWS_SSM_ENDPOINT')
options[:endpoint] = ENV["AWS_SSM_ENDPOINT"] if ENV.has_key?("AWS_SSM_ENDPOINT")
@ssm_client ||= Aws::SSM::Client.new(options)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/yamload/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Yamload
VERSION = '0.6.0'
VERSION = "0.6.0"
end
28 changes: 14 additions & 14 deletions spec/conversion_spec.rb
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
require 'spec_helper'
require "spec_helper"

require 'yamload/conversion'
require "yamload/conversion"

describe Yamload::Conversion do
let(:number) { 42 }
let(:string) { 'a string' }
let(:array) { [number, string] }
let(:number) { 42 }
let(:string) { "a string" }
let(:array) { [number, string] }
let(:hash) {
{
string: string,
array: array,
sub_hash: { something: 'else' }
string: string,
array: array,
sub_hash: {something: "else"}
}
}

subject!(:immutable_object) { converter.to_immutable }

context 'when converting a number' do
context "when converting a number" do
let(:converter) { Yamload::Conversion::Object.new(number) }
specify { is_expected.to eq number }
end

context 'when converting a string' do
context "when converting a string" do
let(:converter) { Yamload::Conversion::Object.new(string) }
specify { expect(string).not_to be_frozen }
specify { is_expected.to be_frozen }
specify { is_expected.to eq string }
end

context 'when converting an array' do
context "when converting an array" do
let(:converter) { Yamload::Conversion::Object.new(array) }
specify { expect(array).not_to be_frozen }
specify { is_expected.to be_frozen }
Expand All @@ -39,8 +39,8 @@
specify { expect(immutable_object[1]).to eq string }
end

context 'when converting a hash' do
let(:converter) { Yamload::Conversion::Object.new(hash) }
context "when converting a hash" do
let(:converter) { Yamload::Conversion::Object.new(hash) }
specify { expect(hash).not_to be_frozen }
specify { is_expected.to be_frozen }
specify { expect(immutable_object.string).to eq string }
Expand All @@ -50,6 +50,6 @@
specify { expect(immutable_object.array[1]).to eq string }
specify { expect(immutable_object.sub_hash).to be_frozen }
specify { expect(immutable_object.sub_hash.something).to be_frozen }
specify { expect(immutable_object.sub_hash.something).to eq 'else' }
specify { expect(immutable_object.sub_hash.something).to eq "else" }
end
end
6 changes: 6 additions & 0 deletions spec/fixtures/unsafe.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
defaults: &defaults
adapter: mysql2

development:
<<: *defaults
adapter: 'sqlite'

0 comments on commit dc9f736

Please sign in to comment.