Sha256: d53fe0028823c702a3080f2cbe105d95b7b98ccd4acf2a84693054f1d303b38f

Contents?: true

Size: 1.41 KB

Versions: 56

Compression:

Stored size: 1.41 KB

Contents

require 'albacore/task_types/asmver/engine'
require 'albacore/logging'
require 'map'

module Albacore::Asmver
  class FileGenerator
    include ::Albacore::Logging

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

    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
    
    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
        @opts.get(:usings) { DEFAULT_USINGS }.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
  end
end

Version data entries

56 entries across 56 versions & 1 rubygems

Version Path
albacore-2.3.9 lib/albacore/task_types/asmver/file_generator.rb
albacore-2.3.8 lib/albacore/task_types/asmver/file_generator.rb
albacore-2.3.7 lib/albacore/task_types/asmver/file_generator.rb
albacore-2.3.6 lib/albacore/task_types/asmver/file_generator.rb
albacore-2.3.5 lib/albacore/task_types/asmver/file_generator.rb
albacore-2.3.4 lib/albacore/task_types/asmver/file_generator.rb
albacore-2.3.3 lib/albacore/task_types/asmver/file_generator.rb
albacore-2.3.2 lib/albacore/task_types/asmver/file_generator.rb
albacore-2.3.1 lib/albacore/task_types/asmver/file_generator.rb
albacore-2.3.0 lib/albacore/task_types/asmver/file_generator.rb
albacore-2.2.1 lib/albacore/task_types/asmver/file_generator.rb
albacore-2.2.0 lib/albacore/task_types/asmver/file_generator.rb
albacore-2.2.0.pre.beta.7 lib/albacore/task_types/asmver/file_generator.rb
albacore-2.2.0.pre.beta.6 lib/albacore/task_types/asmver/file_generator.rb
albacore-2.2.0.pre.beta.5 lib/albacore/task_types/asmver/file_generator.rb
albacore-2.2.0.pre.beta.4 lib/albacore/task_types/asmver/file_generator.rb
albacore-2.2.0.pre.beta.3 lib/albacore/task_types/asmver/file_generator.rb
albacore-2.2.0.pre.beta.2 lib/albacore/task_types/asmver/file_generator.rb
albacore-2.2.0.pre.beta lib/albacore/task_types/asmver/file_generator.rb
albacore-2.1.2 lib/albacore/task_types/asmver/file_generator.rb