Module: FrozenRecord::Backends::Yaml

Extended by:
Yaml
Included in:
Yaml
Defined in:
lib/frozen_record/backends/yaml.rb

Instance Method Summary collapse

Instance Method Details

#filename(model_name) ⇒ String

Transforms the model name into a valid filename.

Parameters:

  • format (String)

    the model name that inherits from FrozenRecord::Base

Returns:

  • (String)

    the file name.



11
12
13
# File 'lib/frozen_record/backends/yaml.rb', line 11

def filename(model_name)
  "#{model_name.underscore.pluralize}.yml"
end

#load(file_path) ⇒ Array

Reads file in ‘file_path` and return records.

Parameters:

  • format (String)

    the file path

Returns:

  • (Array)

    an Array of Hash objects with keys being attributes.



19
20
21
22
23
24
# File 'lib/frozen_record/backends/yaml.rb', line 19

def load(file_path)
  yml_erb_data = File.read(file_path)
  yml_data = ERB.new(yml_erb_data).result

  YAML.load(yml_data) || []
end