Class: Hyrax::FlexibleSchema
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- Hyrax::FlexibleSchema
- Defined in:
- app/models/hyrax/flexible_schema.rb
Overview
rubocop:disable Metrics/ClassLength
Class Method Summary collapse
- .create_default_schema ⇒ Object
- .current_schema_id ⇒ Object
- .current_version ⇒ Object
-
.default_properties ⇒ Array
Retrieve the properties for the model / work type This is a class method called by the model at class load meaning AdminSet is not available and we cannot get the contextual dynamic_schema Instead we use the default (contextless) dynamic_schema which will add all properties available for that class.
-
.mappings_data_for(mapping = 'simple_dc_pmh') ⇒ Object
Retrieve the required data to use for mappings.
Instance Method Summary collapse
- #attributes_for(class_name) ⇒ Object
- #context_select ⇒ Object
- #metadata_profile_type ⇒ Object
- #profile_created_at ⇒ Object
- #schema_version ⇒ Object
- #title ⇒ Object
- #update_contexts ⇒ Object
- #version ⇒ Object
Class Method Details
.create_default_schema ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'app/models/hyrax/flexible_schema.rb', line 20 def self.create_default_schema m3_profile_path = Hyrax::Schema.m3_schema_loader.config_paths&.first raise ArgumentError, "No M3 profile found, check the Hyrax.config.schema_loader_config_search_paths" unless m3_profile_path schema = Hyrax::FlexibleSchema.first return if schema schema = Hyrax::FlexibleSchema.new(profile: YAML.safe_load_file(m3_profile_path)) schema.save(validate: false) schema end |
.current_schema_id ⇒ Object
16 17 18 |
# File 'app/models/hyrax/flexible_schema.rb', line 16 def self.current_schema_id order("created_at asc").last&.id end |
.current_version ⇒ Object
12 13 14 |
# File 'app/models/hyrax/flexible_schema.rb', line 12 def self.current_version order("created_at asc").last&.profile end |
.default_properties ⇒ Array
Retrieve the properties for the model / work type This is a class method called by the model at class load
meaning AdminSet is not available and we cannot get the
contextual dynamic_schema
Instead we use the default (contextless) dynamic_schema
which will add all properties available for that class
37 38 39 40 41 |
# File 'app/models/hyrax/flexible_schema.rb', line 37 def self.default_properties current_version['properties'].symbolize_keys!.keys rescue StandardError [] end |
.mappings_data_for(mapping = 'simple_dc_pmh') ⇒ Object
Retrieve the required data to use for mappings
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/models/hyrax/flexible_schema.rb', line 44 def self.mappings_data_for(mapping = 'simple_dc_pmh') # for OAI-PMH we need the mappings and indexing info # for properties with the specified mapping return {} unless current_version current_version['properties'].each_with_object({}) do |(key, values), obj| next unless values['mappings'] && values['mappings'][mapping] obj[key] = { 'indexing' => values['indexing'], 'mappings' => { mapping => values['mappings'][mapping] } } end end |
Instance Method Details
#attributes_for(class_name) ⇒ Object
65 66 67 |
# File 'app/models/hyrax/flexible_schema.rb', line 65 def attributes_for(class_name) class_names[class_name] end |
#context_select ⇒ Object
73 74 75 |
# File 'app/models/hyrax/flexible_schema.rb', line 73 def context_select contexts&.map { |k, v| [v&.[]('display_label'), k] } end |
#metadata_profile_type ⇒ Object
77 78 79 |
# File 'app/models/hyrax/flexible_schema.rb', line 77 def profile['profile']['type'] end |
#profile_created_at ⇒ Object
85 86 87 |
# File 'app/models/hyrax/flexible_schema.rb', line 85 def profile_created_at created_at.strftime("%b %d, %Y") end |
#schema_version ⇒ Object
69 70 71 |
# File 'app/models/hyrax/flexible_schema.rb', line 69 def schema_version profile['m3_version'] end |
#title ⇒ Object
61 62 63 |
# File 'app/models/hyrax/flexible_schema.rb', line 61 def title "#{profile['profile']['responsibility_statement']} - version #{id}" end |
#update_contexts ⇒ Object
57 58 59 |
# File 'app/models/hyrax/flexible_schema.rb', line 57 def update_contexts self.contexts = profile['contexts'] end |
#version ⇒ Object
81 82 83 |
# File 'app/models/hyrax/flexible_schema.rb', line 81 def version id end |