Class: Rom::Dynamo::Gateway
- Inherits:
-
ROM::Gateway
- Object
- ROM::Gateway
- Rom::Dynamo::Gateway
- Defined in:
- lib/rom/dynamo/gateway.rb
Instance Attribute Summary collapse
-
#ddb ⇒ Object
readonly
Returns the value of attribute ddb.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #[](name) ⇒ Object
- #dataset(name) ⇒ Object
- #dataset?(name) ⇒ Boolean
-
#initialize(uri) ⇒ Gateway
constructor
A new instance of Gateway.
- #use_logger(logger) ⇒ Object
Constructor Details
#initialize(uri) ⇒ Gateway
Returns a new instance of Gateway.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/rom/dynamo/gateway.rb', line 9 def initialize(uri) uri = Addressable::URI.parse(uri) opts = { region: uri.host } opts.merge!(uri.query_values) if uri.query opts.keys.each { |k| opts[k.to_sym] = opts.delete(k) } @options = opts @ddb = Aws::DynamoDB::Client.new(@options) @prefix = uri.path.gsub('/', '') @datasets = {} end |
Instance Attribute Details
#ddb ⇒ Object (readonly)
Returns the value of attribute ddb.
7 8 9 |
# File 'lib/rom/dynamo/gateway.rb', line 7 def ddb @ddb end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
7 8 9 |
# File 'lib/rom/dynamo/gateway.rb', line 7 def logger @logger end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/rom/dynamo/gateway.rb', line 7 def @options end |
Instance Method Details
#[](name) ⇒ Object
34 35 36 |
# File 'lib/rom/dynamo/gateway.rb', line 34 def [](name) @datasets["#{@prefix}#{name}"] end |
#dataset(name) ⇒ Object
25 26 27 28 |
# File 'lib/rom/dynamo/gateway.rb', line 25 def dataset(name) name = "#{@prefix}#{name}" @datasets[name] ||= _has?(name) && Dataset.new(connection: @ddb, name: name, logger: @logger) end |
#dataset?(name) ⇒ Boolean
30 31 32 |
# File 'lib/rom/dynamo/gateway.rb', line 30 def dataset?(name) !!self[name] end |
#use_logger(logger) ⇒ Object
21 22 23 |
# File 'lib/rom/dynamo/gateway.rb', line 21 def use_logger(logger) @logger = logger end |