Class: Librarian::Config::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/librarian/config/source.rb

Direct Known Subclasses

FileSource, HashSource

Constant Summary collapse

RAW_KEY_SUFFIX_VALIDITY_PATTERN =
/\A[A-Z0-9_]+\z/
CONFIG_KEY_VALIDITY_PATTERN =
/\A[a-z][a-z0-9\-]+(?:\.[a-z0-9\-]+)*\z/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(adapter_name, options = { }) ⇒ Source

Returns a new instance of Source


24
25
26
27
28
# File 'lib/librarian/config/source.rb', line 24

def initialize(adapter_name, options = { })
  self.adapter_name = adapter_name

  self.forbidden_keys = options.delete(:forbidden_keys) || []
end

Instance Attribute Details

#adapter_nameObject

Returns the value of attribute adapter_name


21
22
23
# File 'lib/librarian/config/source.rb', line 21

def adapter_name
  @adapter_name
end

Class Method Details

.config_key_validity_patternObject


16
17
18
# File 'lib/librarian/config/source.rb', line 16

def config_key_validity_pattern
  CONFIG_KEY_VALIDITY_PATTERN
end

.raw_key_suffix_validity_patternObject


13
14
15
# File 'lib/librarian/config/source.rb', line 13

def raw_key_suffix_validity_pattern
  RAW_KEY_SUFFIX_VALIDITY_PATTERN
end

Instance Method Details

#[](key) ⇒ Object


30
31
32
33
34
# File 'lib/librarian/config/source.rb', line 30

def [](key)
  load!

  data[key]
end

#[]=(key, value) ⇒ Object


36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/librarian/config/source.rb', line 36

def []=(key, value)
  key_permitted?(key) or raise Error, "key not permitted: #{key.inspect}"
  value_permitted?(key, value) or raise Error, "value for key #{key.inspect} not permitted: #{value.inspect}"

  load!
  if value.nil?
    data.delete(key)
  else
    data[key] = value
  end
  save(data)
end

#keysObject


49
50
51
52
53
# File 'lib/librarian/config/source.rb', line 49

def keys
  load!

  data.keys
end