Sha256: 3fbc2f80ab74206fbaa8529c08bb0c1445c1dfb5f0fa8b1266871f1f1c323c68

Contents?: true

Size: 989 Bytes

Versions: 6

Compression:

Stored size: 989 Bytes

Contents

module Gitrob
  module Github
    class Blob
      attr_reader :path, :size, :repository

      def initialize(path, size, repository)
        @path, @size, @repository = path, size, repository
      end

      def extension
        File.extname(path)[1..-1]
      end

      def filename
        File.basename(path)
      end

      def dirname
        File.dirname(path)
      end

      def url
        "https://github.com/#{URI.escape(repository.owner)}/#{URI.escape(repository.name)}/blob/master/#{URI.escape(path)}"
      end

      def to_model(organization, repository)
        repository.blobs.new(
          :path           => self.path,
          :filename       => self.filename,
          :extension      => self.extension,
          :size           => self.size,
          :organization   => organization
        )
      end

      def save_to_database!(organization, repository)
        self.to_model(organization, repository).tap { |m| m.save }
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
gitrob-0.0.6 lib/gitrob/github/blob.rb
gitrob-0.0.5 lib/gitrob/github/blob.rb
gitrob-0.0.4 lib/gitrob/github/blob.rb
gitrob-0.0.3 lib/gitrob/github/blob.rb
gitrob-0.0.2 lib/gitrob/github/blob.rb
gitrob-0.0.1 lib/gitrob/github/blob.rb