Class: Sprinkle::Policy::Policy
Overview
:nodoc:
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#packages ⇒ Object
readonly
Returns the value of attribute packages.
Instance Method Summary collapse
-
#initialize(name, metadata = {}, &block) ⇒ Policy
constructor
A new instance of Policy.
- #process(deployment) ⇒ Object
- #requires(package, options = {}) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name, metadata = {}, &block) ⇒ Policy
Returns a new instance of Policy.
56 57 58 59 60 61 62 63 64 |
# File 'lib/sprinkle/policy.rb', line 56 def initialize(name, = {}, &block) raise 'No name provided' unless name raise 'No roles provided' unless [:roles] @name = name @roles = [:roles] @packages = [] self.instance_eval(&block) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
54 55 56 |
# File 'lib/sprinkle/policy.rb', line 54 def name @name end |
#packages ⇒ Object (readonly)
Returns the value of attribute packages.
54 55 56 |
# File 'lib/sprinkle/policy.rb', line 54 def packages @packages end |
Instance Method Details
#process(deployment) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/sprinkle/policy.rb', line 72 def process(deployment) all = [] cloud_info "--> Cloud hierarchy for policy #{@name}" @packages.each do |p| cloud_info "\nPolicy #{@name} requires package #{p}" package = Sprinkle::Package::PACKAGES[p] raise "Package definition not found for key: #{p}" unless package package = select_package(p, package) if package.is_a? Array # handle virtual package selection tree = package.tree do |parent, child, depth| indent = "\t" * depth; cloud_info "#{indent}Package #{parent.name} requires #{child.name}" end all << tree end normalize(all) do |package| package.process(deployment, @roles) end end |
#requires(package, options = {}) ⇒ Object
66 67 68 |
# File 'lib/sprinkle/policy.rb', line 66 def requires(package, = {}) @packages << package end |
#to_s ⇒ Object
70 |
# File 'lib/sprinkle/policy.rb', line 70 def to_s; name; end |