orly 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .idea
data/CHANGELOG.md ADDED
@@ -0,0 +1,2 @@
1
+ # v0.0.1
2
+ * Initial Release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in enumify.gemspec
4
+ gemspec
data/Readme.md ADDED
@@ -0,0 +1,22 @@
1
+ # O RLY ![O RLY owl](https://dl.dropbox.com/u/7525692/orly.png)
2
+
3
+ A tool that lets you know when you need to run `bundle install` or `rake db:migrate`
4
+
5
+ ## Installation
6
+
7
+ Simply install the gem once,
8
+
9
+ [sudo] gem install orly
10
+
11
+ and install O RLY in each Git Repo
12
+
13
+ orly --install
14
+
15
+ To remove O RLY just run `orly --uninstall` inside the git repo.
16
+
17
+ ## More info
18
+
19
+ In the Github page https://github.com/yonbergman/orly/
20
+
21
+ ---
22
+ Copyright (c) 2012 Yonatan Bergman, released under the MIT license
data/bin/orly ADDED
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require 'orly'
5
+ rescue LoadError
6
+ require 'rubygems'
7
+ require 'orly'
8
+ end
9
+
10
+ include Orly
11
+
12
+ Choice.options do
13
+
14
+ header "Orly notifies you whenever you pull an update that requires 'bundle install' or 'rake db:migrate'"
15
+
16
+ option :install do
17
+ short '-i'
18
+ long "--install"
19
+ desc "install orly for this git repo"
20
+ action { Orly::Installation::install() }
21
+ end
22
+
23
+ option :uninstall do
24
+ short '-u'
25
+ long "--uninstall"
26
+ desc "uninstall orly for this git repo"
27
+ action { Orly::Installation::uninstall() }
28
+ end
29
+
30
+ option :run do
31
+ short '-r'
32
+ long "--run"
33
+ desc "run orly now"
34
+ action { Orly::run() }
35
+ end
36
+
37
+ end
38
+
39
+ Choice.help if Choice.choices.empty?
@@ -0,0 +1,42 @@
1
+ module Orly
2
+ module Installation
3
+
4
+ HOOK_PATH = File.join ".git", "hooks", "post-merge"
5
+ HOOK_DIR = File.join ".git", "hooks"
6
+ HOOK_CONTENT = <<END
7
+ #!/bin/sh
8
+ orly --run
9
+ END
10
+
11
+ def self.install
12
+ if not File.directory?(".git")
13
+ puts "You don't appear to be in the base directory of a git project.".red
14
+ exit 1
15
+ end
16
+
17
+ Dir.mkdir(HOOK_DIR) unless File.directory?(HOOK_DIR)
18
+
19
+ if File.exists? HOOK_PATH
20
+ puts "A post-merge hook already exists for this project.".red
21
+ exit 1
22
+ end
23
+
24
+ File.open(HOOK_PATH, 'w') {|f| f.write(HOOK_CONTENT) }
25
+ FileUtils.chmod 0755, HOOK_PATH
26
+ puts "installed O RLY hook as:".green
27
+ puts " -> #{File.expand_path(HOOK_PATH)}".green
28
+ puts "(to remove later, you can use: orly --uninstall)"
29
+ end
30
+
31
+ def self.uninstall
32
+ if File.exists? HOOK_PATH
33
+ FileUtils.rm HOOK_PATH
34
+ puts "uninstalled #{HOOK_PATH}".green
35
+ else
36
+ puts "O RLY is not enabled for this directory, so there is nothing to uninstall.".yellow
37
+ end
38
+ end
39
+
40
+
41
+ end
42
+ end
@@ -0,0 +1,22 @@
1
+ module Orly
2
+ module OwlPrinter
3
+
4
+ OWL = <<END
5
+ ,___,
6
+ {o,O}
7
+ |)``)
8
+ -"-"-
9
+ O RLY?
10
+ END
11
+ OWL_LINES = OWL.split("\n")
12
+
13
+ def self.print(lines = [])
14
+ lines.unshift("") if lines.length < OWL_LINES.length
15
+ [lines.length, OWL_LINES.length].max.times do |i|
16
+ owl_line = OWL_LINES[i] || ""
17
+ print_line = lines[i] || ""
18
+ puts "#{owl_line}\t#{print_line}"
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,41 @@
1
+ require 'git'
2
+
3
+ module Orly
4
+ class NoRepo < StandardError ; end
5
+
6
+ class Tester
7
+
8
+ def initialize
9
+ @need_bundle = false
10
+ @need_migrate = false
11
+ run_tests
12
+ rescue ArgumentError
13
+ raise NoRepo.new
14
+ end
15
+
16
+ def run_tests
17
+ get_diff.each do |file|
18
+ if file.path =~ /^Gemfile/
19
+ @need_bundle = true
20
+ elsif file.path =~ /^db\/migrate/
21
+ @need_migrate = true
22
+ end
23
+ end
24
+ rescue Git::GitExecuteError
25
+ false
26
+ end
27
+
28
+ def get_diff
29
+ git = Git.open('.')
30
+ git.diff('HEAD@{1}','HEAD')
31
+ end
32
+
33
+ def need_migrate?
34
+ @need_migrate
35
+ end
36
+
37
+ def need_bundle_install?
38
+ @need_bundle
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,3 @@
1
+ module Orly
2
+ VERSION = "0.0.4"
3
+ end
data/lib/orly.rb ADDED
@@ -0,0 +1,21 @@
1
+ require 'orly/installation'
2
+ require 'orly/tester'
3
+ require 'orly/owl_printer'
4
+ require 'orly/version'
5
+ require "choice"
6
+ require "colored"
7
+
8
+ module Orly
9
+
10
+ def self.run
11
+ tester = Orly::Tester.new()
12
+ notify = []
13
+ notify << "run 'rake db:migrate'".red if tester.need_migrate?
14
+ notify << "run 'bundle install'".red if tester.need_bundle_install?
15
+ Orly::OwlPrinter.print(notify) unless notify.empty?
16
+ rescue Orly::NoRepo
17
+ puts "O RLY: this is not a git repo".red
18
+ end
19
+
20
+
21
+ end
data/orly.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "orly/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "orly"
7
+ s.version = Orly::VERSION
8
+ s.authors = ["yon"]
9
+ s.email = ["yonatanbergman@gmail.com"]
10
+ s.homepage = "http://github.com/yonbergman/orly"
11
+ s.summary = %q{Tells you when you need to run `bundle install` or `rake db:migrate`}
12
+ s.description = %q{Install a post-merge hook for git that tells you when the Gemfile changed or a migration was added}
13
+
14
+ s.rubyforge_project = "orly"
15
+
16
+ s.files = `git ls-files`.split("\n") - ["Gemfile.lock"]
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ #s.add_development_dependency "rake"
23
+ #s.add_development_dependency "rspec"
24
+ s.add_runtime_dependency "git"
25
+ s.add_runtime_dependency "choice"
26
+ s.add_runtime_dependency "colored"
27
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: orly
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 4
10
+ version: 0.0.4
11
+ platform: ruby
12
+ authors:
13
+ - yon
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-06-27 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: git
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: choice
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: colored
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ type: :runtime
61
+ version_requirements: *id003
62
+ description: Install a post-merge hook for git that tells you when the Gemfile changed or a migration was added
63
+ email:
64
+ - yonatanbergman@gmail.com
65
+ executables:
66
+ - orly
67
+ extensions: []
68
+
69
+ extra_rdoc_files: []
70
+
71
+ files:
72
+ - .gitignore
73
+ - CHANGELOG.md
74
+ - Gemfile
75
+ - Readme.md
76
+ - bin/orly
77
+ - lib/orly.rb
78
+ - lib/orly/installation.rb
79
+ - lib/orly/owl_printer.rb
80
+ - lib/orly/tester.rb
81
+ - lib/orly/version.rb
82
+ - orly.gemspec
83
+ homepage: http://github.com/yonbergman/orly
84
+ licenses: []
85
+
86
+ post_install_message:
87
+ rdoc_options: []
88
+
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ hash: 3
97
+ segments:
98
+ - 0
99
+ version: "0"
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ hash: 3
106
+ segments:
107
+ - 0
108
+ version: "0"
109
+ requirements: []
110
+
111
+ rubyforge_project: orly
112
+ rubygems_version: 1.8.10
113
+ signing_key:
114
+ specification_version: 3
115
+ summary: Tells you when you need to run `bundle install` or `rake db:migrate`
116
+ test_files: []
117
+