Class: Dradis::Plugins::Settings::Adapters::Db

Inherits:
Object
  • Object
show all
Defined in:
lib/dradis/plugins/settings/adapters/db.rb

Instance Method Summary collapse

Constructor Details

#initialize(namespace) ⇒ Db

Returns a new instance of Db.



3
4
5
# File 'lib/dradis/plugins/settings/adapters/db.rb', line 3

def initialize(namespace)
  @namespace = namespace.to_s
end

Instance Method Details

#delete(key) ⇒ Object



7
8
9
# File 'lib/dradis/plugins/settings/adapters/db.rb', line 7

def delete(key)
  Configuration.find_by(name: namespaced_key(key)).destroy
end

#exists?(key) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/dradis/plugins/settings/adapters/db.rb', line 11

def exists?(key)
  Configuration.exists?(name: namespaced_key(key))
end

#read(key) ⇒ Object



15
16
17
# File 'lib/dradis/plugins/settings/adapters/db.rb', line 15

def read(key)
  Configuration.find_by(name: namespaced_key(key))&.value
end

#write(key, value) ⇒ Object



19
20
21
22
# File 'lib/dradis/plugins/settings/adapters/db.rb', line 19

def write(key, value)
  db_setting = Configuration.find_or_create_by(name: namespaced_key(key))
  db_setting.update_attribute(:value, value)
end