Sha256: 72a22fe5da83ac2c581aa4f44cb3917a2fc672e2d14f803f1fbafff66d221dcf

Contents?: true

Size: 1.78 KB

Versions: 4

Compression:

Stored size: 1.78 KB

Contents

module Orats
  module Commands
    module Diff
      module Parse
        def gem_version
          "v#{url_to_string(@remote_paths[:version]).match(/'(.*)'/)[1..-1].first}"
        end

        def galaxyfile(contents)
          contents.split
        end

        def hosts(contents)
          contents.scan(/^\[.*\]/)
        end

        def inventory(contents)
          # pluck out all of the values contained with {{ }}
          ansible_variables = contents.scan(/\{\{([^{{}}]*)\}\}/)

          # remove the leading space
          ansible_variables.map! { |line| line.first[0] = '' }

          # match every line that is not a comment and contains a colon
          inventory_variables = contents.scan(/^[^#].*:/)

          inventory_variables.map! do |line|
            # only strip lines that need it
            line.strip! if line.include?(' ') || line.include?("\n")

            # get rid of the trailing colon
            line.chomp(':')

            # if a value of a certain variable has a colon then the regex
            # picks this up as a match. only take the variable name
            # if this happens to occur
            line.split(':').first if line.include?(':')
          end

          (ansible_variables + inventory_variables).uniq.delete_if(&:empty?)
        end

        def playbook(contents)
          roles = contents.scan(/^.*role:.*/)

          roles.map! do |line|
            line.strip! if line.include?(' ') || line.include?("\n")

            role_parts = line.split('role:')

            # start at the actual role name
            line       = role_parts[1]

            if line.include?(',')
              line = line.split(',').first
            end

            line.strip! if line.include?(' ')
          end

          roles.uniq
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
orats-0.7.3 lib/orats/commands/diff/parse.rb
orats-0.7.2 lib/orats/commands/diff/parse.rb
orats-0.7.1 lib/orats/commands/diff/parse.rb
orats-0.7.0 lib/orats/commands/diff/parse.rb