versionate 0.1.0

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: e31d4b61429a3510f9670c7fac0867ba74174a3c
4
+ data.tar.gz: 1b41cf0a17ae9ab03eaba0fce88e3a0a69421904
5
+ SHA512:
6
+ metadata.gz: 1aaaf9ed9a1ab60625a880849fc1d34ddcee77305fc22d01cf8787a8515678391e130ca40f1db1c0f26de287044ead3f631dd4c2625b62e85229ac885c0e72b2
7
+ data.tar.gz: 288d298676254781fe08350bb7a4d971567422c2ee243a811214307a81a164f9aa73e2dbb18c0ca3d80acceb6ed852b005227dce5dfcaff61c507ed0789b2107
@@ -0,0 +1,23 @@
1
+ # Versionate
2
+
3
+ ## Installation
4
+
5
+ ```bash
6
+ $ gem install versionate
7
+ ```
8
+
9
+ ## Usage
10
+
11
+ Run the following command in a directory that has a Gemfile, and it will
12
+ automatically lock it to the latest version of that gem.
13
+
14
+ ```bash
15
+ $ versionate
16
+ ```
17
+
18
+ If, for some odd reason, your Gemfile is called something other than “Gemfile”,
19
+ you can specify the name as an argument to the command, like this:
20
+
21
+ ```bash
22
+ $ versionate file_with_gems.rb
23
+ ```
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,9 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require "versionate"
4
+
5
+ if ARGV.any?
6
+ Versionate.versionate ARGV.first
7
+ else
8
+ Versionate.versionate
9
+ end
@@ -0,0 +1,30 @@
1
+ require "versionate/version"
2
+ require "versionate/api_adapter"
3
+ require "versionate/configuration"
4
+ require "versionate/versioner"
5
+
6
+ module Versionate
7
+
8
+ class << self
9
+
10
+ def versionate gemfile = "Gemfile"
11
+ versioner.versionate gemfile
12
+ end
13
+
14
+ def configure
15
+ yield config if block_given?
16
+ end
17
+
18
+ def config
19
+ @config ||= Versionate::Configuration.new
20
+ end
21
+
22
+ private
23
+
24
+ def versioner
25
+ @versioner ||= Versionate::Versioner.new
26
+ end
27
+
28
+ end
29
+
30
+ end
@@ -0,0 +1,14 @@
1
+ require 'gems'
2
+
3
+ module Versionate
4
+ class ApiAdapter
5
+ def provider
6
+ case Versionate.config.environment
7
+ when :test
8
+ GemsMock
9
+ when :production
10
+ ::Gems
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ module Versionate
2
+ class Configuration
3
+ attr_accessor :environment
4
+
5
+ def initialize
6
+ @environment = :production
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module Versionate
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,56 @@
1
+ module Versionate
2
+ class Versioner
3
+ GEM_REGEXP = /^\s*gem ['"](?<name>.+?)['"](?<extra>,.+$?)?/
4
+
5
+ def versionate(filename)
6
+ result = process filename
7
+
8
+ File.open filename, "w" do |file|
9
+ file.write result
10
+ end
11
+ end
12
+
13
+ def latest_version_for(gem_name)
14
+ provider.info(gem_name.to_sym)["version"]
15
+ end
16
+
17
+ def process(filename)
18
+ orig_file = File.open(filename)
19
+ tmp = StringIO.new
20
+
21
+ orig_file.each do |line|
22
+ gem_name = gem_and_only_gem_from_line line
23
+
24
+ if gem_name
25
+ version = latest_version_for gem_name
26
+ tmp.puts "#{line.chomp}, '#{version}'"
27
+ else
28
+ tmp.puts line
29
+ end
30
+ end
31
+
32
+ orig_file.close
33
+
34
+ tmp.rewind
35
+ result = tmp.read
36
+
37
+ tmp.close
38
+
39
+ result
40
+ end
41
+
42
+ def gem_and_only_gem_from_line(line)
43
+ match = line.match GEM_REGEXP
44
+ return nil unless match
45
+ return nil if match[:extra]
46
+
47
+ match[:name]
48
+ end
49
+
50
+ private
51
+
52
+ def provider
53
+ @provider ||= ApiAdapter.new.provider
54
+ end
55
+ end
56
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: versionate
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sindre Moen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gems
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: coveralls
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.1'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.1'
83
+ description: Appends versions to your Gemfile's gem listings
84
+ email:
85
+ - sindrenm@gmail.com
86
+ executables:
87
+ - versionate
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - README.md
92
+ - Rakefile
93
+ - bin/versionate
94
+ - lib/versionate.rb
95
+ - lib/versionate/api_adapter.rb
96
+ - lib/versionate/configuration.rb
97
+ - lib/versionate/version.rb
98
+ - lib/versionate/versioner.rb
99
+ homepage: https://github.com/sindrenm/versionate
100
+ licenses:
101
+ - MIT
102
+ metadata: {}
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 2.2.2
120
+ signing_key:
121
+ specification_version: 4
122
+ summary: Appends versions to your Gemfile's gem listings
123
+ test_files: []