Class: Qa::LinkedData::Config::Helper

Inherits:
Object
  • Object
show all
Defined in:
app/models/qa/linked_data/config/helper.rb

Class Method Summary collapse

Class Method Details

.fetch(map, key, default) ⇒ Object

Fetch a value from a hash map



7
8
9
# File 'app/models/qa/linked_data/config/helper.rb', line 7

def self.fetch(map, key, default)
  map.fetch(key, default)
end

.fetch_boolean(map, key, default) ⇒ Object

Fetch a boolean value from a hash map throwing an exception if the value is not boolean



12
13
14
15
16
# File 'app/models/qa/linked_data/config/helper.rb', line 12

def self.fetch_boolean(map, key, default)
  value = map.fetch(key, default)
  raise Qa::InvalidConfiguration, "#{key} must be true or false" unless value == true || value == false
  value
end

.fetch_required(map, key, default) ⇒ Object

Fetch a value from a hash map throwing an exception if the value is blank



19
20
21
22
23
# File 'app/models/qa/linked_data/config/helper.rb', line 19

def self.fetch_required(map, key, default)
  value = map.fetch(key, default)
  raise Qa::InvalidConfiguration, "#{key} is required" unless value
  value
end

.fetch_symbol(map, key, default) ⇒ Object

Fetch a value from a hash map throwing an exception if the value is blank



26
27
28
29
30
# File 'app/models/qa/linked_data/config/helper.rb', line 26

def self.fetch_symbol(map, key, default)
  value = map.fetch(key, default)
  return value unless value.respond_to? :to_sym
  value.to_sym
end