Class: Hyrax::Microdata

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
app/services/hyrax/microdata.rb

Overview

Note:

This was extracted from internationalization because Schema.org keys are not internationalized

Responsible for extracting information related to Schema.org microdata.

You may load more than one source file. Source files that are later in the load process will overlay files that are earlier.

Constant Summary collapse

FILENAME =
Hyrax::Engine.root + 'config/schema_org.yml'
TOP_KEY =
'schema_org'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.clear_load_paths!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



53
54
55
56
# File 'app/services/hyrax/microdata.rb', line 53

def self.clear_load_paths!
  @load_paths = nil
  reload!
end

.fetch(key, default: nil) ⇒ Object

TODO:

Should we make specific methods for fetching :property, :type, :value. This would mean privatizing the fetch method

Parameters:

  • key (String)
  • default (String) (defaults to: nil)
    • if we don’t have a key match, use the given default value



21
22
23
# File 'app/services/hyrax/microdata.rb', line 21

def self.fetch(key, default: nil)
  instance.fetch(key, default: default)
end

.load_pathsArray<String>

Note:

The load paths will be processed and loaded into in the natural array order. As each file is loaded, it overlays the already registered keys.

Allow clients to register paths providing config data sources. Register a config files like this:

Microdata.load_path << 'path/to/locale/en.yml'

Returns:

  • (Array<String>)


38
39
40
# File 'app/services/hyrax/microdata.rb', line 38

def self.load_paths
  @load_paths ||= [FILENAME]
end

.load_paths=(input) ⇒ Object

Sets the load_paths

Parameters:

  • (String, Array<String>)


47
48
49
50
# File 'app/services/hyrax/microdata.rb', line 47

def self.load_paths=(input)
  @load_paths = Array.wrap(input)
  reload! # If we are obliterating load paths, we really should clear data
end

.reload!Object



59
60
61
# File 'app/services/hyrax/microdata.rb', line 59

def self.reload!
  instance.reload!
end

Instance Method Details

#fetch(key, default:) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



26
27
28
# File 'app/services/hyrax/microdata.rb', line 26

def fetch(key, default:)
  data.fetch(key) { default }
end

#reload!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



64
65
66
# File 'app/services/hyrax/microdata.rb', line 64

def reload!
  @data = nil
end