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)


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_idObject



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_versionObject



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

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



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_selectObject



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_typeObject



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

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

#profile_created_atObject



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

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

#schema_versionObject



52
53
54
# File 'app/models/hyrax/flexible_schema.rb', line 52

def schema_version
  profile['m3_version']
end

#titleObject



44
45
46
# File 'app/models/hyrax/flexible_schema.rb', line 44

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

#update_contextsObject



40
41
42
# File 'app/models/hyrax/flexible_schema.rb', line 40

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

#versionObject



64
65
66
# File 'app/models/hyrax/flexible_schema.rb', line 64

def version
  id
end