Class: Finitio::Compilation

Inherits:
Object
  • Object
show all
Defined in:
lib/finitio/support/compilation.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(system = System.new, factory = TypeFactory.new, scope = nil, source = nil) ⇒ Compilation

Returns a new instance of Compilation.



4
5
6
7
8
9
# File 'lib/finitio/support/compilation.rb', line 4

def initialize(system = System.new, factory = TypeFactory.new, scope = nil, source = nil)
  @system  = system
  @factory = factory
  @scope = scope || FetchScope.new(system, {})
  @source = source
end

Instance Attribute Details

#factoryObject (readonly)

Returns the value of attribute factory.



10
11
12
# File 'lib/finitio/support/compilation.rb', line 10

def factory
  @factory
end

#scopeObject (readonly)

Returns the value of attribute scope.



10
11
12
# File 'lib/finitio/support/compilation.rb', line 10

def scope
  @scope
end

#sourceObject (readonly)

Returns the value of attribute source.



10
11
12
# File 'lib/finitio/support/compilation.rb', line 10

def source
  @source
end

#systemObject (readonly)

Returns the value of attribute system.



10
11
12
# File 'lib/finitio/support/compilation.rb', line 10

def system
  @system
end

Class Method Details

.coerce(arg, source = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/finitio/support/compilation.rb', line 12

def self.coerce(arg, source = nil)
  case arg
  when NilClass    then new(System.new, TypeFactory.new, nil, source)
  when System      then new(arg, arg.factory, nil, source)
  when TypeFactory then new(System.new, arg, nil, source)
  else
    raise ArgumentError, "Unable to coerce `#{arg}`"
  end
end

Instance Method Details

#add_import(import) ⇒ Object



26
27
28
29
# File 'lib/finitio/support/compilation.rb', line 26

def add_import(import)
  @system.add_import(import)
  self
end

#fetch(type_name, &bl) ⇒ Object

Delegation to FetchScope



76
77
78
# File 'lib/finitio/support/compilation.rb', line 76

def fetch(type_name, &bl)
  scope.fetch(type_name, &bl)
end

#importsObject



22
23
24
# File 'lib/finitio/support/compilation.rb', line 22

def imports
  @system.send(:imports)
end

#resolve_proxiesObject



51
52
53
# File 'lib/finitio/support/compilation.rb', line 51

def resolve_proxies
  system.resolve_proxies
end

#resolve_relative_url(url) ⇒ Object

Raises:



43
44
45
46
47
48
49
# File 'lib/finitio/support/compilation.rb', line 43

def resolve_relative_url(url)
  raise Error, "Unable to resolve `#{url}`, missing path context"\
    unless source.respond_to?(:to_path)
  file = File.expand_path("../#{url}.fio", source.to_path)
  raise Error, "No such file `#{file}`" unless File.file?(file)
  Pathname.new(file)
end

#resolve_url(url) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/finitio/support/compilation.rb', line 31

def resolve_url(url)
  if url.to_s =~ /^\.\//
    resolve_relative_url(url)
  else
    STDLIB_PATHS.each do |path|
      file = File.expand_path("#{url}.fio", path)
      return Pathname.new(file) if File.file?(file)
    end
    raise Error, "No such import `#{url}`"
  end
end

#with_scope(overrides) ⇒ Object



80
81
82
# File 'lib/finitio/support/compilation.rb', line 80

def with_scope(overrides)
  Compilation.new(system, factory, scope.with(overrides), source)
end