Class: NEAR::Action

Inherits:
Object
  • Object
show all
Defined in:
lib/near/action.rb

Overview

Represents a NEAR action.

Defined Under Namespace

Classes: AddKey, CreateAccount, Delegate, DeleteAccount, DeleteKey, DeployContract, FunctionCall, Stake, Transfer

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = nil) ⇒ Action

Returns a new instance of Action.

Parameters:

  • data (Hash, #to_h) (defaults to: nil)


109
110
111
# File 'lib/near/action.rb', line 109

def initialize(data = nil)
  @data = data.to_h if data
end

Instance Attribute Details

#dataHash (readonly)

The action data.

Returns:

  • (Hash)


124
125
126
# File 'lib/near/action.rb', line 124

def data
  @data
end

#typeSymbol (readonly)

Returns:

  • (Symbol)


115
116
117
# File 'lib/near/action.rb', line 115

def type
  @type
end

Class Method Details

.parse(data) ⇒ NEAR::Action

Parameters:

  • data (String, Hash)

Returns:



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/near/action.rb', line 80

def self.parse(data)
  case
    when data.is_a?(String) then case
      when 'CreateAccount' then CreateAccount.new
      when 'DeployContract' then DeployContract.new
      when 'FunctionCall' then FunctionCall.new
      when 'Transfer' then Transfer.new
      when 'Stake' then Stake.new
      when 'AddKey' then AddKey.new
      when 'DeleteKey' then DeleteKey.new
      when 'DeleteAccount' then DeleteAccount.new
      when 'Delegate' then Delegate.new
      else self.new
    end
    when data['CreateAccount'] then CreateAccount.new(data['CreateAccount'])
    when data['DeployContract'] then DeployContract.new(data['DeployContract'])
    when data['FunctionCall'] then FunctionCall.new(data['FunctionCall'])
    when data['Transfer'] then Transfer.new(data['Transfer'])
    when data['Stake'] then Stake.new(data['Stake'])
    when data['AddKey'] then AddKey.new(data['AddKey'])
    when data['DeleteKey'] then DeleteKey.new(data['DeleteKey'])
    when data['DeleteAccount'] then DeleteAccount.new(data['DeleteAccount'])
    when data['Delegate'] then Delegate.new(data['Delegate'])
    else self.new(data[data.keys.first])
  end
end

Instance Method Details

#inspectString

Returns:

  • (String)


136
137
138
139
140
# File 'lib/near/action.rb', line 136

def inspect
  data = self.to_h
  data['args'] = '...' if data['args']
  "#<#{self.class.name} #{data.to_json}>"
end

#to_hHash

Returns:

  • (Hash)


128
# File 'lib/near/action.rb', line 128

def to_h; @data || {}; end

#to_symSymbol

Returns:

  • (Symbol)


132
# File 'lib/near/action.rb', line 132

def to_sym; self.type; end