Class: Builder
- Inherits:
-
Object
- Object
- Builder
- Defined in:
- lib/rubidity/builder.rb
Instance Attribute Summary collapse
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Class Method Summary collapse
-
.load(code, filename, lineno) ⇒ Object
note: try adding filename and lineno to get source for block!!!.
-
.load_file(path) ⇒ Object
auto-add extension and import path for now - why? why not?.
Instance Method Summary collapse
- #contract(name, is: [], abstract: false, &body) ⇒ Object
-
#import(path) ⇒ Object
examples: import ‘./ERC20’.
-
#initialize ⇒ Builder
constructor
A new instance of Builder.
-
#pragma ⇒ Object
examples: pragma :rubidity, “1.0.0”.
Constructor Details
Instance Attribute Details
#source ⇒ Object (readonly)
Returns the value of attribute source.
32 33 34 |
# File 'lib/rubidity/builder.rb', line 32 def source @source end |
Class Method Details
.load(code, filename, lineno) ⇒ Object
note: try adding filename and lineno to get source for block!!!
15 16 17 18 19 20 21 22 |
# File 'lib/rubidity/builder.rb', line 15 def self.load( code, filename, lineno ) ## todo/fix: add filename to @paths too (to avoid possible recursive loading!!) builder = Builder.new builder.instance_eval( code, filename, lineno ) builder end |
.load_file(path) ⇒ Object
auto-add extension and import path for now - why? why not?
7 8 9 10 11 12 |
# File 'lib/rubidity/builder.rb', line 7 def self.load_file( path ) code = File.open( "contracts/#{path}.rb", 'r:utf-8' ) { |f| f.read } basename = File.basename( path ) lineno = 1 load( code, basename, lineno ) end |
Instance Method Details
#contract(name, is: [], abstract: false, &body) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/rubidity/builder.rb', line 60 def contract( name, is: [], abstract: false, &body ) contract = ContractDef.new( name, is: is, abstract: abstract ) contract.instance_eval( &body ) @source.contracts << contract end |
#import(path) ⇒ Object
examples: import ‘./ERC20’
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rubidity/builder.rb', line 43 def import( path ) puts "==> importing >#{path}<..." code = File.open( "contracts/#{path}.rb", 'r:utf-8' ) { |f| f.read } basename = File.basename( path ) if @paths.include?( basename ) puts " skipping import; already loaded" else @paths << basename lineno = 1 ## note: starting at line 1 (NOT 0!!!) instance_eval( code, basename, lineno ) end end |
#pragma ⇒ Object
examples: pragma :rubidity, “1.0.0”
37 38 39 |
# File 'lib/rubidity/builder.rb', line 37 def pragma( ... ) ## ignore for now end |