Class: Virsandra::Configuration
- Inherits:
-
Object
- Object
- Virsandra::Configuration
- 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
- #accept_changes ⇒ Object
- #changed? ⇒ Boolean
- #hash ⇒ Object
-
#initialize(options = {}) ⇒ Configuration
constructor
A new instance of Configuration.
- #reset! ⇒ Object
- #to_hash ⇒ Object
- #validate! ⇒ Object
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( = {}) reset! ( || {}) accept_changes end |
Instance Method Details
#accept_changes ⇒ Object
32 33 34 |
# File 'lib/virsandra/configuration.rb', line 32 def accept_changes @old_hash = hash end |
#changed? ⇒ Boolean
42 43 44 |
# File 'lib/virsandra/configuration.rb', line 42 def changed? hash != @old_hash end |
#hash ⇒ Object
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! (DEFAULT_OPTION_VALUES) end |
#to_hash ⇒ Object
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 |