gitstagram 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+ .rspec
15
+ Gemfile.lock
16
+
17
+ # YARD artifacts
18
+ .yardoc
19
+ _yardoc
20
+ doc/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'http://rubygems.org'
2
+ gemspec
3
+
4
+ group :test do
5
+ gem 'rspec'
6
+ gem 'rr'
7
+ end
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ gitstagram
2
+ ==========
3
+
4
+ Gitstagram is gem that will let take a snapshot after every commit and will generate a time lapse movie from all those snapshots.
data/bin/gitstagram ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/gitstagram/cli.rb'
4
+
5
+ begin
6
+ cli = Gitstagram::CLI.new
7
+ cli.run
8
+ rescue => e
9
+ STDERR.puts e.message
10
+ STDERR.puts e.backtrace.join("\n")
11
+ exit 1
12
+ end
@@ -0,0 +1,17 @@
1
+ require File.expand_path('../lib/gitstagram/version', __FILE__)
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.authors = ["Gregory Marcilhacy"]
5
+ gem.email = ["g.marcilhacy@gmail.com"]
6
+ gem.description = gem.summary = "Take a snapshot after each commit."
7
+ gem.homepage = "https://github.com/gregorym/gitstagram"
8
+
9
+ gem.executables = ['gitstagram']
10
+ gem.files = `git ls-files | grep -v myapp`.split("\n")
11
+ gem.test_files = `git ls-files -- spec/*`.split("\n")
12
+ gem.name = "gitstagram"
13
+ gem.require_paths = ["lib"]
14
+ gem.version = Gitstagram::VERSION
15
+
16
+ gem.add_development_dependency 'rspec'
17
+ end
@@ -0,0 +1,50 @@
1
+ require 'optparse'
2
+ require 'gitstagram'
3
+
4
+ module Gitstagram
5
+ class CLI
6
+
7
+ def run(args=ARGV)
8
+ parse_options(args)
9
+ end
10
+
11
+ def parse_options(argv)
12
+ opts = {}
13
+
14
+ @parser = OptionParser.new do |o|
15
+ o.on "-i", "--install" do
16
+ begin
17
+ Gitstagram.install
18
+ rescue NotGitDirectoryError
19
+ puts "This directory is not a Git repository."
20
+ rescue PostCommitAlreadyExistError
21
+ puts "Cannot install Gitstagram, a post-commit already exists."
22
+ end
23
+ end
24
+
25
+ o.on "-u", "--uninstall" do
26
+ begin
27
+ Gitstagram.uninstall
28
+ rescue NotGitDirectoryError
29
+ puts "This directory is not a Git directory."
30
+ rescue NoPostCommitExistError
31
+ puts "Gitstagram is not installed in this Git repository."
32
+ end
33
+ end
34
+
35
+ o.on "-t", "--timelapse" do
36
+ begin
37
+ Gitstagram.timelapse
38
+ rescue NoSnapshotError
39
+ puts "you do not have any snapshots yet."
40
+ end
41
+ end
42
+
43
+ end
44
+
45
+ @parser.parse!(argv)
46
+ opts
47
+ end
48
+
49
+ end
50
+ end
@@ -0,0 +1,6 @@
1
+ module Gitstagram
2
+ class NotGitDirectoryError < StandardError; end;
3
+ class PostCommitAlreadyExistError < StandardError; end;
4
+ class NoPostCommitExistError < StandardError; end;
5
+ class NoSnapshotError < StandardError; end;
6
+ end
@@ -0,0 +1,40 @@
1
+ module Gitstagram
2
+ class GitDir < Dir
3
+
4
+ #
5
+ # Returns true if the current directory is a git directory.
6
+ ## Check the presence of .git in the folder
7
+ #
8
+ def is_git_directory?
9
+ Dir.glob('.git').include? '.git'
10
+ end
11
+ alias_method :is_git_dir?, :is_git_directory?
12
+
13
+
14
+ #
15
+ # Returns true if the git directory already has a post-commit hook.
16
+ #
17
+ def has_post_commit_hook?
18
+ Dir.glob('.git/hooks/*').include? '.git/hooks/post-commit'
19
+ end
20
+
21
+ #
22
+ # Remove post-commit file from .git/hooks
23
+ #
24
+ def delete_post_commit
25
+ file_path = path + '/.git/hooks/post-commit'
26
+ if File.exists? file_path
27
+ File.delete file_path
28
+ end
29
+ end
30
+
31
+ def add_post_commit
32
+ file = File.open(File.expand_path('post-commit', File.dirname(__FILE__)), 'r') { |f| f.read }
33
+ file.sub!('*||*') do |s|
34
+ File.expand_path('../gitstagram.rb', File.dirname(__FILE__))
35
+ end
36
+
37
+ File.open('./.git/hooks/post-commit', 'w', 0755) {|f| f.write(file) }
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,11 @@
1
+ module Gitstagram
2
+ class MovieMaker
3
+
4
+ class << self
5
+ def build
6
+ Gitstagram::SystemCaller.call "#{Gitstagram.tools_path}/tlassemble #{Gitstagram.saving_path} ~/Desktop/gitstagram.mov -quiet yes"
7
+ end
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ begin
5
+ require 'gitstagram'
6
+ rescue LoadError
7
+ STDERR.puts 'Gistagram is not install. Run: gem install gitstgram'
8
+ end
9
+
10
+ begin
11
+ Gitstagram::Snapshot.smile
12
+ rescue e
13
+ STDERR.puts e.message
14
+ STDERR.puts e.backtrace.join(', ')
15
+ end
16
+ exit 0
@@ -0,0 +1,17 @@
1
+ module Gitstagram
2
+ class Snapshot
3
+
4
+ class << self
5
+
6
+ #
7
+ # Takes a snapshot
8
+ #
9
+ def smile
10
+ saving_path = Gitstagram.saving_path + "/#{Time.now.to_i}.jpg"
11
+ Gitstagram::SystemCaller.call "#{Gitstagram.tools_path}/imagesnap -q -w 3 #{saving_path}"
12
+ end
13
+
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ module Gitstagram
2
+ class SystemCaller
3
+ class << self
4
+ def call(command)
5
+ system command
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module Gitstagram
2
+ VERSION = "0.0.1"
3
+ end
data/lib/gitstagram.rb ADDED
@@ -0,0 +1,71 @@
1
+ require 'gitstagram/version'
2
+ require 'gitstagram/errors'
3
+ require 'gitstagram/system_caller'
4
+ require 'gitstagram/git_dir'
5
+ require 'gitstagram/snapshot'
6
+ require 'gitstagram/movie_maker'
7
+
8
+ module Gitstagram
9
+ class << self
10
+
11
+ #
12
+ # Returns the absolute path of the tools folder
13
+ #
14
+ def tools_path
15
+ File.expand_path('../tools', File.dirname(__FILE__))
16
+ end
17
+
18
+ #
19
+ # Returns the absolute path to the home directory
20
+ #
21
+ def home_path
22
+ File.expand_path("~")
23
+ end
24
+
25
+ #
26
+ # Returns the path to where images are saved.
27
+ #
28
+ def saving_path
29
+ path = home_path + '/.gitstagram'
30
+
31
+ Dir.mkdir(path) unless Dir.exists?(path)
32
+ path
33
+ end
34
+
35
+ #
36
+ # Install the post-commit hook
37
+ #
38
+ def install
39
+ git_dir = GitDir.new(File.expand_path("."))
40
+ raise NotGitDirectoryError unless git_dir.is_git_directory?
41
+ raise PostCommitAlreadyExistError if git_dir.has_post_commit_hook?
42
+
43
+ git_dir.add_post_commit
44
+ puts 'Gitstagram properly installed.'
45
+ end
46
+
47
+ #
48
+ # Remove the post-commit hook
49
+ #
50
+ def uninstall
51
+ git_dir = GitDir.new(File.expand_path("."))
52
+ raise NotGitDirectoryError unless git_dir.is_git_directory?
53
+ raise NoPostCommitExistError unless git_dir.has_post_commit_hook?
54
+
55
+ git_dir.delete_post_commit
56
+ puts 'Gitstagram properly uninstalled from this Git repository.'
57
+ end
58
+
59
+ #
60
+ # Generate video from all the snapshots
61
+ #
62
+ def timelapse
63
+ raise NoSnapshotError if Dir.glob(saving_path+'/*.jpg').count.zero?
64
+
65
+ puts "Generate video..."
66
+ MovieMaker.build
67
+ puts "Video is ready."
68
+ end
69
+
70
+ end
71
+ end
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gitstagram::GitDir do
4
+ before do
5
+ @dir = Gitstagram::GitDir.new('.')
6
+ end
7
+
8
+ describe "#is_git_directory?" do
9
+ context 'folder contains a .git directory' do
10
+ before do
11
+ stub(Dir).glob { ['.git'] }
12
+ end
13
+
14
+ it 'should return true' do
15
+ @dir.is_git_dir?.should be_true
16
+ end
17
+ end
18
+
19
+ context 'folder does not contain a .git directory' do
20
+ before do
21
+ stub(Dir).glob { ['hello', 'world'] }
22
+ end
23
+
24
+ it 'should return false' do
25
+ @dir.is_git_dir?.should be_false
26
+ end
27
+ end
28
+ end
29
+
30
+ describe "#has_post_commit_hook" do
31
+ context "hooks folder contains a post-commit file" do
32
+ before do
33
+ stub(Dir).glob { ['.git/hooks/post-commit', '.git/hooks/pre-commit.sample'] }
34
+ end
35
+
36
+ it "should return true" do
37
+ @dir.has_post_commit_hook?.should be_true
38
+ end
39
+
40
+ end
41
+
42
+ context "hooks folder does not contain a post-commit file" do
43
+ before do
44
+ stub(Dir).glob { ['post-commit.sample', 'pre-commit.sample'] }
45
+ end
46
+
47
+ it "should return true" do
48
+ @dir.has_post_commit_hook?.should be_false
49
+ end
50
+ end
51
+ end
52
+
53
+ describe "#delete_post_commit" do
54
+ before do
55
+ stub(File).exists? { true }
56
+ mock(File).delete("./.git/hooks/post-commit")
57
+ end
58
+
59
+ it "should delete the post-commit file" do
60
+ @dir.delete_post_commit
61
+ end
62
+ end
63
+
64
+ end
@@ -0,0 +1,87 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gitstagram do
4
+
5
+ describe "#saving_path" do
6
+ it "should return path to the ./gitstagram folder" do
7
+ user = File.expand_path("~").split('/').last
8
+ home = Gitstagram.saving_path.should == "/Users/#{user}/.gitstagram"
9
+ end
10
+ end
11
+
12
+ describe "#install" do
13
+ it "should raise NotGitDirectoryError" do
14
+ any_instance_of(Gitstagram::GitDir) do |gd|
15
+ stub(gd).is_git_directory? { false }
16
+ end
17
+ lambda {
18
+ Gitstagram.install
19
+ }.should raise_error(Gitstagram::NotGitDirectoryError)
20
+ end
21
+
22
+ it "should raise PostCommitAlreadyExistError" do
23
+ any_instance_of(Gitstagram::GitDir) do |gd|
24
+ stub(gd).is_git_directory? { true }
25
+ stub(gd).has_post_commit_hook? { true }
26
+ end
27
+
28
+ lambda {
29
+ Gitstagram.install
30
+ }.should raise_error(Gitstagram::PostCommitAlreadyExistError)
31
+ end
32
+
33
+ it "should call #add_post_commit" do
34
+ any_instance_of(Gitstagram::GitDir) do |gd|
35
+ stub(gd).is_git_directory? { true }
36
+ stub(gd).has_post_commit_hook? { false }
37
+ mock(gd).add_post_commit
38
+ end
39
+
40
+ Gitstagram.install
41
+ end
42
+ end
43
+
44
+ describe "#uninstall" do
45
+ it "should raise NotGitDirectoryError" do
46
+ any_instance_of(Gitstagram::GitDir) do |gd|
47
+ stub(gd).is_git_directory? { false }
48
+ end
49
+
50
+ lambda {
51
+ Gitstagram.uninstall
52
+ }.should raise_error(Gitstagram::NotGitDirectoryError)
53
+ end
54
+
55
+ it "should raise NoPostCommitExistError" do
56
+ any_instance_of(Gitstagram::GitDir) do |gd|
57
+ stub(gd).is_git_directory? { true }
58
+ stub(gd).has_post_commit_hook? { false }
59
+ end
60
+
61
+ lambda {
62
+ Gitstagram.uninstall
63
+ }.should raise_error(Gitstagram::NoPostCommitExistError)
64
+ end
65
+
66
+ it "should call #delete_post_commit" do
67
+ any_instance_of(Gitstagram::GitDir) do |gd|
68
+ stub(gd).is_git_directory? { true }
69
+ stub(gd).has_post_commit_hook? { true }
70
+ mock(gd).delete_post_commit
71
+ end
72
+
73
+ Gitstagram.uninstall
74
+ end
75
+ end
76
+
77
+ describe "#timelapse" do
78
+ it "should raise NoSnapshotError" do
79
+ stub(Dir).glob { [] }
80
+
81
+ lambda {
82
+ Gitstagram.timelapse
83
+ }.should raise_error(Gitstagram::NoSnapshotError)
84
+ end
85
+ end
86
+
87
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gitstagram::MovieMaker do
4
+
5
+ describe "#build" do
6
+ before do
7
+ command = "#{Gitstagram.tools_path}/tlassemble #{Gitstagram.saving_path} ~/Desktop/gitstagram.mov -quiet yes"
8
+ mock(Gitstagram::SystemCaller).call(command)
9
+ end
10
+
11
+ it "should build the timelapse" do
12
+ Gitstagram::MovieMaker.build
13
+ end
14
+ end
15
+
16
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gitstagram::Snapshot do
4
+
5
+ describe "#smile" do
6
+ before do
7
+ stub(Time).now { 123 }
8
+ command = "#{Gitstagram.tools_path}/imagesnap -q -w 3 #{Gitstagram.saving_path}/123.jpg"
9
+ mock(Gitstagram::SystemCaller).call(command)
10
+ end
11
+
12
+ it "should take a snapshot" do
13
+ Gitstagram::Snapshot.smile
14
+ end
15
+ end
16
+
17
+ end
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'gitstagram'
5
+
6
+ RSpec.configure do |config|
7
+ config.mock_with :rr
8
+ end
data/tools/.DS_Store ADDED
Binary file
data/tools/imagesnap ADDED
Binary file
data/tools/tlassemble ADDED
Binary file
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gitstagram
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Gregory Marcilhacy
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Take a snapshot after each commit.
31
+ email:
32
+ - g.marcilhacy@gmail.com
33
+ executables:
34
+ - gitstagram
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - .gitignore
39
+ - Gemfile
40
+ - README.md
41
+ - gitstagram.gemspec
42
+ - lib/gitstagram.rb
43
+ - lib/gitstagram/cli.rb
44
+ - lib/gitstagram/errors.rb
45
+ - lib/gitstagram/git_dir.rb
46
+ - lib/gitstagram/movie_maker.rb
47
+ - lib/gitstagram/post-commit
48
+ - lib/gitstagram/snapshot.rb
49
+ - lib/gitstagram/system_caller.rb
50
+ - lib/gitstagram/version.rb
51
+ - spec/git_dir_spec.rb
52
+ - spec/gitstagram_spec.rb
53
+ - spec/movie_maker_spec.rb
54
+ - spec/snapshot_spec.rb
55
+ - spec/spec_helper.rb
56
+ - tools/.DS_Store
57
+ - tools/imagesnap
58
+ - tools/tlassemble
59
+ - bin/gitstagram
60
+ homepage: https://github.com/gregorym/gitstagram
61
+ licenses: []
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 1.8.23
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: Take a snapshot after each commit.
84
+ test_files:
85
+ - spec/git_dir_spec.rb
86
+ - spec/gitstagram_spec.rb
87
+ - spec/movie_maker_spec.rb
88
+ - spec/snapshot_spec.rb
89
+ - spec/spec_helper.rb