Class: R10K::Environment::Base
- Inherits:
-
Object
- Object
- R10K::Environment::Base
- Defined in:
- lib/r10k/environment/base.rb
Overview
This class defines a common interface for environment implementations.
Instance Attribute Summary collapse
- #basedir ⇒ Object readonly
- #dirname ⇒ Object readonly
- #name ⇒ Object readonly
- #path ⇒ Object readonly
- #puppetfile ⇒ Object readonly
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
-
#info ⇒ Hash
Returns a hash describing the current state of the environment.
-
#initialize(name, basedir, dirname, options = {}) ⇒ Base
constructor
Initialize the given environment.
-
#modules ⇒ Array<R10K::Module::Base>
All modules defined in the Puppetfile associated with this environment.
- #purge_exclusions ⇒ Object
-
#signature ⇒ String
abstract
Returns a unique identifier for the environment’s current state.
-
#status ⇒ Symbol
abstract
Determine the current status of the environment.
-
#sync ⇒ void
abstract
Synchronize the given environment.
- #whitelist(user_whitelist = []) ⇒ Object
Constructor Details
#initialize(name, basedir, dirname, options = {}) ⇒ Base
Initialize the given environment.
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/r10k/environment/base.rb', line 34 def initialize(name, basedir, dirname, = {}) @name = name @basedir = basedir @dirname = dirname @options = @full_path = File.join(@basedir, @dirname) @path = Pathname.new(File.join(@basedir, @dirname)) @puppetfile = R10K::Puppetfile.new(@full_path) @puppetfile.environment = self end |
Instance Attribute Details
#basedir ⇒ Object (readonly)
12 13 14 |
# File 'lib/r10k/environment/base.rb', line 12 def basedir @basedir end |
#dirname ⇒ Object (readonly)
16 17 18 |
# File 'lib/r10k/environment/base.rb', line 16 def dirname @dirname end |
#name ⇒ Object (readonly)
8 9 10 |
# File 'lib/r10k/environment/base.rb', line 8 def name @name end |
#path ⇒ Object (readonly)
20 21 22 |
# File 'lib/r10k/environment/base.rb', line 20 def path @path end |
#puppetfile ⇒ Object (readonly)
25 26 27 |
# File 'lib/r10k/environment/base.rb', line 25 def puppetfile @puppetfile end |
Instance Method Details
#accept(visitor) ⇒ Object
98 99 100 101 102 |
# File 'lib/r10k/environment/base.rb', line 98 def accept(visitor) visitor.visit(:environment, self) do puppetfile.accept(visitor) end end |
#info ⇒ Hash
Returns a hash describing the current state of the environment.
84 85 86 87 88 89 |
# File 'lib/r10k/environment/base.rb', line 84 def info { :name => self.name, :signature => self.signature, } end |
#modules ⇒ Array<R10K::Module::Base>
Returns All modules defined in the Puppetfile associated with this environment.
93 94 95 96 |
# File 'lib/r10k/environment/base.rb', line 93 def modules @puppetfile.load @puppetfile.modules end |
#purge_exclusions ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/r10k/environment/base.rb', line 108 def purge_exclusions list = [File.join(@full_path, '.r10k-deploy.json')].to_set list += @puppetfile.managed_directories list += @puppetfile.desired_contents.flat_map do |item| desired_tree = [] if File.directory?(item) desired_tree << File.join(item, '**', '*') end Pathname.new(item).ascend do |path| break if path.to_s == @full_path desired_tree << path.to_s end desired_tree end list.to_a end |
#signature ⇒ String
Returns a unique identifier for the environment’s current state.
77 78 79 |
# File 'lib/r10k/environment/base.rb', line 77 def signature raise NotImplementedError, _("%{class} has not implemented method %{method}") %{class: self.class, method: __method__} end |
#status ⇒ Symbol
Determine the current status of the environment.
This can return the following values:
* :absent - there is no module installed
* :mismatched - there is a module installed but it must be removed and reinstalled
* :outdated - the correct module is installed but it needs to be updated
* :insync - the correct module is installed and up to date, or the module is actually a boy band.
68 69 70 |
# File 'lib/r10k/environment/base.rb', line 68 def status raise NotImplementedError, _("%{class} has not implemented method %{method}") % {class: self.class, method: __method__} end |
#sync ⇒ void
This method returns an undefined value.
Synchronize the given environment.
52 53 54 |
# File 'lib/r10k/environment/base.rb', line 52 def sync raise NotImplementedError, _("%{class} has not implemented method %{method}") % {class: self.class, method: __method__} end |
#whitelist(user_whitelist = []) ⇒ Object
104 105 106 |
# File 'lib/r10k/environment/base.rb', line 104 def whitelist(user_whitelist=[]) user_whitelist.collect { |pattern| File.join(@full_path, pattern) } end |