Class: Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/rubidity/builder.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBuilder

Returns a new instance of Builder.



24
25
26
27
28
29
# File 'lib/rubidity/builder.rb', line 24

def initialize
  @source = Source.new
  ## only load path once; keep track of loaded imports 
  ##  change paths to contracts or such - why? why not?
  @paths  = []   
end

Instance Attribute Details

#sourceObject (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

#pragmaObject

examples: pragma :rubidity, “1.0.0”



37
38
39
# File 'lib/rubidity/builder.rb', line 37

def pragma( ... )
   ## ignore for now
end