Class: Madrox::Timeline

Inherits:
Object
  • Object
show all
Defined in:
lib/madrox/timeline.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo, user, email = nil) ⇒ Timeline

Returns a new instance of Timeline.



31
32
33
34
35
36
# File 'lib/madrox/timeline.rb', line 31

def initialize(repo, user, email = nil)
  @user  = user
  @email = email
  @repo  = repo
  @grit  = repo.grit
end

Instance Attribute Details

#emailObject

Public: Sets the email for this timeline.

email - The String email.

Returns nothing.



12
13
14
# File 'lib/madrox/timeline.rb', line 12

def email
  @email
end

#gritObject (readonly)

Gets the Grit object for this Madrox::Repo.

Returns a Grit::Repo instance.



29
30
31
# File 'lib/madrox/timeline.rb', line 29

def grit
  @grit
end

#repoObject (readonly)

Gets the Madrox object for this timeline.

Returns a Madrox::Repo instance.



24
25
26
# File 'lib/madrox/timeline.rb', line 24

def repo
  @repo
end

#userObject (readonly)

Public: Gets the user name for this timeline.

Returns a String.



6
7
8
# File 'lib/madrox/timeline.rb', line 6

def user
  @user
end

Instance Method Details

#actorObject

Public: Builds a Git actor object for any posted updates to this timeline. Uses the timelines user and email.

Returns a Grit::Actor.



87
88
89
# File 'lib/madrox/timeline.rb', line 87

def actor
  Grit::Actor.new(@user, @email)
end

#messagesObject

Public: Gets the messages for this timeline. Automatically removes any merge commits.

Returns an Array of Grit::Commit instances.



42
43
44
# File 'lib/madrox/timeline.rb', line 42

def messages
  @grit.log(@user).delete_if { |commit| commit.parents.size != 1 }
end

#post(message, options = {}) ⇒ Object

Posts the given message to the timeline. This is a simple commit with no changed content. Just a message.

message - String message for the timeline update. options - Hash of options passed to Grit::Index#commit.

Returns a String SHA1 of the created Git commit.



53
54
55
56
57
58
59
# File 'lib/madrox/timeline.rb', line 53

def post(message, options = {})
  idx     = @grit.index
  parents = [@grit.commit(@user) || @grit.commit("HEAD")]
  parents.compact!
  options.update(:parents => parents, :committer => actor, :head => @user)
  @grit.index.commit(message, options)
end

#retweet(commit, message, options = {}) ⇒ Object

Retweets a given commit. The author name and date is taken from the commit. The message can optionally be annotated.

commit - The Grit::Commit that is being retweeted. message - An optional String annotation to the retweet content. options - An optional Hash that is passed to #post.

Returns a String SHA1 of the created Git commit.



69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/madrox/timeline.rb', line 69

def retweet(commit, message, options = {})
  if message.is_a?(Hash)
    options = message
    message = nil
  end
  if message
    message << " RT @#{commit.author.name}"
  end
  message = "#{message} #{commit.message}"
  message.strip!
  post(message, options.update(:author => commit.author, 
    :authored_date => commit.authored_date))
end