Sha256: 7faf04207637dd65e6952a2c095f37b7bc6fa809ee426de0baaa4c2a9c785ac1

Contents?: true

Size: 944 Bytes

Versions: 9

Compression:

Stored size: 944 Bytes

Contents

module Gitrb

  # This class stores the raw string data of a blob
  class Blob < GitObject

    attr_reader :data, :mode

    # Initialize a Blob
    def initialize(options = {})
      super(options)
      @data = options[:data]
      @mode = options[:mode] || 0100644
      @modified = true if !id
    end

    def modified?
      @modified
    end

    # Set mode
    def mode=(mode)
      if mode != @mode
        @mode = mode
        @modified = true
      end
    end

    # Set data
    def data=(data)
      if data != @data
        @data = data
        @modified = true
      end
    end

    # Set new repository (modified flag is reset)
    def id=(id)
      @modified = false
      super
    end

    def type
      :blob
    end

    def dump
      @data
    end

    # Save the data to the git object repository
    def save
      raise 'Blob is empty' if !data
      repository.put(self) if modified?
      id
    end

  end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
gitrb-0.2.8 lib/gitrb/blob.rb
gitrb-0.2.7 lib/gitrb/blob.rb
gitrb-0.2.6 lib/gitrb/blob.rb
gitrb-0.2.5 lib/gitrb/blob.rb
gitrb-0.2.4 lib/gitrb/blob.rb
gitrb-0.2.3 lib/gitrb/blob.rb
gitrb-0.2.2 lib/gitrb/blob.rb
gitrb-0.2.1 lib/gitrb/blob.rb
gitrb-0.2.0 lib/gitrb/blob.rb