Class: Librarian::Config::Source
- Inherits:
-
Object
- Object
- Librarian::Config::Source
- Defined in:
- lib/librarian/config/source.rb
Direct Known Subclasses
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
-
#adapter_name ⇒ Object
readonly
Returns the value of attribute adapter_name.
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#initialize(adapter_name, options = { }) ⇒ Source
constructor
A new instance of Source.
- #keys ⇒ Object
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, = { }) self.adapter_name = adapter_name self.forbidden_keys = .delete(:forbidden_keys) || [] end |
Instance Attribute Details
#adapter_name ⇒ Object
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_pattern ⇒ Object
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_pattern ⇒ Object
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 |
#keys ⇒ Object
49 50 51 52 53 |
# File 'lib/librarian/config/source.rb', line 49 def keys load! data.keys end |