Class: ContractDef
- Inherits:
-
Object
- Object
- ContractDef
- Defined in:
- lib/rubidity/builder.rb
Instance Attribute Summary collapse
-
#abstract ⇒ Object
readonly
Returns the value of attribute abstract.
-
#events ⇒ Object
readonly
Returns the value of attribute events.
-
#functions ⇒ Object
readonly
Returns the value of attribute functions.
-
#is ⇒ Object
readonly
Returns the value of attribute is.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#storage ⇒ Object
readonly
Returns the value of attribute storage.
-
#structs ⇒ Object
readonly
Returns the value of attribute structs.
Instance Method Summary collapse
- #array(*args) ⇒ Object
- #constructor(args = {}, *options, &body) ⇒ Object
- #event(name, args) ⇒ Object
- #function(name, args, *options, returns: nil, &body) ⇒ Object
-
#initialize(name, is: [], abstract: false) ⇒ ContractDef
constructor
A new instance of ContractDef.
- #mapping(*args) ⇒ Object
- #struct(name, args) ⇒ Object
Constructor Details
#initialize(name, is: [], abstract: false) ⇒ ContractDef
Returns a new instance of ContractDef.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/rubidity/builder.rb', line 89 def initialize( name, is: [], abstract: false ) @name = name @is = if is.is_a?( Symbol ) [is] elsif is.is_a?( Array ) is else raise ArgumentError, "symbol or array expected; got #{is.inspect}" end @abstract = abstract @events = {} @structs = {} @storage = {} @functions = {} end |
Instance Attribute Details
#abstract ⇒ Object (readonly)
Returns the value of attribute abstract.
86 87 88 |
# File 'lib/rubidity/builder.rb', line 86 def abstract @abstract end |
#events ⇒ Object (readonly)
Returns the value of attribute events.
86 87 88 |
# File 'lib/rubidity/builder.rb', line 86 def events @events end |
#functions ⇒ Object (readonly)
Returns the value of attribute functions.
86 87 88 |
# File 'lib/rubidity/builder.rb', line 86 def functions @functions end |
#is ⇒ Object (readonly)
Returns the value of attribute is.
86 87 88 |
# File 'lib/rubidity/builder.rb', line 86 def is @is end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
86 87 88 |
# File 'lib/rubidity/builder.rb', line 86 def name @name end |
#storage ⇒ Object (readonly)
Returns the value of attribute storage.
86 87 88 |
# File 'lib/rubidity/builder.rb', line 86 def storage @storage end |
#structs ⇒ Object (readonly)
Returns the value of attribute structs.
86 87 88 |
# File 'lib/rubidity/builder.rb', line 86 def structs @structs end |
Instance Method Details
#array(*args) ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/rubidity/builder.rb', line 152 def array( *args ) sub_type = args.shift if args.last.is_a?( Symbol ) name = args.pop @storage[ name ] = { type: :array, sub_type: sub_type, args: args } else { type: :array, sub_type: sub_type, args: args } end end |
#constructor(args = {}, *options, &body) ⇒ Object
207 208 209 |
# File 'lib/rubidity/builder.rb', line 207 def constructor(args = {}, *, &body) function(:constructor, args, *, returns: nil, &body ) end |
#event(name, args) ⇒ Object
106 107 108 |
# File 'lib/rubidity/builder.rb', line 106 def event( name, args ) @events[name] = args end |
#function(name, args, *options, returns: nil, &body) ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/rubidity/builder.rb', line 168 def function(name, args, *, returns: nil, &body ) ## check if access to source is possible? puts # puts " function body: #{body.class.name}" #=> Proc # body.soure #=> ["(eval)", 17] - source filename and line number pp body pp body.parameters pp body.source_location puts puts body.source ## note: for now strip names/keys if returns is a hash - why? why not? ## e.g. function :getReserves, {}, :public, :view, returns: { ## _reserve0: :uint112, ## _reserve1: :uint112, ## _blockTimestampLast: :uint32 } returns = returns.values if returns.is_a?( Hash ) ### ## note: turn returns into an array - empty if nil, etc. ## always wrap into array returns = if returns.nil? [] elsif returns.is_a?( Array ) returns else ## assume single type [returns] end @functions[ name ] = { args: args, options: , returns: returns, body: body.source } end |
#mapping(*args) ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/rubidity/builder.rb', line 135 def mapping( *args ) key_type, value_type = args.shift.first if args.last.is_a?( Symbol ) name = args.pop @storage[ name ] = { type: :mapping, key_type: key_type, value_type: value_type, args: args } else { type: :mapping, key_type: key_type, value_type: value_type, args: args } end end |
#struct(name, args) ⇒ Object
110 111 112 |
# File 'lib/rubidity/builder.rb', line 110 def struct( name, args ) @structs[name] = args end |