Class: TonClient::Context

Inherits:
Object show all
Defined in:
lib/ton-client-ruby/Client/Context.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config: {}) ⇒ Context

Returns a new instance of Context.



6
7
8
9
10
11
12
# File 'lib/ton-client-ruby/Client/Context.rb', line 6

def initialize(config: {})
  TonClient.check_configuration
  @config = TonBinding.make_string(config.to_json)
  context = TonBinding.tc_create_context(@config)
  @id = TonBinding.read_string_to_hash(context)['result']
  ObjectSpace.define_finalizer(self, self.class.finalize(@id))
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/ton-client-ruby/Client/Context.rb', line 4

def id
  @id
end

Class Method Details

.finalize(id) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/ton-client-ruby/Client/Context.rb', line 26

def self.finalize(id)
  Proc.new do
    if (id != nil) && (id > 0)
      TonBinding.tc_destroy_context(id)
    end
  end
end

Instance Method Details

#configObject



18
19
20
# File 'lib/ton-client-ruby/Client/Context.rb', line 18

def config
  TonBinding.read_string_to_hash(@config)
end

#config=(value = {}) ⇒ Object



14
15
16
# File 'lib/ton-client-ruby/Client/Context.rb', line 14

def config=(value = {})
  @config = TonBinding.make_string(value.to_json)
end

#destroyObject



22
23
24
# File 'lib/ton-client-ruby/Client/Context.rb', line 22

def destroy
  TonBinding.tc_destroy_context(id)
end