Class: ChefDK::PolicyfileLock

Inherits:
Object
  • Object
show all
Defined in:
lib/chef-dk/policyfile_lock.rb

Defined Under Namespace

Classes: CachedCookbook, LocalCookbook

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ PolicyfileLock

Returns a new instance of PolicyfileLock.



182
183
184
185
186
187
188
# File 'lib/chef-dk/policyfile_lock.rb', line 182

def initialize(options = {})
  @name = nil
  @run_list = []
  @cookbook_locks = {}
  @relative_paths_root = Dir.pwd
  handle_options(options)
end

Instance Attribute Details

#cache_pathObject (readonly)

Returns the value of attribute cache_path.



179
180
181
# File 'lib/chef-dk/policyfile_lock.rb', line 179

def cache_path
  @cache_path
end

#cookbook_locksObject (readonly)

Returns the value of attribute cookbook_locks.



178
179
180
# File 'lib/chef-dk/policyfile_lock.rb', line 178

def cookbook_locks
  @cookbook_locks
end

#nameObject

Returns the value of attribute name.



175
176
177
# File 'lib/chef-dk/policyfile_lock.rb', line 175

def name
  @name
end

#relative_paths_rootObject (readonly)

Returns the value of attribute relative_paths_root.



180
181
182
# File 'lib/chef-dk/policyfile_lock.rb', line 180

def relative_paths_root
  @relative_paths_root
end

#run_listObject

Returns the value of attribute run_list.



176
177
178
# File 'lib/chef-dk/policyfile_lock.rb', line 176

def run_list
  @run_list
end

Class Method Details

.build(options = {}) {|lock| ... } ⇒ Object

Yields:

  • (lock)


163
164
165
166
167
# File 'lib/chef-dk/policyfile_lock.rb', line 163

def self.build(options = {})
  lock = new(options)
  yield lock
  lock
end

.build_from_compiler(compiler, options = {}) ⇒ Object



169
170
171
172
173
# File 'lib/chef-dk/policyfile_lock.rb', line 169

def self.build_from_compiler(compiler, options = {})
  lock = new(options)
  lock.build_from_compiler(compiler)
  lock
end

Instance Method Details

#build_from_compiler(compiler) ⇒ Object



217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/chef-dk/policyfile_lock.rb', line 217

def build_from_compiler(compiler)
  @run_list = compiler.expanded_run_list

  compiler.all_cookbook_specs.each do |cookbook_name, spec|
    if spec.mirrors_canonical_upstream?
      cached_cookbook(cookbook_name) do |cached_cb|
        cached_cb.cache_key = spec.cache_key
        cached_cb.origin = spec.uri
      end
    else
      local_cookbook(cookbook_name) do |local_cb|
        local_cb.source = spec.relative_path
        local_cb.relative_paths_root = spec.relative_paths_root
      end
    end
  end
  self
end

#cached_cookbook(name) {|cached_cookbook| ... } ⇒ Object

Yields:



190
191
192
193
194
# File 'lib/chef-dk/policyfile_lock.rb', line 190

def cached_cookbook(name)
  cached_cookbook = CachedCookbook.new(name, cache_path)
  yield cached_cookbook
  @cookbook_locks[name] = cached_cookbook
end

#cookbook_locks_for_lockfileObject



210
211
212
213
214
215
# File 'lib/chef-dk/policyfile_lock.rb', line 210

def cookbook_locks_for_lockfile
  cookbook_locks.inject({}) do |locks_map, (name, cookbook_spec)|
    locks_map[name] = cookbook_spec.to_lock
    locks_map
  end
end

#local_cookbook(name) {|local_cookbook| ... } ⇒ Object

Yields:



196
197
198
199
200
# File 'lib/chef-dk/policyfile_lock.rb', line 196

def local_cookbook(name)
  local_cookbook = LocalCookbook.new(name, relative_paths_root)
  yield local_cookbook
  @cookbook_locks[name] = local_cookbook
end

#to_lockObject



202
203
204
205
206
207
208
# File 'lib/chef-dk/policyfile_lock.rb', line 202

def to_lock
  {}.tap do |lock|
    lock["name"] = name
    lock["run_list"] = run_list
    lock["cookbook_locks"] = cookbook_locks_for_lockfile
  end
end