Class: Albacore::Asmver::FileGenerator

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/albacore/task_types/asmver/file_generator.rb

Constant Summary collapse

DEFAULT_USINGS =
%w|
System.Reflection
System.Runtime.CompilerServices
System.Runtime.InteropServices|

Instance Method Summary collapse

Methods included from Logging

#debug, #err, #error, #fatal, #info, #puts, #trace, #warn

Constructor Details

#initialize(engine, ns, opts) ⇒ FileGenerator

Returns a new instance of FileGenerator.

Raises:

  • (ArgumentError)


14
15
16
17
18
19
20
# File 'lib/albacore/task_types/asmver/file_generator.rb', line 14

def initialize engine, ns, opts
  raise ArgumentError, 'engine is nil' unless engine
  raise ArgumentError, 'ns is nil' unless ns
  @engine = engine 
  @ns     = ns
  @opts   = Map.new opts
end

Instance Method Details

#generate(out, attrs = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/albacore/task_types/asmver/file_generator.rb', line 22

def generate out, attrs = {}
  trace { "generating file with attributes: #{attrs} [file_generator #generate]" }

  # https://github.com/ahoward/map/blob/master/test/map_test.rb#L374
  attrs = Map.new attrs

  # write the attributes in the namespace
  @engine.build_namespace @ns, out do
    # after namespace My.Ns.Here
    out << "\n"

    # open all namespaces to use .Net attributes, concat with your custom attrs
    [ DEFAULT_USINGS, (@opts.get(:usings) || [])].flatten.each do |ns|
      out << @engine.build_using_statement(ns)
      out << "\n"
    end

    warn 'no attributes have been given to [file_generator #generate]' if attrs.empty?

    # write all attributes
    attrs.each do |name, data|
      trace { "building attribute #{name}: '#{data}' [file_generator #generate]" }
      out << @engine.build_attribute(name, data)
      out << "\n"
    end
  end

  nil
end