strongmind_multi_version_common_cartridge 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/gem-push.yml +46 -0
  3. data/.gitignore +14 -0
  4. data/.rspec +1 -0
  5. data/.rubocop.yml +60 -0
  6. data/Gemfile +3 -0
  7. data/LICENSE +674 -0
  8. data/PULL_REQUEST_TEMPLATE.md +7 -0
  9. data/README.md +36 -0
  10. data/lib/multi_version_common_cartridge/cartridge.rb +58 -0
  11. data/lib/multi_version_common_cartridge/cartridge_versions.rb +25 -0
  12. data/lib/multi_version_common_cartridge/item.rb +29 -0
  13. data/lib/multi_version_common_cartridge/manifest.rb +33 -0
  14. data/lib/multi_version_common_cartridge/resources/basic_lti_link.rb +46 -0
  15. data/lib/multi_version_common_cartridge/resources/canvas_assignment.rb +30 -0
  16. data/lib/multi_version_common_cartridge/resources/canvas_course_settings.rb +29 -0
  17. data/lib/multi_version_common_cartridge/resources/canvas_elements/assignment.rb +33 -0
  18. data/lib/multi_version_common_cartridge/resources/canvas_elements/course_settings.rb +111 -0
  19. data/lib/multi_version_common_cartridge/resources/resource.rb +23 -0
  20. data/lib/multi_version_common_cartridge/sax_machine_nokogiri_xml_saver.rb +85 -0
  21. data/lib/multi_version_common_cartridge/version.rb +19 -0
  22. data/lib/multi_version_common_cartridge/writers/basic_lti_extension_writer.rb +45 -0
  23. data/lib/multi_version_common_cartridge/writers/basic_lti_link_writer.rb +242 -0
  24. data/lib/multi_version_common_cartridge/writers/basic_lti_vendor_writer.rb +66 -0
  25. data/lib/multi_version_common_cartridge/writers/canvas_assignment_writer.rb +104 -0
  26. data/lib/multi_version_common_cartridge/writers/canvas_course_settings_writer.rb +218 -0
  27. data/lib/multi_version_common_cartridge/writers/cartridge_writer.rb +85 -0
  28. data/lib/multi_version_common_cartridge/writers/factory.rb +61 -0
  29. data/lib/multi_version_common_cartridge/writers/item_writer.rb +60 -0
  30. data/lib/multi_version_common_cartridge/writers/manifest_metadata_writer.rb +62 -0
  31. data/lib/multi_version_common_cartridge/writers/manifest_organization_writer.rb +68 -0
  32. data/lib/multi_version_common_cartridge/writers/manifest_resources_writer.rb +48 -0
  33. data/lib/multi_version_common_cartridge/writers/manifest_writer.rb +88 -0
  34. data/lib/multi_version_common_cartridge/writers/resource_writer.rb +54 -0
  35. data/lib/multi_version_common_cartridge/writers/supported_versions.rb +37 -0
  36. data/lib/multi_version_common_cartridge/xml_definitions.rb +149 -0
  37. data/lib/multi_version_common_cartridge.rb +45 -0
  38. data/multi_version_common_cartridge.gemspec +27 -0
  39. metadata +164 -0
@@ -0,0 +1,85 @@
1
+ # multi_version_common_cartridge
2
+ # Copyright © 2019 Vista Higher Learning, Inc.
3
+ #
4
+ # multi_version_common_cartridge is free software: you can redistribute it
5
+ # and/or modify it under the terms of the GNU General Public
6
+ # License as published by the Free Software Foundation, either
7
+ # version 3 of the License, or (at your option) any later version.
8
+ #
9
+ # multi_version_common_cartridge is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with multi_version_common_cartridge. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ require 'common_cartridge'
18
+
19
+ module MultiVersionCommonCartridge
20
+ module Writers
21
+ class CartridgeWriter
22
+ include SupportedVersions
23
+
24
+ attr_reader :cartridge
25
+
26
+ def initialize(cartridge, version)
27
+ @cartridge = cartridge
28
+ @finalized = false
29
+ @version = validate_version(version)
30
+ end
31
+
32
+ def finalize
33
+ manifest_writer.finalize
34
+ cartridge.all_items.each { |item| item_writer(item).finalize }
35
+ cartridge.all_resources.each { |resource| resource_writer(resource).finalize }
36
+ @finalized = true
37
+ end
38
+
39
+ def write_in_dir(dir)
40
+ # Should we raise, or should we call finalize from here?
41
+ raise StandardError, 'the cartridge has not been finalized' unless @finalized
42
+ FileUtils.mkdir_p(dir)
43
+ manifest_writer.write(dir)
44
+ cartridge.all_resources.each do |resource|
45
+ resource_writer(resource).create_files(dir)
46
+ end
47
+ end
48
+
49
+ def write_to_zip(filename)
50
+ Dir.mktmpdir do |dir|
51
+ write_in_dir(dir)
52
+ zip_dir(filename, dir)
53
+ end
54
+ end
55
+
56
+ private def zip_dir(filename, dir)
57
+ Zip::OutputStream.open(filename) { |zos| } # make sure it's a zip
58
+
59
+ Zip::File.open(filename, Zip::File::CREATE) do |zipfile|
60
+ base_path = Pathname.new(dir)
61
+ Dir["#{dir}/**/*"].each do |file|
62
+ entry = Pathname.new(file).relative_path_from(base_path)
63
+ zipfile.add(entry, file)
64
+ end
65
+ end
66
+ end
67
+
68
+ private def writers_factory
69
+ @writers_factory ||= Factory.new(cartridge, @version)
70
+ end
71
+
72
+ private def manifest_writer
73
+ writers_factory.manifest_writer
74
+ end
75
+
76
+ private def item_writer(item)
77
+ writers_factory.item_writer(item)
78
+ end
79
+
80
+ private def resource_writer(resource)
81
+ writers_factory.resource_writer(resource)
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,61 @@
1
+ # multi_version_common_cartridge
2
+ # Copyright © 2019 Vista Higher Learning, Inc.
3
+ #
4
+ # multi_version_common_cartridge is free software: you can redistribute it
5
+ # and/or modify it under the terms of the GNU General Public
6
+ # License as published by the Free Software Foundation, either
7
+ # version 3 of the License, or (at your option) any later version.
8
+ #
9
+ # multi_version_common_cartridge is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with multi_version_common_cartridge. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ module MultiVersionCommonCartridge
18
+ module Writers
19
+ class Factory
20
+ RESOURCE_WRITERS = {
21
+ ::MultiVersionCommonCartridge::Resources::BasicLtiLink::BasicLtiLink => BasicLtiLinkWriter,
22
+ ::MultiVersionCommonCartridge::Resources::CanvasAssignment::CanvasAssignment => CanvasAssignmentWriter,
23
+ ::MultiVersionCommonCartridge::Resources::CanvasCourseSettings::CanvasCourseSettings => CanvasCourseSettingsWriter,
24
+ }.freeze
25
+
26
+ def initialize(cartridge, version)
27
+ @cartridge = cartridge
28
+ @version = version
29
+ @item_writers = {}
30
+ @resource_writers = {}
31
+ end
32
+
33
+ def manifest_writer
34
+ @manifest_writer ||= ManifestWriter.new(@cartridge.manifest, self, @version)
35
+ end
36
+
37
+ def manifest_metadata_writer
38
+ @manifest_metadata_writer ||= ManifestMetadataWriter.new(@cartridge.manifest, @version)
39
+ end
40
+
41
+ def manifest_organization_writer
42
+ @manifest_organization_writer ||= ManifestOrganizationWriter.new(@cartridge, self, @version)
43
+ end
44
+
45
+ def manifest_resources_writer
46
+ @manifest_resources_writer ||= ManifestResourcesWriter.new(@cartridge, self, @version)
47
+ end
48
+
49
+ def item_writer(item)
50
+ @item_writers[item] ||= ItemWriter.new(item, self, @version)
51
+ end
52
+
53
+ def resource_writer(resource)
54
+ return @resource_writers[resource] if @resource_writers.key?(resource)
55
+ writer_class = RESOURCE_WRITERS[resource.class]
56
+ raise "Unknown resource '#{resource.class.name}'" unless writer_class
57
+ @resource_writers[resource] = writer_class.new(resource, @version)
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,60 @@
1
+ # multi_version_common_cartridge
2
+ # Copyright © 2019 Vista Higher Learning, Inc.
3
+ #
4
+ # multi_version_common_cartridge is free software: you can redistribute it
5
+ # and/or modify it under the terms of the GNU General Public
6
+ # License as published by the Free Software Foundation, either
7
+ # version 3 of the License, or (at your option) any later version.
8
+ #
9
+ # multi_version_common_cartridge is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with multi_version_common_cartridge. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ module MultiVersionCommonCartridge
18
+ module Writers
19
+ class ItemWriter
20
+ include SupportedVersions
21
+
22
+ MESSAGES = {
23
+ no_title: 'A title is required',
24
+ no_identifier: 'An identifier is required'
25
+ }.freeze
26
+
27
+ attr_reader :item
28
+
29
+ def initialize(item, factory, version)
30
+ @item = item
31
+ @factory = factory
32
+ @version = validate_version(version)
33
+ end
34
+
35
+ def finalize
36
+ validate_title
37
+ validate_identifier
38
+ end
39
+
40
+ def organization_item_element
41
+ CommonCartridge::Elements::Organizations::Item.new.tap do |item_element|
42
+ item_element.identifier = item.identifier
43
+ item_element.identifierref = item.resource.identifier if item.resource
44
+ item_element.title = item.title
45
+ item_element.items = item.children.map do |child|
46
+ @factory.item_writer(child).organization_item_element
47
+ end
48
+ end
49
+ end
50
+
51
+ private def validate_title
52
+ raise StandardError, MESSAGES[:no_title] unless item.title
53
+ end
54
+
55
+ private def validate_identifier
56
+ raise StandardError, MESSAGES[:no_identifier] unless item.identifier
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,62 @@
1
+ # multi_version_common_cartridge
2
+ # Copyright © 2019 Vista Higher Learning, Inc.
3
+ #
4
+ # multi_version_common_cartridge is free software: you can redistribute it
5
+ # and/or modify it under the terms of the GNU General Public
6
+ # License as published by the Free Software Foundation, either
7
+ # version 3 of the License, or (at your option) any later version.
8
+ #
9
+ # multi_version_common_cartridge is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with multi_version_common_cartridge. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ require 'common_cartridge'
18
+
19
+ module MultiVersionCommonCartridge
20
+ module Writers
21
+ class ManifestMetadataWriter
22
+ # http://www.imsglobal.org/profile/cc/ccv1p3/ccv1p3_imscp_v1p2_v1p0.xsd
23
+ # ManifestMetadata.Type
24
+ include SupportedVersions
25
+
26
+ attr_reader :manifest
27
+
28
+ def initialize(manifest, version)
29
+ @manifest = manifest
30
+ @version = validate_version(version)
31
+ end
32
+
33
+ def finalize
34
+ # nothing to check
35
+ end
36
+
37
+ def metadata_element
38
+ CommonCartridge::Elements::Metadata.new.tap do |metadata|
39
+ metadata.schema = XmlDefinitions::SCHEMA[@version]
40
+ metadata.schemaversion = XmlDefinitions::SCHEMA_VERSION[@version]
41
+ metadata.lom = lom_element
42
+ end
43
+ end
44
+
45
+ private def lom_element
46
+ CommonCartridge::Elements::Lom::Lom.new.tap do |lom|
47
+ lom.general = CommonCartridge::Elements::Lom::General.new.tap do |general|
48
+ general.title = lom_general_title_element
49
+ end
50
+ end
51
+ end
52
+
53
+ private def lom_general_title_element
54
+ CommonCartridge::Elements::Lom::Title.new.tap do |title_element|
55
+ title_element.strings = manifest.titles.map do |language, value|
56
+ CommonCartridge::Elements::Lom::LanguageString.new(language: language, value: value)
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,68 @@
1
+ # multi_version_common_cartridge
2
+ # Copyright © 2019 Vista Higher Learning, Inc.
3
+ #
4
+ # multi_version_common_cartridge is free software: you can redistribute it
5
+ # and/or modify it under the terms of the GNU General Public
6
+ # License as published by the Free Software Foundation, either
7
+ # version 3 of the License, or (at your option) any later version.
8
+ #
9
+ # multi_version_common_cartridge is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with multi_version_common_cartridge. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ require 'common_cartridge'
18
+ require 'securerandom'
19
+
20
+ module MultiVersionCommonCartridge
21
+ module Writers
22
+ class ManifestOrganizationWriter
23
+ # http://www.imsglobal.org/profile/cc/ccv1p3/ccv1p3_imscp_v1p2_v1p0.xsd
24
+ # Organizations.Type, Organization.Type
25
+ include SupportedVersions
26
+
27
+ ORGANIZATION_STRUCTURE = 'rooted-hierarchy'.freeze
28
+ DEFAULT_ROOT_ITEM_IDENTIFIER = 'root'.freeze
29
+
30
+ MESSAGES = {
31
+ no_identifier: 'An identifier is required'
32
+ }.freeze
33
+
34
+ attr_reader :cartridge
35
+
36
+ def initialize(cartridge, factory, version)
37
+ @cartridge = cartridge
38
+ @factory = factory
39
+ @version = validate_version(version)
40
+ end
41
+
42
+ def finalize
43
+ validate_identifier
44
+ end
45
+
46
+ def organization_element
47
+ CommonCartridge::Elements::Organizations::Organization.new.tap do |element|
48
+ element.identifier = SecureRandom.uuid
49
+ element.structure = ORGANIZATION_STRUCTURE
50
+ element.root_item = root_item
51
+ end
52
+ end
53
+
54
+ private def root_item
55
+ CommonCartridge::Elements::Organizations::RootItem.new.tap do |root_item|
56
+ root_item.identifier = cartridge.manifest.organization_identifier || DEFAULT_ROOT_ITEM_IDENTIFIER
57
+ root_item.items = cartridge.items.map do |item|
58
+ @factory.item_writer(item).organization_item_element
59
+ end
60
+ end
61
+ end
62
+
63
+ private def validate_identifier
64
+ # raise StandardError, MESSAGES[:no_identifier] unless manifest..identifier
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,48 @@
1
+ # multi_version_common_cartridge
2
+ # Copyright © 2019 Vista Higher Learning, Inc.
3
+ #
4
+ # multi_version_common_cartridge is free software: you can redistribute it
5
+ # and/or modify it under the terms of the GNU General Public
6
+ # License as published by the Free Software Foundation, either
7
+ # version 3 of the License, or (at your option) any later version.
8
+ #
9
+ # multi_version_common_cartridge is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with multi_version_common_cartridge. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ require 'common_cartridge'
18
+
19
+ module MultiVersionCommonCartridge
20
+ module Writers
21
+ class ManifestResourcesWriter
22
+ # http://www.imsglobal.org/profile/cc/ccv1p3/ccv1p3_imscp_v1p2_v1p0.xsd
23
+ # Resources.type
24
+ include SupportedVersions
25
+
26
+ attr_reader :cartridge
27
+
28
+ def initialize(cartridge, factory, version)
29
+ @cartridge = cartridge
30
+ @factory = factory
31
+ @resource_writers = {}
32
+ @version = validate_version(version)
33
+ end
34
+
35
+ def finalize
36
+ # nothing to check
37
+ end
38
+
39
+ def root_resource_element
40
+ @root_resource_element ||= CommonCartridge::Elements::Resources::RootResource.new(
41
+ resources: cartridge.all_resources.map do |resource|
42
+ @factory.resource_writer(resource).resource_element
43
+ end
44
+ )
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,88 @@
1
+ # multi_version_common_cartridge
2
+ # Copyright © 2019 Vista Higher Learning, Inc.
3
+ #
4
+ # multi_version_common_cartridge is free software: you can redistribute it
5
+ # and/or modify it under the terms of the GNU General Public
6
+ # License as published by the Free Software Foundation, either
7
+ # version 3 of the License, or (at your option) any later version.
8
+ #
9
+ # multi_version_common_cartridge is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with multi_version_common_cartridge. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ require 'common_cartridge'
18
+
19
+ module MultiVersionCommonCartridge
20
+ module Writers
21
+ class ManifestWriter
22
+ include SupportedVersions
23
+
24
+ MESSAGES = {
25
+ no_identifier: 'An identifier is required',
26
+ }.freeze
27
+
28
+ attr_reader :manifest
29
+
30
+ def initialize(manifest, factory, version)
31
+ @manifest = manifest
32
+ @factory = factory
33
+ @version = validate_version(version)
34
+ end
35
+
36
+ def finalize
37
+ raise StandardError, MESSAGES[:no_identifier] unless manifest.identifier
38
+ metadata_writer.finalize
39
+ organization_writer.finalize
40
+ resources_writer.finalize
41
+ end
42
+
43
+ def write(dir)
44
+ doc = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |builder|
45
+ SaxMachineNokogiriXmlSaver.new.save(builder, manifest_element, 'manifest')
46
+ end
47
+ File.open(File.join(dir, 'imsmanifest.xml'), 'w') { |file| file.write(doc.to_xml) }
48
+ end
49
+
50
+ def manifest_element
51
+ @manifest_element ||= CommonCartridge::Elements::Manifest.new.tap do |element|
52
+ element.identifier = manifest.identifier
53
+ element.xmlns = required_namespaces['xmlns']
54
+ element.xmlns_lomimscc = required_namespaces['xmlns:lomimscc']
55
+ element.xmlns_lom = required_namespaces['xmlns:lom']
56
+ element.xmlns_xsi = required_namespaces['xmlns:xsi']
57
+ element.xsi_schema_location = xsi_schema_location
58
+ element.metadata = metadata_writer.metadata_element
59
+ element.root_organization = CommonCartridge::Elements::Organizations::RootOrganization.new(
60
+ organizations: [organization_writer.organization_element]
61
+ )
62
+ element.root_resource = resources_writer.root_resource_element
63
+ end
64
+ end
65
+
66
+ private def metadata_writer
67
+ @factory.manifest_metadata_writer
68
+ end
69
+
70
+ private def organization_writer
71
+ @factory.manifest_organization_writer
72
+ end
73
+
74
+ private def resources_writer
75
+ @factory.manifest_resources_writer
76
+ end
77
+
78
+ private def required_namespaces
79
+ XmlDefinitions::REQUIRED_NAMESPACES[@version]
80
+ end
81
+
82
+ private def xsi_schema_location
83
+ locations = XmlDefinitions::REQUIRED_SCHEMA_LOCATIONS[@version]
84
+ locations.flatten.join(' ')
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,54 @@
1
+ # multi_version_common_cartridge
2
+ # Copyright © 2019 Vista Higher Learning, Inc.
3
+ #
4
+ # multi_version_common_cartridge is free software: you can redistribute it
5
+ # and/or modify it under the terms of the GNU General Public
6
+ # License as published by the Free Software Foundation, either
7
+ # version 3 of the License, or (at your option) any later version.
8
+ #
9
+ # multi_version_common_cartridge is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with multi_version_common_cartridge. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ module MultiVersionCommonCartridge
18
+ module Writers
19
+ class ResourceWriter
20
+ include SupportedVersions
21
+
22
+ attr_reader :resource
23
+
24
+ def initialize(resource, version)
25
+ @resource = resource
26
+ @version = validate_version(version)
27
+ end
28
+
29
+ def finalize
30
+ resource.identifier ||= 'i_' + Digest::MD5.hexdigest("resource #{resource.object_id}")
31
+ end
32
+
33
+ def resource_element
34
+ CommonCartridge::Elements::Resources::Resource.new.tap do |element|
35
+ element.identifier = resource.identifier
36
+ element.type = type
37
+ element.href = resource.href
38
+ element.files = files.map do |file|
39
+ CommonCartridge::Elements::Resources::File.new(href: file)
40
+ end
41
+ end
42
+ end
43
+
44
+ def type
45
+ raise NotImplementedError, 'Subclasses must implement the type method ' \
46
+ 'that returns the correct resource type.'
47
+ end
48
+
49
+ def files
50
+ []
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,37 @@
1
+ # multi_version_common_cartridge
2
+ # Copyright © 2019 Vista Higher Learning, Inc.
3
+ #
4
+ # multi_version_common_cartridge is free software: you can redistribute it
5
+ # and/or modify it under the terms of the GNU General Public
6
+ # License as published by the Free Software Foundation, either
7
+ # version 3 of the License, or (at your option) any later version.
8
+ #
9
+ # multi_version_common_cartridge is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with multi_version_common_cartridge. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ module MultiVersionCommonCartridge
18
+ module Writers
19
+ module SupportedVersions
20
+ SUPPORTED_VERSIONS = [
21
+ MultiVersionCommonCartridge::CartridgeVersions::CC_1_1_0,
22
+ MultiVersionCommonCartridge::CartridgeVersions::CC_1_2_0,
23
+ MultiVersionCommonCartridge::CartridgeVersions::CC_1_3_0,
24
+ MultiVersionCommonCartridge::CartridgeVersions::THIN_CC_1_2_0,
25
+ MultiVersionCommonCartridge::CartridgeVersions::THIN_CC_1_3_0
26
+ ].freeze
27
+ UNSUPPORTED_VERSION_MSG_TEMPLATE = "Unsupported common cartridge version '%<version>s'".freeze
28
+
29
+ def validate_version(version)
30
+ unless SUPPORTED_VERSIONS.include?(version)
31
+ raise ArgumentError, format(UNSUPPORTED_VERSION_MSG_TEMPLATE, version: version)
32
+ end
33
+ version
34
+ end
35
+ end
36
+ end
37
+ end