Class: Rant::CSharp::CompilerAdapterFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/rant/csharp/compiler_adapter_factory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ CompilerAdapterFactory

Returns a new instance of CompilerAdapterFactory.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rant/csharp/compiler_adapter_factory.rb', line 10

def initialize context
  @context = context
  @compiler = nil
  
  # Default compiler mappings
  @compiler_map ||= {
    "csc" => CscCompiler,
    "mcs" => McsCompiler,
    "gmcs" => GmcsCompiler
  }
end

Instance Attribute Details

#compiler_mapObject

Returns the value of attribute compiler_map.



8
9
10
# File 'lib/rant/csharp/compiler_adapter_factory.rb', line 8

def compiler_map
  @compiler_map
end

#contextObject

Returns the value of attribute context.



7
8
9
# File 'lib/rant/csharp/compiler_adapter_factory.rb', line 7

def context
  @context
end

Instance Method Details

#compilerObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rant/csharp/compiler_adapter_factory.rb', line 22

def compiler
  if !@compiler
    compiler_map.each_key do |key|
      if context.env.find_bin(key)
        @compiler = compiler_map[key].new(context)
        break
      end
    end
    
    if !@compiler
      raise Exception.new("Could not find C# compiler in path (csc, mcs, gmcs). " +
                          "Please amend your path or explicitly define one with the :compiler option")
    end
  end
  
  @compiler
end