Class: Superstore::Adapters::AbstractAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/superstore/adapters/abstract_adapter.rb

Direct Known Subclasses

JsonbAdapter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ AbstractAdapter

Returns a new instance of AbstractAdapter.



5
6
7
8
# File 'lib/superstore/adapters/abstract_adapter.rb', line 5

def initialize(config)
  @config = config
  @batch_statements = nil
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



4
5
6
# File 'lib/superstore/adapters/abstract_adapter.rb', line 4

def config
  @config
end

Instance Method Details

#batchObject



33
34
35
36
37
38
39
# File 'lib/superstore/adapters/abstract_adapter.rb', line 33

def batch
  @batch_statements = []
  yield
  execute_batch(@batch_statements) if @batch_statements.any?
ensure
  @batch_statements = nil
end

#batching?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/superstore/adapters/abstract_adapter.rb', line 29

def batching?
  !@batch_statements.nil?
end

#delete(table, ids) ⇒ Object

Delete rows by an array of ids



23
24
# File 'lib/superstore/adapters/abstract_adapter.rb', line 23

def delete(table, ids) # abstract
end

#execute_batch(statements) ⇒ Object

abstract



26
27
# File 'lib/superstore/adapters/abstract_adapter.rb', line 26

def execute_batch(statements) # abstract
end

#execute_batchable(statement) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/superstore/adapters/abstract_adapter.rb', line 41

def execute_batchable(statement)
  if @batch_statements
    @batch_statements << statement
  else
    execute statement
  end
end

#insert(table, id, attributes) ⇒ Object

Insert a new row



15
16
# File 'lib/superstore/adapters/abstract_adapter.rb', line 15

def insert(table, id, attributes) # abstract
end

#select(scope) ⇒ Object

Read records from a instance of Superstore::Scope



11
12
# File 'lib/superstore/adapters/abstract_adapter.rb', line 11

def select(scope) # abstract
end

#update(table, id, attributes) ⇒ Object

Update an existing row



19
20
# File 'lib/superstore/adapters/abstract_adapter.rb', line 19

def update(table, id, attributes) # abstract
end