Class: Hocho::InventoryProviders::File
- Defined in:
- lib/hocho/inventory_providers/file.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #files ⇒ Object
- #hosts ⇒ Object
-
#initialize(path:) ⇒ File
constructor
A new instance of File.
Constructor Details
#initialize(path:) ⇒ File
Returns a new instance of File.
9 10 11 |
# File 'lib/hocho/inventory_providers/file.rb', line 9 def initialize(path:) @path = path end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
13 14 15 |
# File 'lib/hocho/inventory_providers/file.rb', line 13 def path @path end |
Instance Method Details
#files ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/hocho/inventory_providers/file.rb', line 15 def files @files ||= case when ::File.directory?(path) Dir[::File.join(path, "*.yml")] else [path] end end |
#hosts ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/hocho/inventory_providers/file.rb', line 24 def hosts @hosts ||= files.flat_map do |file| content = Hocho::Utils::Symbolize.keys_of(YAML.load_file(file)) content.map do |name, value| Host.new( name.to_s, providers: self.class, properties: value[:properties] || {}, tags: value[:tags] || {}, ssh_options: value[:ssh_options], ) end end end |