Class: FilterArray

Inherits:
Object
  • Object
show all
Defined in:
lib/inspec/utils/filter_array.rb

Overview

copyright: 2015, Chef Software, Inc.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rules) ⇒ FilterArray

Returns a new instance of FilterArray.



7
8
9
# File 'lib/inspec/utils/filter_array.rb', line 7

def initialize(rules)
  @rules = rules
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args) ⇒ Object



22
23
24
# File 'lib/inspec/utils/filter_array.rb', line 22

def method_missing(meth, *args)
  field(meth, args[0])
end

Instance Attribute Details

#rulesObject Also known as: content

Returns the value of attribute rules.



4
5
6
# File 'lib/inspec/utils/filter_array.rb', line 4

def rules
  @rules
end

Instance Method Details

#field(key, value = nil) ⇒ Object

allows for chaining .field(‘arch’, ‘b32’).field(‘key’, ‘access’).rules



13
14
15
16
17
18
19
20
# File 'lib/inspec/utils/filter_array.rb', line 13

def field(key, value = nil)
  if value
    res = rules.find_all { |r| r[key.to_sym] == value }
    FilterArray.new(res)
  else
    rules.map { |h| h[key.to_sym] }.uniq
  end
end