diff --git a/lib/cff/index.rb b/lib/cff/index.rb index b44d682..2875e9d 100644 --- a/lib/cff/index.rb +++ b/lib/cff/index.rb @@ -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. @@ -22,6 +22,7 @@ require_relative 'person' require_relative 'reference' require_relative 'schema' +require_relative 'schemas' require_relative 'validatable' require_relative 'citable' @@ -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 diff --git a/lib/cff/schemas.rb b/lib/cff/schemas.rb index a9bd799..9f74c5f 100644 --- a/lib/cff/schemas.rb +++ b/lib/cff/schemas.rb @@ -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 diff --git a/lib/cff/util.rb b/lib/cff/util.rb index 4eeec4f..a5b12ff 100644 --- a/lib/cff/util.rb +++ b/lib/cff/util.rb @@ -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. @@ -16,7 +16,7 @@ require_relative 'entity' require_relative 'person' -require_relative 'version' +require_relative 'schemas' require 'rubygems' @@ -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 diff --git a/lib/cff/version.rb b/lib/cff/version.rb index 2e40f17..c74f58a 100644 --- a/lib/cff/version.rb +++ b/lib/cff/version.rb @@ -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. @@ -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 diff --git a/test/cff_test.rb b/test/cff_test.rb index 2bdbc9b..570ad88 100644 --- a/test/cff_test.rb +++ b/test/cff_test.rb @@ -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. @@ -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 diff --git a/test/file_test.rb b/test/file_test.rb index 82b48f5..874ee6d 100644 --- a/test/file_test.rb +++ b/test/file_test.rb @@ -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. @@ -41,7 +41,7 @@ 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 @@ -49,7 +49,7 @@ 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 @@ -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] diff --git a/test/index_test.rb b/test/index_test.rb index f0d9d27..23a3740 100644 --- a/test/index_test.rb +++ b/test/index_test.rb @@ -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. @@ -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 diff --git a/test/util_test.rb b/test/util_test.rb index 55b62fc..4b75ff3 100644 --- a/test/util_test.rb +++ b/test/util_test.rb @@ -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. @@ -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