Class: Streamer::FactProviders::YamlProvider

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/streamer/fact_providers/yaml_provider.rb

Overview

YamlProvider provides data from a yaml file

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path: nil, yaml: nil) ⇒ YamlProvider

Returns a new instance of YamlProvider.



10
11
12
13
# File 'lib/streamer/fact_providers/yaml_provider.rb', line 10

def initialize(path: nil, yaml: nil)
  load_file(path) if path
  load_yaml(yaml) if yaml
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



7
8
9
# File 'lib/streamer/fact_providers/yaml_provider.rb', line 7

def data
  @data
end

Instance Method Details

#load_file(path) ⇒ Object



15
16
17
# File 'lib/streamer/fact_providers/yaml_provider.rb', line 15

def load_file(path)
  @data = YAML.load(File.read(path))
end

#load_yaml(yaml) ⇒ Object



19
20
21
# File 'lib/streamer/fact_providers/yaml_provider.rb', line 19

def load_yaml(yaml)
  @data = YAML.load(yaml)
end

#providerObject



23
24
25
# File 'lib/streamer/fact_providers/yaml_provider.rb', line 23

def provider
  @provider ||= HashProvider.new(data)
end