Class: NotionRb::Transaction
- Inherits:
-
Object
- Object
- NotionRb::Transaction
- Defined in:
- lib/notion_rb/transaction.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#operations ⇒ Object
readonly
Returns the value of attribute operations.
Instance Method Summary collapse
- #add_operation(operation_name, *args) ⇒ Object
-
#initialize ⇒ Transaction
constructor
A new instance of Transaction.
- #to_h ⇒ Object
Constructor Details
#initialize ⇒ Transaction
Returns a new instance of Transaction.
7 8 9 10 |
# File 'lib/notion_rb/transaction.rb', line 7 def initialize @id = SecureRandom.uuid @operations = [] end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/notion_rb/transaction.rb', line 5 def id @id end |
#operations ⇒ Object (readonly)
Returns the value of attribute operations.
5 6 7 |
# File 'lib/notion_rb/transaction.rb', line 5 def operations @operations end |
Instance Method Details
#add_operation(operation_name, *args) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/notion_rb/transaction.rb', line 12 def add_operation(operation_name, *args) operations.push( Operations::Factory.build(operation_name, *args) ) self end |
#to_h ⇒ Object
19 20 21 |
# File 'lib/notion_rb/transaction.rb', line 19 def to_h { id: id, operations: operations.flat_map { |o| o.commands.map(&:to_h) } } end |