Sha256: 064149d24eddf335a8516d7f625bd531a9c4e065bac59604e67c1731d7ab6df0
Contents?: true
Size: 1.81 KB
Versions: 8
Compression:
Stored size: 1.81 KB
Contents
# encoding: utf-8 # Copyright 2015 Dominik Richter. All rights reserved. # author: Dominik Richter # author: Christoph Hartmann require 'logger' module Inspec # Extract metadata.rb information class Metadata attr_reader :params def initialize(logger = nil) @logger = logger || Logger.new(nil) @params = {} @missing_methods = [] end %w{ name title maintainer maintainer_email copyright copyright_email license summary description version }.each do |name| define_method name.to_sym do |arg| params[name.to_sym] = arg end end def supports(sth, version = nil) params[:supports] ||= [] params[:supports].push( { os: sth, version: version, }, ) end def valid? is_valid = true %w{ name title version summary }.each do |field| next unless params[field.to_sym].nil? @logger.error("Missing profile #{field} in metadata.rb") is_valid = false end %w{ maintainer copyright }.each do |field| next unless params[field.to_sym].nil? @logger.warn("Missing profile #{field} in metadata.rb") is_valid = false end is_valid && @missing_methods.empty? end def method_missing(sth, *args) @logger.warn "metadata.rb doesn't support: #{sth} #{args}" @missing_methods.push(sth) end def self.from_file(path, profile_id, logger = nil) logger ||= Logger.new(nil) unless File.file?(path) logger.error "Can't find metadata file #{path}" return nil end res = Metadata.new(logger) res.instance_eval(File.read(path), path, 1) res.params[:name] = profile_id.to_s unless profile_id.to_s.empty? res end end end
Version data entries
8 entries across 8 versions & 1 rubygems