Class: Bolt::Target
- Inherits:
-
Object
- Object
- Bolt::Target
- Defined in:
- lib/bolt/target.rb
Instance Attribute Summary collapse
-
#inventory ⇒ Object
writeonly
Sets the attribute inventory.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Class Method Summary collapse
-
.from_asserted_hash(hash) ⇒ Object
Satisfies the Puppet datatypes API.
Instance Method Summary collapse
- #eql?(other) ⇒ Boolean (also: #==)
- #features ⇒ Object
- #hash ⇒ Object
- #host ⇒ Object
-
#initialize(uri, options = nil) ⇒ Target
constructor
A new instance of Target.
-
#name ⇒ Object
name is currently just uri but should be used instead to identify the Target ouside the transport or uri options.
- #password ⇒ Object
- #port ⇒ Object
- #protocol ⇒ Object
- #select_impl(task, additional_features = []) ⇒ Object
- #to_s ⇒ Object
- #update_conf(conf) ⇒ Object
- #user ⇒ Object
Constructor Details
#initialize(uri, options = nil) ⇒ Target
Returns a new instance of Target.
16 17 18 19 20 21 |
# File 'lib/bolt/target.rb', line 16 def initialize(uri, = nil) @uri = uri @uri_obj = parse(uri) @options = || {} @options.freeze end |
Instance Attribute Details
#inventory=(value) ⇒ Object (writeonly)
Sets the attribute inventory
9 10 11 |
# File 'lib/bolt/target.rb', line 9 def inventory=(value) @inventory = value end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/bolt/target.rb', line 8 def @options end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
8 9 10 |
# File 'lib/bolt/target.rb', line 8 def uri @uri end |
Class Method Details
.from_asserted_hash(hash) ⇒ Object
Satisfies the Puppet datatypes API
12 13 14 |
# File 'lib/bolt/target.rb', line 12 def self.from_asserted_hash(hash) new(hash['uri'], hash['options']) end |
Instance Method Details
#eql?(other) ⇒ Boolean Also known as: ==
62 63 64 |
# File 'lib/bolt/target.rb', line 62 def eql?(other) self.class.equal?(other.class) && @uri == other.uri end |
#features ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/bolt/target.rb', line 54 def features if @inventory @inventory.features(self) else Set.new end end |
#hash ⇒ Object
67 68 69 |
# File 'lib/bolt/target.rb', line 67 def hash @uri.hash ^ @options.hash end |
#host ⇒ Object
75 76 77 |
# File 'lib/bolt/target.rb', line 75 def host @uri_obj.hostname end |
#name ⇒ Object
name is currently just uri but should be used instead to identify the Target ouside the transport or uri options.
81 82 83 |
# File 'lib/bolt/target.rb', line 81 def name uri end |
#password ⇒ Object
99 100 101 102 103 |
# File 'lib/bolt/target.rb', line 99 def password Addressable::URI.unencode_component( @uri_obj.password || @password ) end |
#port ⇒ Object
85 86 87 |
# File 'lib/bolt/target.rb', line 85 def port @uri_obj.port || @port end |
#protocol ⇒ Object
89 90 91 |
# File 'lib/bolt/target.rb', line 89 def protocol @uri_obj.scheme || @protocol end |
#select_impl(task, additional_features = []) ⇒ Object
48 49 50 51 52 |
# File 'lib/bolt/target.rb', line 48 def select_impl(task, additional_features = []) available_features = features + additional_features suitable_impl = task.implementations.find { |impl| Set.new(impl['requirements']).subset?(available_features) } return suitable_impl['path'] if suitable_impl end |
#to_s ⇒ Object
71 72 73 |
# File 'lib/bolt/target.rb', line 71 def to_s "Target('#{@uri}', #{@options})" end |
#update_conf(conf) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/bolt/target.rb', line 23 def update_conf(conf) @protocol = conf[:transport] t_conf = conf[:transports][protocol.to_sym] # Override url methods @user = t_conf['user'] @password = t_conf['password'] @port = t_conf['port'] url_keys = %w[user password port] @options = t_conf.reject { |k, _| url_keys.include?(k) }.merge(@options) self end |
#user ⇒ Object
93 94 95 96 97 |
# File 'lib/bolt/target.rb', line 93 def user Addressable::URI.unencode_component( @uri_obj.user || @user ) end |