Class: Hyrax::FlexibleSchema

Inherits:
ApplicationRecord
  • Object
show all
Defined in:
app/models/hyrax/flexible_schema.rb

Overview

rubocop:disable Metrics/ClassLength

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create_default_schemaObject

Raises:

  • (ArgumentError)


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_idObject



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_versionObject



12
13
14
# File 'app/models/hyrax/flexible_schema.rb', line 12

def self.current_version
  order("created_at asc").last&.profile
end

.default_propertiesArray

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

Returns:

  • (Array)

    property#to_sym



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_selectObject



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_typeObject



77
78
79
# File 'app/models/hyrax/flexible_schema.rb', line 77

def 
  profile['profile']['type']
end

#profile_created_atObject



85
86
87
# File 'app/models/hyrax/flexible_schema.rb', line 85

def profile_created_at
  created_at.strftime("%b %d, %Y")
end

#schema_versionObject



69
70
71
# File 'app/models/hyrax/flexible_schema.rb', line 69

def schema_version
  profile['m3_version']
end

#titleObject



61
62
63
# File 'app/models/hyrax/flexible_schema.rb', line 61

def title
  "#{profile['profile']['responsibility_statement']} - version #{id}"
end

#update_contextsObject



57
58
59
# File 'app/models/hyrax/flexible_schema.rb', line 57

def update_contexts
  self.contexts = profile['contexts']
end

#versionObject



81
82
83
# File 'app/models/hyrax/flexible_schema.rb', line 81

def version
  id
end