Class: GreyscaleRecord::DataStore::Store
- Inherits:
-
Object
- Object
- GreyscaleRecord::DataStore::Store
- Defined in:
- lib/greyscale_record/data_store/store.rb
Instance Method Summary collapse
- #[](name) ⇒ Object
-
#apply_patch(patch) ⇒ Object
This only allows for one patch at a time.
- #init_table(name, rows) ⇒ Object
-
#initialize ⇒ Store
constructor
A new instance of Store.
- #patched? ⇒ Boolean
- #remove_patch ⇒ Object
- #table(name) ⇒ Object
- #with_patch(patch) ⇒ Object
Constructor Details
#initialize ⇒ Store
Returns a new instance of Store.
4 5 6 7 |
# File 'lib/greyscale_record/data_store/store.rb', line 4 def initialize @data = {} @tables = {} end |
Instance Method Details
#[](name) ⇒ Object
9 10 11 |
# File 'lib/greyscale_record/data_store/store.rb', line 9 def []( name ) data[ name ] end |
#apply_patch(patch) ⇒ Object
This only allows for one patch at a time. Is there ever a case when we would need, like a stack of these things? I don’t think so?
36 37 38 |
# File 'lib/greyscale_record/data_store/store.rb', line 36 def apply_patch( patch ) Thread.current[patch_key] = patched_data patch end |
#init_table(name, rows) ⇒ Object
21 22 23 24 |
# File 'lib/greyscale_record/data_store/store.rb', line 21 def init_table( name, rows ) @data[name] = rows @tables[name] = Table.new( name, self ) end |
#patched? ⇒ Boolean
44 45 46 |
# File 'lib/greyscale_record/data_store/store.rb', line 44 def patched? Thread.current[patch_key].present? end |
#remove_patch ⇒ Object
40 41 42 |
# File 'lib/greyscale_record/data_store/store.rb', line 40 def remove_patch Thread.current[patch_key] = nil end |
#table(name) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/greyscale_record/data_store/store.rb', line 13 def table( name ) unless @tables[name] raise GreyscaleRecord::Errors::DataStoreError, "Data Store error: table '#{name}' does not exist" end @tables[name] end |
#with_patch(patch) ⇒ Object
26 27 28 29 30 |
# File 'lib/greyscale_record/data_store/store.rb', line 26 def with_patch( patch ) apply_patch patch yield remove_patch end |