Sha256: 1f3ca3cc5d281fbe1052961208194d598a5652241d7b8d60d41d14a047f9b6a3

Contents?: true

Size: 572 Bytes

Versions: 31

Compression:

Stored size: 572 Bytes

Contents

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

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

    attr_reader :file

    def initialize(file)
      @file = file
    end

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

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

    def method_missing(name, *args, &block)
      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

31 entries across 31 versions & 1 rubygems

Version Path
troy-0.0.15 lib/troy/meta.rb
troy-0.0.14 lib/troy/meta.rb
troy-0.0.13 lib/troy/meta.rb
troy-0.0.12 lib/troy/meta.rb
troy-0.0.11 lib/troy/meta.rb
troy-0.0.10 lib/troy/meta.rb
troy-0.0.9 lib/troy/meta.rb
troy-0.0.8 lib/troy/meta.rb
troy-0.0.7 lib/troy/meta.rb
troy-0.0.6 lib/troy/meta.rb
troy-0.0.5 lib/troy/meta.rb