Class: Madrox::Timeline
- Inherits:
-
Object
- Object
- Madrox::Timeline
- Defined in:
- lib/madrox/timeline.rb
Instance Attribute Summary collapse
-
#email ⇒ Object
Public: Sets the email for this timeline.
-
#grit ⇒ Object
readonly
Gets the Grit object for this Madrox::Repo.
-
#repo ⇒ Object
readonly
Gets the Madrox object for this timeline.
-
#user ⇒ Object
readonly
Public: Gets the user name for this timeline.
Instance Method Summary collapse
-
#actor ⇒ Object
Public: Builds a Git actor object for any posted updates to this timeline.
-
#fave(commit) ⇒ Object
Public: Marks a given commit as a favorite.
-
#initialize(repo, user, email = nil) ⇒ Timeline
constructor
A new instance of Timeline.
-
#messages(options = {}) ⇒ Object
Public: Gets the messages for this timeline.
-
#post(message, options = {}) ⇒ Object
Public: Posts the given message to the timeline.
-
#retweet(commit, message, options = {}) ⇒ Object
Public: Retweets a given commit.
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
#email ⇒ Object
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 |
#grit ⇒ Object (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 |
#repo ⇒ Object (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 |
#user ⇒ Object (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
#actor ⇒ Object
Public: Builds a Git actor object for any posted updates to this timeline. Uses the timelines user and email.
Returns a Grit::Actor.
110 111 112 |
# File 'lib/madrox/timeline.rb', line 110 def actor Grit::Actor.new(@user, @email) end |
#fave(commit) ⇒ Object
Public: Marks a given commit as a favorite. The commit is stored in a separate branch named “##user-favorites”. The commit’s original committed author and date remain the same, and the new commit tracks the date it was favorited.
101 102 103 104 |
# File 'lib/madrox/timeline.rb', line 101 def fave(commit) post(commit., :head => "#{@user}-favorites", :author => commit., :authored_date => commit.) end |
#messages(options = {}) ⇒ Object
Public: Gets the messages for this timeline. Automatically removes any merge commits.
options - Hash of options to filter the message output.
:max_count - Fixnum specifying the number of commits to show.
Default: 30.
:skip - Fixnum specifying the number of commits to skip.
:page - Fixnum of the current page. This is used to
implicitly calculate the :skip option.
Default: 1
Returns an Array of Grit::Commit instances.
50 51 52 53 54 55 56 57 58 |
# File 'lib/madrox/timeline.rb', line 50 def ( = {}) [:no_merges] = true [:max_count] ||= 30 [:skip] ||= begin [:max_count] * ([.delete(:page).to_i, 1].max - 1) end @grit.log(@user, nil, ). delete_if { |commit| commit.parents.size != 1 } end |
#post(message, options = {}) ⇒ Object
Public: 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.
67 68 69 70 71 72 73 |
# File 'lib/madrox/timeline.rb', line 67 def post(, = {}) idx = @grit.index = {:committer => actor, :head => @user}.update() [:parents] ||= [@grit.commit(@user) || @grit.commit("HEAD")] [:parents].compact! @grit.index.commit(, ) end |
#retweet(commit, message, options = {}) ⇒ Object
Public: 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.
83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/madrox/timeline.rb', line 83 def retweet(commit, , = {}) if .is_a?(Hash) = = nil end if << " RT @#{commit..name}" end = "#{} #{commit.}" .strip! post(, .update(:author => commit., :authored_date => commit.)) end |