Class: Petra::Configuration::Base
- Inherits:
-
Object
- Object
- Petra::Configuration::Base
- Defined in:
- lib/petra/configuration/base.rb
Constant Summary collapse
- DEFAULTS =
{ persistence_adapter_name: 'file', log_level: 'debug', instant_read_integrity_fail: true }.freeze
Instance Method Summary collapse
-
#__configuration_hash(*sub_keys) ⇒ Hash
The complete configuration or one of its sub-namespaces.
-
#class_configurator(class_name) ⇒ Object
(also: #[])
Builds a ClassConfigurator for the given class or class name.
-
#configure_class(class_name, &proc) ⇒ Object
Executes the given block in the context of a ClassConfigurator to configure petra’s behaviour for a certain model/class.
-
#instant_read_integrity_fail(new_value = nil) ⇒ Object
(also: #instantly_fail_on_read_integrity_errors)
Configures whether a read integrity error will be automatically detected whenever an attribute is read.
-
#log_level(new_value = nil) ⇒ Object
The log level for petra.
-
#persistence_adapter(name = nil) ⇒ Class
Sets the adapter to be used as transaction persistence adapter.
-
#proxy_class_instances(*class_names) ⇒ Object
A shortcut method to set
proxy_instances
for multiple classes at once without having toconfigure_class
for each one.
Instance Method Details
#__configuration_hash(*sub_keys) ⇒ Hash
Returns the complete configuration or one of its sub-namespaces. If a namespace does not exists yet, it will be initialized with an empty hash.
114 115 116 117 118 |
# File 'lib/petra/configuration/base.rb', line 114 def __configuration_hash(*sub_keys) sub_keys.inject(@configuration ||= {}) do |h, k| h[k] ||= {} end end |
#class_configurator(class_name) ⇒ Object Also known as: []
Builds a ClassConfigurator for the given class or class name.
100 101 102 |
# File 'lib/petra/configuration/base.rb', line 100 def class_configurator(class_name) ClassConfigurator.for_class(class_name) end |
#configure_class(class_name, &proc) ⇒ Object
Executes the given block in the context of a ClassConfigurator to configure petra’s behaviour for a certain model/class
88 89 90 91 92 |
# File 'lib/petra/configuration/base.rb', line 88 def configure_class(class_name, &proc) configurator = class_configurator(class_name) configurator.instance_eval(&proc) configurator.__persist! end |
#instant_read_integrity_fail(new_value = nil) ⇒ Object Also known as: instantly_fail_on_read_integrity_errors
Configures whether a read integrity error will be automatically detected whenever an attribute is read. If this is set to false
, the read values will only be checked during the commit phase.
23 24 25 26 27 28 29 |
# File 'lib/petra/configuration/base.rb', line 23 def instant_read_integrity_fail(new_value = nil) if !new_value.nil? __configuration_hash[:instant_read_integrity_fail] = new_value else __config_or_default(:instant_read_integrity_fail) end end |
#log_level(new_value = nil) ⇒ Object
The log level for petra. Only messages which are greater or equal to this level will be shown in the output
57 58 59 60 61 62 63 |
# File 'lib/petra/configuration/base.rb', line 57 def log_level(new_value = nil) if new_value __configuration_hash[:log_level] = new_value.to_s else __config_or_default(:log_level).to_sym end end |
#persistence_adapter(name = nil) ⇒ Class
Sets the adapter to be used as transaction persistence adapter. An adapter has to be registered before it may be used (see Adapter)
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/petra/configuration/base.rb', line 40 def persistence_adapter(name = nil) if name unless Petra::PersistenceAdapters::Adapter.registered_adapter?(name) fail Petra::ConfigurationError, "The given adapter `#{name}` hasn't been registered. " \ "Valid adapters are: #{Petra::PersistenceAdapters::Adapter.registered_adapters.keys.inspect}" end __configuration_hash[:persistence_adapter_name] = name else Petra::PersistenceAdapters::Adapter[__config_or_default(:persistence_adapter_name)] end end |
#proxy_class_instances(*class_names) ⇒ Object
A shortcut method to set proxy_instances
for multiple classes at once without having to configure_class
for each one.
76 77 78 79 80 81 82 |
# File 'lib/petra/configuration/base.rb', line 76 def proxy_class_instances(*class_names) class_names.each do |klass| configure_class(klass) do proxy_instances true end end end |