Class: Inspec::Metadata
- Inherits:
-
Object
- Object
- Inspec::Metadata
- Defined in:
- lib/inspec/metadata.rb
Overview
Extract metadata.rb information
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(logger = nil) ⇒ Metadata
constructor
A new instance of Metadata.
- #method_missing(sth, *args) ⇒ Object
- #supports(sth, version = nil) ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(logger = nil) ⇒ Metadata
Returns a new instance of Metadata.
12 13 14 15 16 |
# File 'lib/inspec/metadata.rb', line 12 def initialize(logger = nil) @logger = logger || Logger.new(nil) @params = {} @missing_methods = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sth, *args) ⇒ Object
60 61 62 63 |
# File 'lib/inspec/metadata.rb', line 60 def method_missing(sth, *args) @logger.warn "metadata.rb doesn't support: #{sth} #{args}" @missing_methods.push(sth) end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
11 12 13 |
# File 'lib/inspec/metadata.rb', line 11 def params @params end |
Class Method Details
.from_file(path, profile_id, logger = nil) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/inspec/metadata.rb', line 65 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 |
Instance Method Details
#supports(sth, version = nil) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/inspec/metadata.rb', line 35 def supports(sth, version = nil) params[:supports] ||= [] params[:supports].push( { os: sth, version: version, }, ) end |
#valid? ⇒ Boolean
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/inspec/metadata.rb', line 45 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 |