Class: Puppet::Indirector::Face

Inherits:
Face
  • Object
show all
Defined in:
lib/puppet/indirector/face.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#fromObject

Returns the value of attribute from.



114
115
116
# File 'lib/puppet/indirector/face.rb', line 114

def from
  @from
end

Class Method Details

.indirectionsObject



34
35
36
# File 'lib/puppet/indirector/face.rb', line 34

def self.indirections
  Puppet::Indirector::Indirection.instances.collect(&:to_s).sort
end

.terminus_classes(indirection) ⇒ Object



38
39
40
# File 'lib/puppet/indirector/face.rb', line 38

def self.terminus_classes(indirection)
  Puppet::Indirector::Terminus.terminus_classes(indirection.to_sym).collect(&:to_s).sort
end

Instance Method Details

#call_indirection_method(method, key, options) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/puppet/indirector/face.rb', line 42

def call_indirection_method(method, key, options)
  begin
    if method == :save
      # key is really the instance to save
      result = indirection.__send__(method, key, nil, options)
    else
      result = indirection.__send__(method, key, options)
    end
  rescue => detail
    message = _("Could not call '%{method}' on '%{indirection}': %{detail}") % { method: method, indirection: indirection_name, detail: detail }
    Puppet.log_exception(detail, message)
    raise RuntimeError, message, detail.backtrace
  end

  result
end

#indirectionObject

Return an indirection associated with a face, if one exists; One usually does.



128
129
130
131
132
133
134
# File 'lib/puppet/indirector/face.rb', line 128

def indirection
  unless @indirection
    @indirection = Puppet::Indirector::Indirection.instance(indirection_name)
    @indirection or raise _("Could not find terminus for %{indirection}") % { indirection: indirection_name }
  end
  @indirection
end

#indirection_nameObject



116
117
118
# File 'lib/puppet/indirector/face.rb', line 116

def indirection_name
  @indirection_name || name.to_sym
end

#set_indirection_name(name) ⇒ Object

Here’s your opportunity to override the indirection name. By default it will be the same name as the face.



122
123
124
# File 'lib/puppet/indirector/face.rb', line 122

def set_indirection_name(name)
  @indirection_name = name
end

#set_terminus(from) ⇒ Object



136
137
138
139
140
141
# File 'lib/puppet/indirector/face.rb', line 136

def set_terminus(from)
  indirection.terminus_class = from
rescue => detail
  msg = _("Could not set '%{indirection}' terminus to '%{from}' (%{detail}); valid terminus types are %{types}") % { indirection: indirection.name, from: from, detail: detail, types: self.class.terminus_classes(indirection.name).join(", ") }
  raise detail, msg, detail.backtrace
end