git-version 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7abd95f02647559aa6cec401e08d2c2edbe2da8f
4
+ data.tar.gz: b0663e91d71fac7848102c35f5dce9a45f9dbac3
5
+ SHA512:
6
+ metadata.gz: 1181dbe9d831a2b2a38d558c36078a7c7ad9e56370fdb12834611ee2efad293608af8372a4d67292761422b5b87679cbf9a0fb1aeb34db22d20ffbb8c767f6bd
7
+ data.tar.gz: 5f8c2d3914404c44335beb0938de6c5c743dcd9a77c918aafd0c2af638153ee5db4cd8d2f2b4962eba7b56c96b7b6d39bebf3092d2adc4b3ca36b1deeff71692
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/README.md CHANGED
@@ -10,7 +10,7 @@ I also wanted to play around with rails engines.
10
10
 
11
11
  Prerequisites
12
12
  -------------
13
- - Rails 3
13
+ - Rails > 3.1.0
14
14
  - Using git for deployment
15
15
 
16
16
  Installation
data/Rakefile CHANGED
@@ -1 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new('spec')
5
+
6
+ task :default => :spec
7
+
@@ -1,7 +1,5 @@
1
- require 'grit'
2
-
3
1
  GitVersion::Engine.routes.draw do
4
- root :to => proc {|env| [200, {}, [ENV['COMMIT_HASH'] || Grit::Repo.new(Rails.root + '.git').commits.first.id[0...7]]]}
2
+ root :to => proc {|env| [200, {'Content-Type' => 'text/plain'}, [GitVersion::Finder.new.find]]}
5
3
  end
6
4
 
7
5
  Rails.application.routes.draw do
@@ -18,5 +18,5 @@ Gem::Specification.new do |s|
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
20
 
21
- s.add_runtime_dependency "grit"
21
+ s.add_development_dependency "rspec"
22
22
  end
@@ -0,0 +1,24 @@
1
+ module GitVersion
2
+ module Generators
3
+ class InstallGenerator < ::Rails::Generators::Base
4
+
5
+ desc <<DESC
6
+ Description:
7
+ Copy git-version files to your application.
8
+ DESC
9
+
10
+ def self.source_root
11
+ @source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
12
+ end
13
+
14
+ def copy_gitattributes
15
+ template 'gitattributes', '.gitattributes'
16
+ end
17
+
18
+ def copy_version
19
+ template 'config/version.txt'
20
+ end
21
+ end
22
+ end
23
+ end
24
+
@@ -0,0 +1,2 @@
1
+ config/version.txt ident
2
+
@@ -1,5 +1,7 @@
1
- require "git-version/version"
2
- require "git-version/engine"
1
+ require 'git-version/version'
2
+ require 'git-version/engine'
3
+ require 'git-version/finder'
3
4
 
4
5
  module GitVersion
5
6
  end
7
+
@@ -3,3 +3,4 @@ module GitVersion
3
3
  isolate_namespace GitVersion
4
4
  end
5
5
  end
6
+
@@ -0,0 +1,26 @@
1
+ module GitVersion
2
+ class Finder
3
+ def find
4
+ from_environment || from_config_file || from_git_repo
5
+ end
6
+
7
+ private
8
+
9
+ def from_environment
10
+ ENV['COMMIT_HASH']
11
+ end
12
+
13
+ def from_config_file
14
+ version_file = File.join(Rails.root, 'config', 'version.txt')
15
+
16
+ if File.exists? version_file
17
+ File.read(version_file).match(/\$Id: ([a-zA-Z0-9]*) \$/)[1] rescue nil
18
+ end
19
+ end
20
+
21
+ def from_git_repo
22
+ `git rev-parse HEAD`
23
+ end
24
+ end
25
+ end
26
+
@@ -1,3 +1,4 @@
1
1
  module GitVersion
2
- VERSION = "0.0.2"
2
+ VERSION = '0.0.3'
3
3
  end
4
+
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+ require 'git-version/finder'
3
+ require 'tmpdir'
4
+ require 'fileutils'
5
+
6
+ describe GitVersion::Finder do
7
+ after(:each) do
8
+ ENV['COMMIT_HASH'] = nil
9
+ end
10
+
11
+ it 'uses the COMMIT_HASH environment variable' do
12
+ ENV['COMMIT_HASH'] = '12345'
13
+
14
+ expect(subject.find).to eq('12345')
15
+ end
16
+
17
+ it 'uses the config/version.txt file if it exists' do
18
+ Dir.mktmpdir do |root|
19
+ Rails.root = root
20
+ FileUtils.mkdir(File.join(root, 'config'))
21
+ File.open(File.join(root, 'config', 'version.txt'), 'w') do |file|
22
+ file.write('$Id: 055c8729cdcc372500a08db659c045e16c4409fb $')
23
+ end
24
+
25
+ expect(subject.find).to eq('055c8729cdcc372500a08db659c045e16c4409fb')
26
+ end
27
+ end
28
+
29
+ it 'uses the git repo if one is found' do
30
+ expect(subject.find).to eq(`git rev-parse HEAD`)
31
+ end
32
+ end
33
+
@@ -0,0 +1,12 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+
4
+ class Rails
5
+ class << self
6
+ attr_accessor :root
7
+ end
8
+ end
9
+
10
+ RSpec.configure do |config|
11
+ end
12
+
metadata CHANGED
@@ -1,27 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-version
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
5
- prerelease:
4
+ version: 0.0.3
6
5
  platform: ruby
7
6
  authors:
8
7
  - Darrin Holst
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-01-04 00:00:00.000000000Z
11
+ date: 2014-03-15 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
- name: grit
16
- requirement: &70345732445180 !ruby/object:Gem::Requirement
17
- none: false
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
- type: :runtime
20
+ type: :development
23
21
  prerelease: false
24
- version_requirements: *70345732445180
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
25
27
  description: Add current git commit hash as a rails endpoint bound to /version
26
28
  email:
27
29
  - darrinholst@gmail.com
@@ -29,44 +31,46 @@ executables: []
29
31
  extensions: []
30
32
  extra_rdoc_files: []
31
33
  files:
32
- - .gitignore
34
+ - ".gitignore"
35
+ - ".rspec"
33
36
  - Gemfile
34
37
  - LICENSE
35
38
  - README.md
36
39
  - Rakefile
37
40
  - config/routes.rb
38
41
  - git-version.gemspec
42
+ - lib/generators/git_version/install/install_generator.rb
43
+ - lib/generators/git_version/install/templates/config/version.txt
44
+ - lib/generators/git_version/install/templates/gitattributes
39
45
  - lib/git-version.rb
40
46
  - lib/git-version/engine.rb
47
+ - lib/git-version/finder.rb
41
48
  - lib/git-version/version.rb
49
+ - spec/git-version/finder_spec.rb
50
+ - spec/spec_helper.rb
42
51
  homepage: ''
43
52
  licenses: []
53
+ metadata: {}
44
54
  post_install_message:
45
55
  rdoc_options: []
46
56
  require_paths:
47
57
  - lib
48
58
  required_ruby_version: !ruby/object:Gem::Requirement
49
- none: false
50
59
  requirements:
51
- - - ! '>='
60
+ - - ">="
52
61
  - !ruby/object:Gem::Version
53
62
  version: '0'
54
- segments:
55
- - 0
56
- hash: 55499764461789626
57
63
  required_rubygems_version: !ruby/object:Gem::Requirement
58
- none: false
59
64
  requirements:
60
- - - ! '>='
65
+ - - ">="
61
66
  - !ruby/object:Gem::Version
62
67
  version: '0'
63
- segments:
64
- - 0
65
- hash: 55499764461789626
66
68
  requirements: []
67
69
  rubyforge_project: git-version
68
- rubygems_version: 1.8.10
70
+ rubygems_version: 2.2.2
69
71
  signing_key:
70
- specification_version: 3
72
+ specification_version: 4
71
73
  summary: Add current git commit as a rails endpoint
72
- test_files: []
74
+ test_files:
75
+ - spec/git-version/finder_spec.rb
76
+ - spec/spec_helper.rb