Friday, September 20, 2024 3:00:21 AM
> settings

Customize


Authenticate

> file.rb
# frozen_string_literal: true

class Project
  class File < Entry
    def initialize(...)
      super

      @type = @path.extname
      @last_modified_at = nil
    end

    def parent?(parent)
      return false if parent.nil?

      parent.key.slice(0, key.size - 1) == key[..-2] # Without filename
    end

    def child?(_child)
      false
    end

    def self_or_child?(_child)
      false
    end

    def content
      if @last_modified_at == modified_at
        @content
      else
        @last_modified_at = modified_at
        @content = ::File.read(@path)
      end
    end

    def mime_type
      Marcel::MimeType.for(@path)
    end

    private

    def modified_at
      @path.mtime
    end
  end
end
All opinions represented herein are my own
- © 2024 itsthedevman
- build 340fbb8