Module: Blender::Manifest::Roles
- Included in:
- Root
- Defined in:
- lib/blender/manifest/roles.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#current_roles ⇒ Object
A very simple mechanism to define roles.
-
#role(r) ⇒ Object
conditionally runs the code block if the role ‘r’ is currently defined.
-
#roles(*roles) ⇒ Object
ADDS roles to the currently defined roles.
Class Method Details
.included(base) ⇒ Object
3 4 5 |
# File 'lib/blender/manifest/roles.rb', line 3 def self.included(base) base.send :extend, self end |
Instance Method Details
#current_roles ⇒ Object
A very simple mechanism to define roles
Roles to accept can be defined from environment, /etc/roles file or can be explicitly defined like ‘roles xxx, yyy’ usually the ‘roles a,b,c’ call will come inside of a ‘node` block and so will be conditionally executed depending on the running host
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/blender/manifest/roles.rb', line 15 def current_roles @current_roles ||= if ENV['ROLES'] ENV['ROLES'].split(",") elsif File.exists?("/etc/roles") File.read("/etc/roles").strip.split else [] end end |
#role(r) ⇒ Object
conditionally runs the code block if the role ‘r’ is currently defined
33 34 35 36 37 38 |
# File 'lib/blender/manifest/roles.rb', line 33 def role r if block_given? && current_roles.include?(r.to_s) puts "ROLE: #{r}" yield end end |
#roles(*roles) ⇒ Object
ADDS roles to the currently defined roles
27 28 29 |
# File 'lib/blender/manifest/roles.rb', line 27 def roles *roles current_roles.concat(roles.map {|r| r.to_s}) end |