Class: NotionRb::Transaction

Inherits:
Object
  • Object
show all
Defined in:
lib/notion_rb/transaction.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTransaction

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

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/notion_rb/transaction.rb', line 5

def id
  @id
end

#operationsObject (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_hObject



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