Class: Loom::Pattern::Reference

Inherits:
Object
  • Object
show all
Defined in:
lib/loom/pattern/reference.rb

Overview

See Loom::Pattern::Pattern for the difference between refs and patterns.

Defined Under Namespace

Classes: RunContext

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(slug, pattern, source_file, definition_ctx) ⇒ Reference

Returns a new instance of Reference.



7
8
9
10
11
12
13
# File 'lib/loom/pattern/reference.rb', line 7

def initialize(slug, pattern, source_file, definition_ctx)
  @slug = slug
  @source_file = source_file
  @definition_ctx = definition_ctx
  @desc = pattern.description
  @pattern = pattern
end

Instance Attribute Details

#descObject (readonly)

Returns the value of attribute desc.



5
6
7
# File 'lib/loom/pattern/reference.rb', line 5

def desc
  @desc
end

#patternObject (readonly)

Returns the value of attribute pattern.



5
6
7
# File 'lib/loom/pattern/reference.rb', line 5

def pattern
  @pattern
end

#slugObject (readonly)

Returns the value of attribute slug.



5
6
7
# File 'lib/loom/pattern/reference.rb', line 5

def slug
  @slug
end

#source_fileObject (readonly)

Returns the value of attribute source_file.



5
6
7
# File 'lib/loom/pattern/reference.rb', line 5

def source_file
  @source_file
end

Instance Method Details

#call(shell_api, host_fact_set) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/loom/pattern/reference.rb', line 21

def call(shell_api, host_fact_set)
  run_context = RunContext.new @pattern, @definition_ctx

  fact_set = @definition_ctx.fact_set host_fact_set
  Loom.log.debug5(self) {
    "fact set for pattern execution => #{fact_set.facts}" }

  # TODO: wrap up this fact_set in a delegator/facade/proxy to eliminate the
  # .loom file from directly accessing it. Add logging and deprecation
  # warnings there.... like FactSet+hostname+ currently.
  @definition_ctx.define_let_readers run_context, fact_set

  begin
    run_context.run shell_api, fact_set
  rescue => e
    error_msg = "error executing '#{slug}' in #{source_file} =>\n\t#{e}\n%s"
    Loom.log.error(error_msg % e.backtrace.join("\n\t"))
    raise
  end
end

#expand_slugsObject

Used by Loom::Pattern::Loader to expand weaves. A Pattern::Reference it just expands to itself.



17
18
19
# File 'lib/loom/pattern/reference.rb', line 17

def expand_slugs
  @slug
end