Sha256: 4fcf0d5d9d9817518e652e17487182fe8738d681a546cd0de82c0ea7d254db52

Contents?: true

Size: 728 Bytes

Versions: 8

Compression:

Stored size: 728 Bytes

Contents

module FrozenRecord
  module Backends
    module Yaml
      extend self

      # Transforms the model name into a valid filename.
      #
      # @param format [String] the model name that inherits
      #   from FrozenRecord::Base
      # @return [String] the file name.
      def filename(model_name)
        "#{model_name.underscore.pluralize}.yml"
      end

      # Reads file in `file_path` and return records.
      #
      # @param format [String] the file path
      # @return [Array] an Array of Hash objects with keys being attributes.
      def load(file_path)
        yml_erb_data = File.read(file_path)
        yml_data = ERB.new(yml_erb_data).result

        YAML.load(yml_data) || []
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
frozen_record-0.16.0 lib/frozen_record/backends/yaml.rb
frozen_record-0.15.0 lib/frozen_record/backends/yaml.rb
frozen_record-0.14.0 lib/frozen_record/backends/yaml.rb
frozen_record-0.13.0 lib/frozen_record/backends/yaml.rb
frozen_record-0.12.1 lib/frozen_record/backends/yaml.rb
frozen_record-0.12.0 lib/frozen_record/backends/yaml.rb
frozen_record-0.11.0 lib/frozen_record/backends/yaml.rb
frozen_record-0.10.0 lib/frozen_record/backends/yaml.rb