Class: Virsandra::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/virsandra/configuration.rb

Constant Summary collapse

OPTIONS =
[
  :consistency,
  :keyspace,
  :servers,
].freeze
DEFAULT_OPTION_VALUES =
{
  servers: "127.0.0.1",
  consistency: :quorum
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Configuration

Returns a new instance of Configuration.



16
17
18
19
20
# File 'lib/virsandra/configuration.rb', line 16

def initialize(options = {})
  reset!
  use_options(options || {})
  accept_changes
end

Instance Method Details

#accept_changesObject



32
33
34
# File 'lib/virsandra/configuration.rb', line 32

def accept_changes
  @old_hash = hash
end

#changed?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/virsandra/configuration.rb', line 42

def changed?
  hash != @old_hash
end

#hashObject



46
47
48
# File 'lib/virsandra/configuration.rb', line 46

def hash
  to_hash.hash
end

#reset!Object



22
23
24
# File 'lib/virsandra/configuration.rb', line 22

def reset!
  use_options(DEFAULT_OPTION_VALUES)
end

#to_hashObject



36
37
38
39
40
# File 'lib/virsandra/configuration.rb', line 36

def to_hash
  OPTIONS.each_with_object({}) do |attr, settings|
    settings[attr] = send(attr)
  end
end

#validate!Object



26
27
28
29
30
# File 'lib/virsandra/configuration.rb', line 26

def validate!
  unless [servers, keyspace].all?
    raise ConfigurationError.new("A keyspace and server must be defined")
  end
end