Class: Ddr::AdminSet

Inherits:
Struct
  • Object
show all
Defined in:
app/models/ddr/admin_set.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#codeObject

Returns the value of attribute code

Returns:

  • (Object)

    the current value of code



2
3
4
# File 'app/models/ddr/admin_set.rb', line 2

def code
  @code
end

#titleObject

Returns the value of attribute title

Returns:

  • (Object)

    the current value of title



2
3
4
# File 'app/models/ddr/admin_set.rb', line 2

def title
  @title
end

Class Method Details

.allObject



12
13
14
# File 'app/models/ddr/admin_set.rb', line 12

def self.all
  keystore.values
end

.call(obj) ⇒ Object



16
17
18
# File 'app/models/ddr/admin_set.rb', line 16

def self.call(obj)
  find_by_code(obj.admin_set)
end

.configObject



4
5
6
# File 'app/models/ddr/admin_set.rb', line 4

def self.config
  @config ||= YAML.load_file(::File.expand_path('../../../config/aux/admin_set.yml', __dir__))
end

.find_by_code(code) ⇒ Object



20
21
22
23
24
25
26
27
# File 'app/models/ddr/admin_set.rb', line 20

def self.find_by_code(code)
  return unless code

  keystore.fetch(code)

rescue KeyError => _
  raise Ddr::NotFoundError, "AdminSet code '#{code}' not found."
end

.keysObject



29
30
31
# File 'app/models/ddr/admin_set.rb', line 29

def self.keys
  keystore.keys
end

.keystoreObject



8
9
10
# File 'app/models/ddr/admin_set.rb', line 8

def self.keystore
  @keystore ||= Hash[config.map { |entry| [entry['code'], new(entry).freeze] }].freeze
end

Instance Method Details

#to_sObject



33
34
35
# File 'app/models/ddr/admin_set.rb', line 33

def to_s
  title
end