Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ruby_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
fail-fast: false
matrix:
# Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
ruby: [ "3.0", "3.1", "3.2", "3.3", "3.4", "4.0" ]
ruby: [ "3.3", "3.4", "4.0" ]
steps:
- name: Checkout Repository
uses: sanger/.github/.github/actions/setup/checkout@master
Expand Down
6 changes: 5 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ plugins:

AllCops:
NewCops: enable
TargetRubyVersion: 3.0
TargetRubyVersion: 3.3

Gemspec/DevelopmentDependencies:
EnforcedStyle: gemspec
Expand All @@ -42,3 +42,7 @@ RSpec/NestedGroups:
# The single-line syntax can be clearer than the multi-line version for multiple definitions
Style/EmptyClassDefinition:
Enabled: false

# Only use shorthand hash syntax when all keys match the variables for better readability
Style/HashSyntax:
EnforcedShorthandSyntax: consistent
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.6
3.3.11
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Keeps track of notable changes. Please remember to add new behaviours to the
Unreleased section to make new releases easy.
Follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.1]

- [Removed] Remove support for Ruby 3.0 - 3.2
- [Changed] Update Psych dependency to explicitly use unsafe loading

## [1.0.0]

- [Changed] Version numbering to follow [Ruby Gem versioning guidelines](https://guides.rubygems.org/patterns/)
Expand Down
8 changes: 6 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ PATH
remote: .
specs:
record_loader (1.0.0)
psych (~> 3.0)
psych (~> 5.0)

GEM
remote: https://rubygems.org/
specs:
ast (2.4.3)
coderay (1.1.3)
date (3.5.1)
diff-lcs (1.5.0)
docile (1.4.1)
json (2.19.4)
Expand All @@ -27,7 +28,9 @@ GEM
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
psych (3.3.4)
psych (5.3.1)
date
stringio
racc (1.8.1)
rainbow (3.1.1)
rake (13.0.6)
Expand Down Expand Up @@ -74,6 +77,7 @@ GEM
simplecov-lcov (0.9.0)
simplecov_json_formatter (0.1.4)
sorbet-runtime (0.6.13169)
stringio (3.2.0)
unicode-display_width (3.2.0)
unicode-emoji (~> 4.1)
unicode-emoji (4.2.0)
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# RecordLoader

[![Ruby](https://img.shields.io/badge/ruby-3.0-e2242a?logo=ruby)](https://ruby-doc.org/3.0.6/)
[![Ruby](https://img.shields.io/badge/ruby-3.3%20|%203.4%20|%204.0-e2242a?logo=ruby)](https://www.ruby-lang.org/en/)
[![Test Coverage](https://codecov.io/gh/sanger/record_loader/graph/badge.svg?token=AO7PUU5SB0)](https://codecov.io/gh/sanger/record_loader)
[![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](https://rubydoc.info/github/sanger/record_loader)

RecordLoader provides a simple and standardized way of populating databases from information described in a series of
organized yaml files. It is intended to be used to generate a number of idempotent tasks, which can be run in both
your production and development environments.
your production and development environments. It should only be used with trusted data.

While written with ActiveRecord/Rails in mind, it is possible to use RecordLoader in different environments.

Expand Down Expand Up @@ -46,6 +46,7 @@ If using with Rails:

| Rails Version | RecordLoader Version |
| ------------- | -------------------- |
| 7.x and above | 1.x |
| 6.x and below | 0.3.0\*, 1.0.0 |

_\* Pin psych < 4_
Expand Down
4 changes: 2 additions & 2 deletions lib/record_loader/adapter/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def logger
# Wraps the ActiveRecord::Base.transaction method.
# @see https://api.rubyonrails.org/classes/ActiveRecord/Transactions/ClassMethods.html
# @return [Void]
def transaction(&block)
ActiveRecord::Base.transaction(&block)
def transaction(&)
ActiveRecord::Base.transaction(&)
end

#
Expand Down
4 changes: 2 additions & 2 deletions lib/record_loader/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def adapter(adapter = nil)
def initialize(files: nil, directory: default_path, dev: adapter.development?)
@path = directory.is_a?(Pathname) ? directory : Pathname.new(directory)

list = Filter.create(files: files, dev: dev, wip_list: wip_list)
list = Filter.create(files:, dev:, wip_list:)
@files = @path.glob("*#{RecordFile::EXTENSION}")
.select { |child| list.include?(RecordFile.new(child)) }
load_config
Expand Down Expand Up @@ -133,7 +133,7 @@ def default_path
#
def load_config
@config = @files.each_with_object({}) do |file, store|
latest_file = Psych.load_file(file)
latest_file = Psych.unsafe_load_file(file)
Comment thread
StephenHulme marked this conversation as resolved.
duplicate_keys = store.keys & latest_file.keys
adapter.logger.warn "Duplicate keys in #{@path}: #{duplicate_keys}" unless duplicate_keys.empty?
store.merge!(latest_file)
Expand Down
2 changes: 1 addition & 1 deletion lib/record_loader/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module Filter
# @return [RecordLoader::Filter::Standard, RecordLoader::Filter::FileList] An appropriate filter
def self.create(files: nil, dev: false, wip_list: [])
if files.nil?
RecordLoader::Filter::Standard.new(dev: dev, wip_list: wip_list)
RecordLoader::Filter::Standard.new(dev:, wip_list:)
else
RecordLoader::Filter::FileList.new(files)
end
Expand Down
5 changes: 3 additions & 2 deletions record_loader.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
spec.homepage = 'https://github.com/sanger/record_loader'
spec.license = 'MIT'

spec.required_ruby_version = '>= 3.0.6'
spec.required_ruby_version = '>= 3.3.11'

# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
# to allow pushing to a single host or delete this section to allow pushing to any host.
Expand All @@ -35,7 +35,8 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']

spec.add_dependency 'psych', '~> 3.0'
# Runtime dependencies
spec.add_dependency 'psych', '~> 5.0'

# Development dependencies
spec.add_development_dependency 'bundler', '~> 2.5'
Expand Down
16 changes: 16 additions & 0 deletions spec/record_loader/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@ def create_or_update_called
end
end

describe '#initialize' do
let(:dev) { false }

context 'when loading a string' do
let(:selected_files) { ['000_example'] }

it 'loads the config from the specified file' do
expect(record_loader.instance_variable_get(:@config))
.to eq({
'Example a' => { 'key_a' => 'value a' },
'Example b' => { 'key_a' => 'value b' }
})
end
end
end

describe '#create' do
before { record_loader.create! }

Expand Down
2 changes: 1 addition & 1 deletion spec/record_loader/filter/standard_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'record_loader/filter/standard'

RSpec.describe RecordLoader::Filter::Standard, type: :model do
subject(:filter) { described_class.new(dev: dev, wip_list: wip_list) }
subject(:filter) { described_class.new(dev:, wip_list:) }

def record_file(name)
RecordLoader::RecordFile.new(Pathname.new(name))
Expand Down
Loading