Class: Foobara::Persistence::EntityAttributesCrudDriver
- Inherits:
-
Object
- Object
- Foobara::Persistence::EntityAttributesCrudDriver
- Defined in:
- foobara-0.3.0/projects/persistence/src/entity_attributes_crud_driver.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Table
Instance Attribute Summary collapse
-
#raw_connection ⇒ Object
Returns the value of attribute raw_connection.
-
#table_prefix ⇒ Object
Returns the value of attribute table_prefix.
-
#tables ⇒ Object
Returns the value of attribute tables.
Class Method Summary collapse
Instance Method Summary collapse
- #commit_transaction(_raw_tx) ⇒ Object
- #flush_transaction(_raw_tx) ⇒ Object
-
#initialize(connection_or_credentials = nil, table_prefix: nil, connect: true) ⇒ EntityAttributesCrudDriver
constructor
A new instance of EntityAttributesCrudDriver.
-
#open_connection(_connection_or_credentials) ⇒ Object
Default behavior is for technologies that don’t have a connection concept in a proper sense.
-
#open_transaction ⇒ Object
Default behavior is for storage technologies that don’t support proper transaction support.
- #revert_transaction(_raw_tx) ⇒ Object
- #rollback_transaction(_raw_tx) ⇒ Object
- #table_for(entity_class) ⇒ Object
Constructor Details
#initialize(connection_or_credentials = nil, table_prefix: nil, connect: true) ⇒ EntityAttributesCrudDriver
Returns a new instance of EntityAttributesCrudDriver.
13 14 15 16 17 18 19 20 |
# File 'projects/persistence/src/entity_attributes_crud_driver.rb', line 13 def initialize(connection_or_credentials = nil, table_prefix: nil, connect: true) self.table_prefix = table_prefix self.tables = {} if connect self.raw_connection = open_connection(connection_or_credentials) end end |
Instance Attribute Details
#raw_connection ⇒ Object
Returns the value of attribute raw_connection.
5 6 7 |
# File 'projects/persistence/src/entity_attributes_crud_driver.rb', line 5 def raw_connection @raw_connection end |
#table_prefix ⇒ Object
Returns the value of attribute table_prefix.
5 6 7 |
# File 'projects/persistence/src/entity_attributes_crud_driver.rb', line 5 def table_prefix @table_prefix end |
#tables ⇒ Object
Returns the value of attribute tables.
5 6 7 |
# File 'projects/persistence/src/entity_attributes_crud_driver.rb', line 5 def tables @tables end |
Class Method Details
.has_real_transactions? ⇒ Boolean
8 9 10 |
# File 'projects/persistence/src/entity_attributes_crud_driver.rb', line 8 def has_real_transactions? false end |
Instance Method Details
#commit_transaction(_raw_tx) ⇒ Object
44 45 |
# File 'projects/persistence/src/entity_attributes_crud_driver.rb', line 44 def commit_transaction(_raw_tx) end |
#flush_transaction(_raw_tx) ⇒ Object
35 36 |
# File 'projects/persistence/src/entity_attributes_crud_driver.rb', line 35 def flush_transaction(_raw_tx) end |
#open_connection(_connection_or_credentials) ⇒ Object
Default behavior is for technologies that don’t have a connection concept in a proper sense
24 25 26 |
# File 'projects/persistence/src/entity_attributes_crud_driver.rb', line 24 def open_connection(_connection_or_credentials) # should we return some kind of Connection object here even if it does nothing interesting? end |
#open_transaction ⇒ Object
Default behavior is for storage technologies that don’t support proper transaction support
30 31 32 33 |
# File 'projects/persistence/src/entity_attributes_crud_driver.rb', line 30 def open_transaction # Should we have some kind of fake transaction object that raises errors when used after rolledback/closed? Object.new end |
#revert_transaction(_raw_tx) ⇒ Object
38 39 |
# File 'projects/persistence/src/entity_attributes_crud_driver.rb', line 38 def revert_transaction(_raw_tx) end |
#rollback_transaction(_raw_tx) ⇒ Object
41 42 |
# File 'projects/persistence/src/entity_attributes_crud_driver.rb', line 41 def rollback_transaction(_raw_tx) end |
#table_for(entity_class) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'projects/persistence/src/entity_attributes_crud_driver.rb', line 47 def table_for(entity_class) key = entity_class.full_entity_name tables[key] ||= begin if table_prefix table_name = entity_class.entity_name table_name.gsub!(/^Types::/, "") table_name = Util.underscore(entity_class.entity_name) table_name = if table_prefix == true "#{Util.underscore(entity_class.domain.scoped_full_name)}_#{table_name}" else "#{table_prefix}_#{table_name}" end table_name.gsub!("::", "_") end # TODO: this seems like a smell Persistence.bases_need_sorting! self.class::Table.new(entity_class, self, table_name) end end |