Method: KDoc::YamlDoc#load

Defined in:
lib/k_doc/yaml_doc.rb

#load(load_action: :once, data_action: :replace) ⇒ Object

Load data from file

Parameters:

  • load_action (Symbol) (defaults to: :once)

    The load_action to take if data has already been loaded

  • load_action (:once) (defaults to: :once)

    :once will load the data from content source on first try only

  • load_action (:reload) (defaults to: :once)

    :reload will reload from content source each time

  • data_action (Symbol) (defaults to: :replace)

    The data_action to take when setting data, defaults to :replace

  • data_action (:replace) (defaults to: :replace)

    :replace will replace the existing data instance with the incoming data value

  • data_action (:append) (defaults to: :replace)

    :append will keep existing data and then new value data over the top



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/k_doc/yaml_doc.rb', line 31

def load(load_action: :once, data_action: :replace)
  return if load_action == :once && loaded?

  content = File.read(file)
  hash = YAML.safe_load(content)

  set_data(hash, data_action: data_action)

  @loaded = true

  log_any_messages
end