Module: PgEventstore::Extensions::ActsAsConfigurable::Configurable
- Defined in:
- lib/pg_eventstore/extensions/acts_as_configurable.rb,
sig/pg_eventstore/extensions/acts_as_configurable.rbs
Instance Attribute Summary collapse
-
#mutex ⇒ Thread::Mutex
Returns the value of attribute mutex.
Instance Method Summary collapse
- #available_configs ⇒ Array<Symbol>
- #config(name = const_get(:DEFAULT_CONFIG)) ⇒ PgEventstore::Config
-
#configure(name: const_get(:DEFAULT_CONFIG)) {|arg0| ... } ⇒ Object
Creates a Config if not exists and yields it to the given block.
-
#connection(name = const_get(:DEFAULT_CONFIG)) ⇒ PgEventstore::Connection
Look ups and returns a Connection, based on the given config.
-
#connection_options(config) ⇒ Hash
{ uri: String, pool_size: Integer, pool_timeout: Integer }.
- #init_variables ⇒ void
Instance Attribute Details
#mutex ⇒ Thread::Mutex
Returns the value of attribute mutex.
19 20 21 |
# File 'lib/pg_eventstore/extensions/acts_as_configurable.rb', line 19 def mutex @mutex end |
Instance Method Details
#available_configs ⇒ Array<Symbol>
42 43 44 |
# File 'lib/pg_eventstore/extensions/acts_as_configurable.rb', line 42 def available_configs @config.keys end |
#config(name = const_get(:DEFAULT_CONFIG)) ⇒ PgEventstore::Config
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/pg_eventstore/extensions/acts_as_configurable.rb', line 48 def config(name = const_get(:DEFAULT_CONFIG)) return @config[name] if @config[name] = " Could not find \#{name.inspect} config. You can define it like this:\n \#{self}.configure(name: \#{name.inspect}) do |config|\n # your config goes here\n end\n TEXT\n raise error_message\nend\n" |
#configure(name: const_get(:DEFAULT_CONFIG)) {|arg0| ... } ⇒ Object
Creates a Config if not exists and yields it to the given block.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/pg_eventstore/extensions/acts_as_configurable.rb', line 25 def configure(name: const_get(:DEFAULT_CONFIG)) config_class = const_get(:CONFIG_CLASS) mutex.synchronize do @config[name] = @config[name] ? config_class.new(name:, **@config[name].) : config_class.new(name:) connection_config_was = (@config[name]) yield(@config[name]).tap do @config[name].freeze next if connection_config_was == (@config[name]) # Reset the connection if user decided to reconfigure connection's options @connection.delete(name) end end end |
#connection(name = const_get(:DEFAULT_CONFIG)) ⇒ PgEventstore::Connection
Look ups and returns a Connection, based on the given config. If not exists - it creates one. This operation is a thread-safe
64 65 66 67 68 |
# File 'lib/pg_eventstore/extensions/acts_as_configurable.rb', line 64 def connection(name = const_get(:DEFAULT_CONFIG)) mutex.synchronize do @connection[name] ||= Connection.new(**(config(name))) end end |
#connection_options(config) ⇒ Hash
Returns { uri: String, pool_size: Integer, pool_timeout: Integer }.
74 75 76 |
# File 'lib/pg_eventstore/extensions/acts_as_configurable.rb', line 74 def (config) raise NotImplementedError end |
#init_variables ⇒ void
This method returns an undefined value.
79 80 81 82 83 84 |
# File 'lib/pg_eventstore/extensions/acts_as_configurable.rb', line 79 def init_variables default_config = const_get(:DEFAULT_CONFIG) @config = { default_config => const_get(:CONFIG_CLASS).new(name: default_config) } @connection = {} @mutex = Thread::Mutex.new end |