Class: Spacelift::Policy::Collection
- Inherits:
-
Object
- Object
- Spacelift::Policy::Collection
- 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
- #ensure(name, &block) ⇒ Object
-
#initialize ⇒ Collection
constructor
A new instance of Collection.
- #process(resources) ⇒ Object
Constructor Details
#initialize ⇒ Collection
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
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
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 |