Sha256: d0b7651aae616ba705d200e54ebb4446a18a1d76a54f68aaab6ac3746f993eb4

Contents?: true

Size: 630 Bytes

Versions: 2

Compression:

Stored size: 630 Bytes

Contents

# frozen_string_literal: true

module Troy
  class Meta
    extend Forwardable
    def_delegators :data, :[], :fetch, :key?

    REGEX = /^---\n(.*?)\n---\n+/m.freeze

    attr_reader :file

    def initialize(file)
      @file = file
    end

    def content
      @content ||= raw.gsub(REGEX, "")
    end

    def data
      @data ||=
        raw =~ REGEX ? YAML.safe_load(raw[REGEX, 1], [Date, Time]) : {}
    end

    def method_missing(name, *_args)
      data[name.to_s]
    end

    def respond_to_missing?(_method, _include_private = false)
      true
    end

    def raw
      @raw ||= File.read(file)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
troy-0.0.37 lib/troy/meta.rb
troy-0.0.36 lib/troy/meta.rb