cff 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0685f4e60680971f1d131ee18722cd4989631cc223a192197a226cf18b8deca4'
4
- data.tar.gz: 2bc27bb586bd0056a631b992a1da78befae597d8cc3815f5e124a72aa0e50180
3
+ metadata.gz: aa0896639724d0e82551bf84fde9801a00974dac14e120dafa51b53bc07c33cb
4
+ data.tar.gz: 0ef577895dff069272703c4c063dc5a84e1e484be6c23ce696592803093c43f7
5
5
  SHA512:
6
- metadata.gz: 2b36c030c352a815045c8ee5464f2c445802e99ab44a7caab1503029f785f740673b273949faf530593141497e9948652886d2a2761ea1f8f66cb6707be7bcb5
7
- data.tar.gz: 0325a6308c04c27213a16d54fb657f2b94c3fbb554e838ab469d3c10ef737e57bc3150b58e68550605b51aa2b971d5d6560933686d124be74aa746f1fb8c6669
6
+ metadata.gz: 63ae9c19849721bb92af374493b8930d75d7bb3bfbbc6e14a8f1fad0bbbf39064c635f5c03f5d2828bc507b33f65dea69d194a640f6be212bf6088fc3238b9f0
7
+ data.tar.gz: 5101768a4a0ab8de6176ba2506c98ad5efce62f517f34146feaa8a114939e2154f415ac1cdb4162e4b7407c7bdf3e3bdba1f8c7b06c4b5f714b68f620f402bc6
data/CHANGES.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changes log for the Ruby CFF Library
2
2
 
3
+ ## 1.3.0
4
+
5
+ * Abstract out parsing YAML.
6
+ * Turn on underlying support for YAML anchors/aliases.
7
+
3
8
  ## 1.2.0
4
9
 
5
10
  * Always treat dates as Ruby Date objects.
data/CITATION.cff CHANGED
@@ -1,4 +1,4 @@
1
- # This CITATION.cff file was created by ruby-cff (v 1.2.0).
1
+ # This CITATION.cff file was created by ruby-cff (v 1.3.0).
2
2
  # Gem: https://rubygems.org/gems/cff
3
3
  # CFF: https://citation-file-format.github.io/
4
4
 
@@ -21,9 +21,9 @@ keywords:
21
21
  - metadata
22
22
  - citation file format
23
23
  - CFF
24
- version: 1.2.0
24
+ version: 1.3.0
25
25
  doi: 10.5281/zenodo.1184077
26
- date-released: 2024-01-19
26
+ date-released: 2024-10-26
27
27
  license: Apache-2.0
28
28
  repository-artifact: https://rubygems.org/gems/cff
29
29
  repository-code: https://github.com/citation-file-format/ruby-cff
data/README.md CHANGED
@@ -122,6 +122,30 @@ CFF::File.open('CITATION.cff') do |cff|
122
122
  end
123
123
  ```
124
124
 
125
+ #### Notes on CFF files with YAML anchors and aliases
126
+
127
+ Ruby CFF can read files that use YAML anchors and aliases. An anchor (`&<label>`) identifies a section of your file for reuse elsewhere. An alias (`*<label>`) is then used to mark where you want that section to be repeated. In this example, the `&authors` anchor marks an author list for reuse wherever the `*authors` alias is used:
128
+
129
+ ```yaml
130
+ cff-version: 1.2.0
131
+ title: Ruby CFF Library
132
+ authors: &authors
133
+ - family-names: Haines
134
+ given-names: Robert
135
+ affiliation: The University of Manchester, UK
136
+
137
+ ...
138
+
139
+ references:
140
+ - type: software
141
+ title: Citation File Format
142
+ authors: *authors
143
+ ```
144
+
145
+ Ruby uses a single object to represent all aliases of an anchor. This means that once the above has been read in by Ruby CFF, if you add an author to either the top-level author list, or the author list in the reference, the new author will appear in both places. With this in mind, you should only use anchors and aliases where the relationship between sections is such that you are sure that exact repetition will always make sense.
146
+
147
+ When saving CFF files that use anchors and aliases the underlying YAML library will not preserve their names. For example, if the above is loaded into Ruby CFF and then immediately saved `&authors`/`*authors` will most likely become `&1`/`*1`.
148
+
125
149
  ### Validating CFF files
126
150
 
127
151
  To quickly validate a file and raise an error on failure, you can use `CFF::File` directly:
data/lib/cff/file.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2022 The Ruby Citation File Format Developers.
3
+ # Copyright (c) 2018-2024 The Ruby Citation File Format Developers.
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@ require_relative 'index'
19
19
  require_relative 'version'
20
20
 
21
21
  require 'date'
22
- require 'yaml'
23
22
 
24
23
  ##
25
24
  module CFF
@@ -71,9 +70,7 @@ module CFF
71
70
  content = ::File.read(file)
72
71
  comment = File.parse_comment(content)
73
72
 
74
- new(
75
- file, YAML.safe_load(content, permitted_classes: [Date, Time]), comment
76
- )
73
+ new(file, Util.parse_yaml(content), comment)
77
74
  end
78
75
 
79
76
  # :call-seq:
@@ -91,7 +88,7 @@ module CFF
91
88
  if ::File.exist?(file)
92
89
  content = ::File.read(file)
93
90
  comment = File.parse_comment(content)
94
- yaml = YAML.safe_load(content, permitted_classes: [Date, Time])
91
+ yaml = Util.parse_yaml(content)
95
92
  else
96
93
  comment = CFF_COMMENT
97
94
  yaml = ''
data/lib/cff/index.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2022 The Ruby Citation File Format Developers.
3
+ # Copyright (c) 2018-2024 The Ruby Citation File Format Developers.
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -25,8 +25,6 @@ require_relative 'schema'
25
25
  require_relative 'validatable'
26
26
  require_relative 'citable'
27
27
 
28
- require 'yaml'
29
-
30
28
  ##
31
29
  module CFF
32
30
  # Index is the core data structure for a CITATION.cff file. It can be
@@ -100,7 +98,7 @@ module CFF
100
98
  #
101
99
  # Read a CFF Index from a String and parse it for subsequent manipulation.
102
100
  def self.read(index)
103
- new(YAML.safe_load(index, permitted_classes: [Date, Time]))
101
+ new(Util.parse_yaml(index))
104
102
  end
105
103
 
106
104
  # :call-seq:
data/lib/cff/util.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2022 The Ruby Citation File Format Developers.
3
+ # Copyright (c) 2018-2024 The Ruby Citation File Format Developers.
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@ require_relative 'person'
19
19
  require_relative 'version'
20
20
 
21
21
  require 'rubygems'
22
+ require 'yaml'
22
23
 
23
24
  ##
24
25
  module CFF
@@ -30,6 +31,10 @@ module CFF
30
31
 
31
32
  module_function
32
33
 
34
+ def parse_yaml(string)
35
+ YAML.safe_load(string, aliases: true, permitted_classes: [Date, Time])
36
+ end
37
+
33
38
  def update_cff_version(version)
34
39
  return '' if version.nil? || version.empty?
35
40
 
@@ -44,6 +49,8 @@ module CFF
44
49
  # is a Person or Entity. This isn't perfect, but works 99.99% I think.
45
50
  def build_actor_collection!(source)
46
51
  source.map! do |s|
52
+ next s if s.is_a?(Person) || s.is_a?(Entity)
53
+
47
54
  s.has_key?('name') ? Entity.new(s) : Person.new(s)
48
55
  end
49
56
  end
data/lib/cff/version.rb CHANGED
@@ -17,7 +17,7 @@
17
17
  ##
18
18
  module CFF
19
19
  # :nodoc:
20
- VERSION = '1.2.0'
20
+ VERSION = '1.3.0'
21
21
  DEFAULT_SPEC_VERSION = '1.2.0'
22
22
  MIN_VALIDATABLE_VERSION = '1.2.0'
23
23
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cff
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Haines
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2024-01-19 00:00:00.000000000 Z
12
+ date: 2024-10-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json_schema
@@ -242,7 +242,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
242
242
  - !ruby/object:Gem::Version
243
243
  version: '0'
244
244
  requirements: []
245
- rubygems_version: 3.3.23
245
+ rubygems_version: 3.4.1
246
246
  signing_key:
247
247
  specification_version: 4
248
248
  summary: A Ruby library for manipulating CITATION.cff files.