Sha256: b5197f631cff5cbc763d8d65cf0aaec53c0b26c24408920ab4cb70f8877dbdb9

Contents?: true

Size: 1.71 KB

Versions: 1

Compression:

Stored size: 1.71 KB

Contents

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

        def galaxyfile(contents)
          contents.split
        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

1 entries across 1 versions & 1 rubygems

Version Path
orats-0.6.5 lib/orats/commands/outdated/parse.rb