Class: Spacelift::Policy::Collection

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/spacelift/policy/policy.rb

Overview

Collection is a singleton instance combining multiple rules. It’s defined this way to allow pulling policy from multiple files in no particular order.

Instance Method Summary collapse

Constructor Details

#initializeCollection

Returns a new instance of Collection.



28
29
30
31
# File 'lib/spacelift/policy/policy.rb', line 28

def initialize
  @rules = []
  @violations = []
end

Instance Method Details

#ensure(name, &block) ⇒ Object

Raises:



33
34
35
36
37
# File 'lib/spacelift/policy/policy.rb', line 33

def ensure(name, &block)
  raise Error, "definition not provided for rule '#{name}'" unless block

  @rules << Rule.new(name, &block)
end

#process(resources) ⇒ Object

Raises:



39
40
41
42
43
44
# File 'lib/spacelift/policy/policy.rb', line 39

def process(resources)
  raise Error, 'no rules defined' if @rules.empty?

  resources.each { |resource| process_resource(resource) }
  @violations
end