Skip to content

Commit

Permalink
Move schema related version numbers to the new schema module.
Browse files Browse the repository at this point in the history
  • Loading branch information
hainesr committed Feb 3, 2024
1 parent 43964ae commit 83bfda1
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 25 deletions.
5 changes: 3 additions & 2 deletions lib/cff/index.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) 2018-2022 The Ruby Citation File Format Developers.
# Copyright (c) 2018-2024 The Ruby Citation File Format Developers.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -22,6 +22,7 @@
require_relative 'person'
require_relative 'reference'
require_relative 'schema'
require_relative 'schemas'
require_relative 'validatable'
require_relative 'citable'

Expand Down Expand Up @@ -83,7 +84,7 @@ def initialize(param)
@fields = build_index(param)
else
@fields = {}
@fields['cff-version'] = DEFAULT_SPEC_VERSION
@fields['cff-version'] = Schemas::DEFAULT_VERSION
@fields['message'] = DEFAULT_MESSAGE
@fields['title'] = param
end
Expand Down
6 changes: 6 additions & 0 deletions lib/cff/schemas.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@
module CFF
module Schemas # :nodoc:
PATH = ::File.join(__dir__, 'schemas')

FILES = Dir.glob(::File.join(PATH, '*.json')).to_h do |file|
[::File.basename(file, '.json'), JSON.parse(::File.read(file))]
end.freeze

VERSIONS = FILES.keys.freeze

DEFAULT_VERSION = '1.2.0'

MIN_VALIDATABLE_VERSION = '1.2.0'
end
end
8 changes: 4 additions & 4 deletions lib/cff/util.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) 2018-2022 The Ruby Citation File Format Developers.
# Copyright (c) 2018-2024 The Ruby Citation File Format Developers.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -16,7 +16,7 @@

require_relative 'entity'
require_relative 'person'
require_relative 'version'
require_relative 'schemas'

require 'rubygems'

Expand All @@ -33,8 +33,8 @@ module Util
def update_cff_version(version)
return '' if version.nil? || version.empty?

if Gem::Version.new(version) < Gem::Version.new(MIN_VALIDATABLE_VERSION)
MIN_VALIDATABLE_VERSION
if Gem::Version.new(version) < Gem::Version.new(Schemas::MIN_VALIDATABLE_VERSION)
Schemas::MIN_VALIDATABLE_VERSION
else
version
end
Expand Down
7 changes: 2 additions & 5 deletions lib/cff/version.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) 2018-2022 The Ruby Citation File Format Developers.
# Copyright (c) 2018-2024 The Ruby Citation File Format Developers.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -16,8 +16,5 @@

##
module CFF
# :nodoc:
VERSION = '2.0.0'
DEFAULT_SPEC_VERSION = '1.2.0'
MIN_VALIDATABLE_VERSION = '1.2.0'
VERSION = '2.0.0' # :nodoc:
end
6 changes: 1 addition & 5 deletions test/cff_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) 2018-2022 The Ruby Citation File Format Developers.
# Copyright (c) 2018-2024 The Ruby Citation File Format Developers.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -22,8 +22,4 @@ class CFFTest < Minitest::Test
def test_that_it_has_a_version_number
refute_nil ::CFF::VERSION
end

def test_that_it_has_a_spec_version_number
refute_nil ::CFF::DEFAULT_SPEC_VERSION
end
end
8 changes: 4 additions & 4 deletions test/file_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) 2018-2022 The Ruby Citation File Format Developers.
# Copyright (c) 2018-2024 The Ruby Citation File Format Developers.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -41,15 +41,15 @@ def test_new_file_from_model
index = ::CFF::Index.new(title)
file = ::CFF::File.new('', index)

assert_equal(::CFF::DEFAULT_SPEC_VERSION, file.cff_version)
assert_equal(::CFF::Schemas::DEFAULT_VERSION, file.cff_version)
assert_equal(title, file.title)
end

def test_new_file_from_title
title = 'software'
file = ::CFF::File.new('', title)

assert_equal(::CFF::DEFAULT_SPEC_VERSION, file.cff_version)
assert_equal(::CFF::Schemas::DEFAULT_VERSION, file.cff_version)
assert_equal(title, file.title)
end

Expand Down Expand Up @@ -131,7 +131,7 @@ def test_read_short_cff_file
end

# `cff-version` will be updated to a validatable version.
assert_equal(::CFF::MIN_VALIDATABLE_VERSION, cff.cff_version)
assert_equal(::CFF::Schemas::MIN_VALIDATABLE_VERSION, cff.cff_version)

assert_equal(1, cff.authors.length)
person = cff.authors[0]
Expand Down
4 changes: 2 additions & 2 deletions test/index_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) 2018-2022 The Ruby Citation File Format Developers.
# Copyright (c) 2018-2024 The Ruby Citation File Format Developers.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -36,7 +36,7 @@ def test_bad_methods_not_allowed
end

def test_default_index_cff_version
assert_equal(::CFF::DEFAULT_SPEC_VERSION, ::CFF::Index.new('').cff_version)
assert_equal(::CFF::Schemas::DEFAULT_VERSION, ::CFF::Index.new('').cff_version)
end

def test_cff_version_is_output_correctly
Expand Down
6 changes: 3 additions & 3 deletions test/util_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) 2018-2022 The Ruby Citation File Format Developers.
# Copyright (c) 2018-2024 The Ruby Citation File Format Developers.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -23,8 +23,8 @@ class CFFUtilTest < Minitest::Test

def test_update_cff_version
assert_equal('', update_cff_version(''))
assert_equal(::CFF::MIN_VALIDATABLE_VERSION, update_cff_version('1.0.3'))
assert_equal(::CFF::MIN_VALIDATABLE_VERSION, update_cff_version('1.1.0'))
assert_equal(::CFF::Schemas::MIN_VALIDATABLE_VERSION, update_cff_version('1.0.3'))
assert_equal(::CFF::Schemas::MIN_VALIDATABLE_VERSION, update_cff_version('1.1.0'))
assert_equal('1.2.0', update_cff_version('1.2.0'))
assert_equal('1.2.1', update_cff_version('1.2.1'))
end
Expand Down

0 comments on commit 83bfda1

Please sign in to comment.