Class: Hws::Transactions::Models::TransactionGroup
- Defined in:
- lib/hws-transactions/models/transaction_group.rb
Constant Summary collapse
- DEFAULT_LIMIT =
10
Instance Method Summary collapse
-
#add_entry(value, txn_time, tags = {}) ⇒ Object
tags: hash of the form mentioned below.
- #immutable_tags ⇒ Object
-
#list_entries(filters = {}, page_context = {}) ⇒ Object
filters struture: { ‘col1’ => ‘val1’, ‘col2’ => ‘val2’, ‘mut1’ => { ‘jsonf1’ => ‘val1’, ‘jsonf2’ => => ‘val2’ } } pagination_context structure: { ‘last_entry’: ”, ‘page_size’: 10 }.
- #mutable_tags ⇒ Object
-
#update_entry(entry_id, mutable_tags) ⇒ Object
only mutable tags are allowed to be updated TODO: Optimistic locking?.
Methods inherited from Base
Instance Method Details
#add_entry(value, txn_time, tags = {}) ⇒ Object
tags: hash of the form mentioned below.
'mutable_tags': {mutable_tag_key1: m_tag_val1, mutable_tag_key2: m_tag_val2,
'immutable_tags': i_tag_val1, immutable_tag_key2: i_tag_val2
}
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/hws-transactions/models/transaction_group.rb', line 17 def add_entry(value, txn_time, = {}) = () self.transaction_entries.create( value: value, txn_time: txn_time, mutable_tags: ['mutable_tags'], immutable_tags: ['immutable_tags'] ) end |
#immutable_tags ⇒ Object
72 73 74 75 |
# File 'lib/hws-transactions/models/transaction_group.rb', line 72 def @i_tags ||= self.['immutable_tags'].to_set @i_tags end |
#list_entries(filters = {}, page_context = {}) ⇒ Object
filters struture:
'col1' => 'val1',
'col2' => 'val2',
'mut1' => {
'jsonf1' => 'val1',
'jsonf2' => {'nested_jsonf3' => 'val2'
}
} pagination_context structure: {
'last_entry': '',
'page_size': 10
}
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/hws-transactions/models/transaction_group.rb', line 54 def list_entries(filters = {}, page_context = {}) filtered_query = if filters.empty? self.transaction_entries else Hws::Helpers::Query.construct_query(self.transaction_entries, filters) end unless page_context['last_entry'].nil? filtered_query = filtered_query.where('id > ?', page_context['last_entry']) end filtered_query.order('id').limit(page_context['page_size'] || DEFAULT_LIMIT) end |
#mutable_tags ⇒ Object
67 68 69 70 |
# File 'lib/hws-transactions/models/transaction_group.rb', line 67 def @m_tags ||= self.['mutable_tags'].to_set @m_tags end |
#update_entry(entry_id, mutable_tags) ⇒ Object
only mutable tags are allowed to be updated TODO: Optimistic locking?
30 31 32 33 34 35 36 37 38 |
# File 'lib/hws-transactions/models/transaction_group.rb', line 30 def update_entry(entry_id, ) entry = self.transaction_entries.find(entry_id) unless .keys.all? { |key| self..include?(key) } raise 'Invalid mutable tags present in update_entry request.' end entry.update!(mutable_tags: entry..merge()) end |