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.
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
19 20 21 22 23 24 25 |
# File 'app/models/hyrax/flexible_schema.rb', line 19 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 Hyrax::FlexibleSchema.first_or_create do |f| f.profile = YAML.safe_load_file(m3_profile_path) end end |
.current_schema_id ⇒ Object
15 16 17 |
# File 'app/models/hyrax/flexible_schema.rb', line 15 def self.current_schema_id order("created_at asc").last&.id end |
.current_version ⇒ Object
11 12 13 |
# File 'app/models/hyrax/flexible_schema.rb', line 11 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
34 35 36 37 38 |
# File 'app/models/hyrax/flexible_schema.rb', line 34 def self.default_properties current_version['properties'].symbolize_keys!.keys rescue StandardError [] end |
Instance Method Details
#attributes_for(class_name) ⇒ Object
48 49 50 |
# File 'app/models/hyrax/flexible_schema.rb', line 48 def attributes_for(class_name) class_names[class_name] end |
#context_select ⇒ Object
56 57 58 |
# File 'app/models/hyrax/flexible_schema.rb', line 56 def context_select contexts&.map { |k, v| [v&.[]('display_label'), k] } end |
#metadata_profile_type ⇒ Object
60 61 62 |
# File 'app/models/hyrax/flexible_schema.rb', line 60 def profile['profile']['type'] end |
#profile_created_at ⇒ Object
68 69 70 |
# File 'app/models/hyrax/flexible_schema.rb', line 68 def profile_created_at created_at.strftime("%b %d, %Y") end |
#schema_version ⇒ Object
52 53 54 |
# File 'app/models/hyrax/flexible_schema.rb', line 52 def schema_version profile['m3_version'] end |
#title ⇒ Object
44 45 46 |
# File 'app/models/hyrax/flexible_schema.rb', line 44 def title "#{profile['profile']['responsibility_statement']} - version #{id}" end |
#update_contexts ⇒ Object
40 41 42 |
# File 'app/models/hyrax/flexible_schema.rb', line 40 def update_contexts self.contexts = profile['contexts'] end |
#version ⇒ Object
64 65 66 |
# File 'app/models/hyrax/flexible_schema.rb', line 64 def version id end |