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'

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.



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

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



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

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>)


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

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

.load_paths=(input) ⇒ Object

Sets the load_paths

Parameters:

  • (String, Array<String>)


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

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



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

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.



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

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.



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

def reload!
  @data = nil
end