Sha256: 3620f6a95a893e3adcd820a1e4759151327ffd971c9cef94a3b99d7351825a26

Contents?: true

Size: 809 Bytes

Versions: 1

Compression:

Stored size: 809 Bytes

Contents

module Munge
  class ItemFactory
    def initialize(sourcepath, binary_extensions)
      @sourcepath        = sourcepath
      @binary_extensions = binary_extensions
    end

    def create(filepath)
      path    = Munge::Attribute::Path.new(@sourcepath, filepath)
      content = Munge::Attribute::Content.new(File.read(path.absolute))
      stat    = Munge::Attribute::Metadata.new(filepath)

      if binary_extension?(filepath)
        Munge::Item::Binary.new(path, content, stat)
      else
        Munge::Item::Text.new(path, content, stat)
      end
    end

    private

    def binary_extension?(filepath)
      file_extensions = File.basename(filepath).split(".")[1..-1]

      extensions_intersection = @binary_extensions & file_extensions

      !extensions_intersection.empty?
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
munge-0.2.0 lib/munge/core/source/item_factory.rb