Sha256: 17b16ad841cb1df0c2a2ffe1786569517815e5ed3eba23d1e1a12c118c58f986

Contents?: true

Size: 1.22 KB

Versions: 2

Compression:

Stored size: 1.22 KB

Contents

require 'yaml'

module MavenHelperScript

  class ConfigurationChecker
    def initialize(file)
      @yml = YAML::load_file(File.join(file, 'm.yml'))
      @commands = buildCommandKeys()
    end

    public
    def checkForArguments()
      @yml['arguments'] || Array[]
    end

    def checkForModule(mapping)
      @yml['modules'][mapping] || mapping
    end

    def checkForCommand(mapping)
      result = @commands[mapping]

      if !result
        result = ""
        mapping.each_char do |character|
          result << findCommandFor(character) << " "
        end
        result.strip!
      end


      if !result || result.empty?
        raise "Unable to locate command for: " << mapping
      end

      result
    end

    private
    def buildCommandKeys()
      commandKeys = Hash.new()
      @yml['commands'].each do |phase|
        if phase.include? ':'
          key = ""
          phase.split(':').each do |part|
            key << part[0]
          end
          commandKeys[key] = phase
        else
          commandKeys[phase[0]] = phase
        end
      end
      commandKeys
    end

    def findCommandFor(mapping)
      @commands[mapping] || ""
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
maven-helper-script-0.1.1 lib/configuration_checker.rb
maven-helper-script-0.1.0 lib/configuration_checker.rb