Sha256: c8262e8b53faa3f044cdc0099a20d39edd3a8c6d9e1e53c1f3f82837dfbe7b2e

Contents?: true

Size: 1.69 KB

Versions: 1

Compression:

Stored size: 1.69 KB

Contents

module Integrity
  class Commit
    include DataMapper::Resource

    property :id,           Integer,  :serial => true
    property :identifier,   String,   :nullable => false
    property :message,      String,   :length => 255
    property :author,       Author,   :length => 255
    property :url,          String
    property :committed_at, DateTime
    property :created_at,   DateTime
    property :updated_at,   DateTime

    has 1,     :build,   :class_name => "Integrity::Build",
                         :order => [:created_at.desc]

    belongs_to :project, :class_name => "Integrity::Project",
                         :child_key => [:project_id]

    def message
      attribute_get(:message) || "<Commit message not loaded>"
    end

    def author
      attribute_get(:author) ||
        Author.load('<Commit author not loaded> <<Commit author not loaded>>', :author)
    end

    def short_identifier
      identifier.to_s[0..6]
    end

    def status
      build.nil? ? :pending : build.status
    end

    def successful?
      status == :success
    end

    def failed?
      status == :failed
    end

    def pending?
      status == :pending
    end

    def human_readable_status
      case status
      when :success; "Built #{short_identifier} successfully"
      when :failed;  "Built #{short_identifier} and failed"
      when :pending; "#{short_identifier} hasn't been built yet"
      end
    end

    def output
      build && build.output
    end
    
    def committed_at=(time_with_timezone)
      unless time_with_timezone.respond_to?(:getlocal)
        time_with_timezone = Time.parse(time_with_timezone)
      end
      attribute_set(:committed_at, time_with_timezone.getlocal)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
alphasights-integrity-0.1.9.8 lib/integrity/commit.rb