Module: PlainRecord::Extra::Git
- Defined in:
- lib/plain_record/extra/git.rb
Overview
Extention to get time from git commits of model file.
It make sense only with ‘entry_in` models. You can get created or modified time from first or last git commit time.
It is additional extention, so you need to include ‘PlainRecord::Extra::Git` module to your model.
class Post
include PlainRecord::Resource
include PlainRecord::Extra::Git
virtual :created_at, git_created_time
virtual :updated_at, git_modify_time
end
Defined Under Namespace
Modules: Model
Class Method Summary collapse
Instance Method Summary collapse
-
#first_git_commit ⇒ Object
Return time of first commit of model file (created time).
-
#git_uncommitted? ⇒ Boolean
If file have changes, that is not commited yet.
-
#last_git_commit ⇒ Object
Return time of last commit of model file (modified time).
Class Method Details
.included(base) ⇒ Object
38 39 40 |
# File 'lib/plain_record/extra/git.rb', line 38 def self.included(base) base.send :extend, Model end |
Instance Method Details
#first_git_commit ⇒ Object
Return time of first commit of model file (created time).
If file isn’t commited yet, it will return ‘Time.now`.
45 46 47 48 49 50 |
# File 'lib/plain_record/extra/git.rb', line 45 def first_git_commit return Time.now unless file times = `git log --reverse --date=iso --pretty=format:%cD #{file}` time = times.split("\n").first time ? Time.parse(time) : Time.now end |
#git_uncommitted? ⇒ Boolean
If file have changes, that is not commited yet.
62 63 64 |
# File 'lib/plain_record/extra/git.rb', line 62 def git_uncommitted? not `git status -s #{file}`.empty? end |
#last_git_commit ⇒ Object
Return time of last commit of model file (modified time).
If file isn’t commited yet, it will return ‘Time.now`.
55 56 57 58 59 |
# File 'lib/plain_record/extra/git.rb', line 55 def last_git_commit return Time.now if file.nil? or git_uncommitted? time = `git log -1 --date=iso --pretty=format:%cD #{file}` time ? Time.parse(time) : Time.now end |