version_reader 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ /pkg
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color --format doc
data/.rvmrc ADDED
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
7
+ # Only full ruby name is supported here, for short names use:
8
+ # echo "rvm use 1.9.3" > .rvmrc
9
+ environment_id="ruby-1.9.3-p194@version-reader"
10
+
11
+ # Uncomment the following lines if you want to verify rvm version per project
12
+ # rvmrc_rvm_version="1.13.4 (stable)" # 1.10.1 seams as a safe start
13
+ # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14
+ # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15
+ # return 1
16
+ # }
17
+
18
+ # First we attempt to load the desired environment directly from the environment
19
+ # file. This is very fast and efficient compared to running through the entire
20
+ # CLI and selector. If you want feedback on which environment was used then
21
+ # insert the word 'use' after --create as this triggers verbose mode.
22
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
23
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
24
+ then
25
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
26
+ [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
27
+ \. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
28
+ if [[ $- == *i* ]] # check for interactive shells
29
+ then echo "Using: $(tput setaf 2)$GEM_HOME$(tput sgr0)" # show the user the ruby and gemset they are using in green
30
+ else echo "Using: $GEM_HOME" # don't use colors in non-interactive shells
31
+ fi
32
+ else
33
+ # If the environment file has not yet been created, use the RVM CLI to select.
34
+ rvm --create use "$environment_id" || {
35
+ echo "Failed to create RVM environment '${environment_id}'."
36
+ return 1
37
+ }
38
+ fi
39
+
40
+ # If you use bundler, this might be useful to you:
41
+ # if [[ -s Gemfile ]] && {
42
+ # ! builtin command -v bundle >/dev/null ||
43
+ # builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
44
+ # }
45
+ # then
46
+ # printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
47
+ # gem install bundler
48
+ # fi
49
+ # if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
50
+ # then
51
+ # bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
52
+ # fi
data/.watchr ADDED
@@ -0,0 +1,18 @@
1
+ def run_spec(file)
2
+ unless File.exist?(file)
3
+ puts "#{file} does not exist"
4
+ return
5
+ end
6
+
7
+ puts "Running #{file}"
8
+ system "rspec #{file}"
9
+ puts
10
+ end
11
+
12
+ watch("spec/.*/*_spec.rb") do |match|
13
+ run_spec match[0]
14
+ end
15
+
16
+ watch("lib/(.*/?.*)\.rb") do |match|
17
+ run_spec %{spec/#{match[1]}_spec.rb}
18
+ end
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,28 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ version_reader (0.0.1)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.1.3)
10
+ rspec (2.11.0)
11
+ rspec-core (~> 2.11.0)
12
+ rspec-expectations (~> 2.11.0)
13
+ rspec-mocks (~> 2.11.0)
14
+ rspec-core (2.11.0)
15
+ rspec-expectations (2.11.1)
16
+ diff-lcs (~> 1.1.3)
17
+ rspec-mocks (2.11.1)
18
+ version_bumper (0.3.0)
19
+ watchr (0.7)
20
+
21
+ PLATFORMS
22
+ ruby
23
+
24
+ DEPENDENCIES
25
+ rspec
26
+ version_bumper
27
+ version_reader!
28
+ watchr
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # version_reader
2
+
3
+ Small Gem to read your version file.
4
+
5
+ ## Usage
6
+
7
+ Assuming you have a file ~/CoolApp/VERSION with the content of ```0.4.2\n```.
8
+
9
+ ```ruby
10
+ require 'version_reader'
11
+
12
+ version_reader = VersionReader.new('~/CoolApp/VERSION')
13
+ version_reader.normal # 0.4.2
14
+ ```
15
+
16
+ ## Rails integration
17
+
18
+ If you add this gem to your Gemfile of a Rails application it will
19
+ automatically define ```CoolApp::Application.version``` and fill in a VersionReader instance.
20
+
21
+ It will also load some Rails flavor.
22
+
23
+ ## Flavors
24
+
25
+ Flavors are an easy way to extend a VersionReader object with additional informations.
26
+
27
+ ### Rails
28
+
29
+ The Rails flavor adds some additional methods which also show some information about the current Rails-Environment.
30
+
31
+ #### rails_env
32
+
33
+ Always adds the current Rails-Environment to the version. Maybe useful to see whether this is staging or not :)
34
+
35
+ ```ruby
36
+ ruby CoolApp::Application.version.rails_env
37
+ ```
38
+ Output would be ```0.4.2-development```.
39
+
40
+
41
+ #### rails_env_without
42
+
43
+ Adds the current Rails-Environment if it does not match one of the given environments.
44
+
45
+ ```ruby
46
+ CoolApp::Application.version.rails_env_without(:production,:staging)
47
+ ```
48
+
49
+ Output would be ```0.4.2-development``` or ```0.4.2``` for staging and production.
50
+
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'version_bumper'
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,42 @@
1
+ class VersionReader
2
+
3
+ class FileError < RuntimeError; end
4
+
5
+ autoload :Flavor, 'version_reader/flavor'
6
+
7
+ attr_accessor :raise_errors
8
+ attr_accessor :no_version_string
9
+
10
+ def initialize(version_file)
11
+ @version_file = version_file
12
+ @raise_errors = true
13
+ @no_version_string = "Versionfile #{@version_file} not found"
14
+ end
15
+
16
+ def normal
17
+ version
18
+ end
19
+
20
+ private
21
+ def version
22
+ @version ||= read_version.strip
23
+ end
24
+
25
+ def read_version
26
+ File.read(@version_file)
27
+ rescue Errno::ENOENT => @error
28
+ handle_error
29
+ end
30
+
31
+ def handle_error
32
+ if @raise_errors
33
+ raise VersionReader::FileError, @error.to_s
34
+ else
35
+ @no_version_string
36
+ end
37
+ end
38
+
39
+ end
40
+
41
+ require 'version_reader/railtie' if defined?(Rails)
42
+
@@ -0,0 +1,5 @@
1
+ class VersionReader
2
+ module Flavor
3
+ autoload :Rails, 'version_reader/flavor/rails'
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ class VersionReader
2
+ module Flavor
3
+ module Rails
4
+
5
+ attr_writer :env
6
+
7
+ def rails_env
8
+ "#{version}-#{env}"
9
+ end
10
+
11
+ def rails_env_without(*environments)
12
+ if environments.map { |env| env.to_sym }.include?(env)
13
+ version
14
+ else
15
+ rails_env
16
+ end
17
+ end
18
+
19
+ private
20
+ def env
21
+ (@env ||= ::Rails.env).to_sym
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,17 @@
1
+ class VersionReader
2
+ class Railtie < Rails::Railtie
3
+
4
+ initializer "version_reader.add_app_version_variable" do |app|
5
+ app.class.class_eval do
6
+ attr_accessor :version
7
+ end unless app.respond_to?(:version)
8
+ end
9
+
10
+ initializer "version_reader.set_app_version" do |app|
11
+ app.version = VersionReader.new(File.join(::Rails.root, 'VERSION'))
12
+ app.version.extend(VersionReader::Flavor::Rails)
13
+ app.version.raise_errors = false
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+ require 'version_reader'
3
+
4
+ describe VersionReader do
5
+
6
+ subject do
7
+ VersionReader.new(version_file)
8
+ end
9
+
10
+ context "version file exists" do
11
+ let(:version_file) do
12
+ File.expand_path('../../../VERSION', __FILE__)
13
+ end
14
+
15
+ its(:normal) { should =~ /\A\d\.\d\.\d\z/ }
16
+ end
17
+
18
+ context "version file does not exist" do
19
+ let(:version_file) do
20
+ 'this-should-really-not-exist-' + rand.to_s
21
+ end
22
+
23
+ it "railses an VersionReader error" do
24
+ expect { subject.normal }.to raise_error(VersionReader::FileError)
25
+ end
26
+ end
27
+
28
+ end
File without changes
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+ require 'version_reader/flavor/rails'
3
+
4
+ describe VersionReader::Flavor::Rails do
5
+
6
+ subject do
7
+ reader = mock()
8
+ reader.should_receive(:version).and_return('0.4.2')
9
+ reader.extend(VersionReader::Flavor::Rails)
10
+ end
11
+
12
+ [:test, :development, :staging, :production].each do |rails_env|
13
+ it "adds #{rails_env} to the end of the version" do
14
+ subject.env = rails_env
15
+ subject.rails_env.should eq("0.4.2-#{rails_env}")
16
+ end
17
+ end
18
+
19
+ it "does not add the specfied environment to the version" do
20
+ subject.env = :production
21
+ subject.rails_env_without(:production).should eq("0.4.2")
22
+ end
23
+
24
+ it "does not add the specfied environments to the version" do
25
+ subject.env = :production
26
+ subject.rails_env_without(:development, :production, :staging).should eq("0.4.2")
27
+ end
28
+
29
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+ require 'version_reader'
3
+
4
+ describe VersionReader do
5
+
6
+ subject do
7
+ VersionReader.new('VERSION')
8
+ end
9
+
10
+ context "version file exists" do
11
+ before do
12
+ File.should_receive(:read).with('VERSION').and_return("0.4.2\n")
13
+ end
14
+
15
+ its(:normal) { should eq('0.4.2') }
16
+
17
+ end
18
+
19
+ context "version file does not exist" do
20
+ before do
21
+ File.should_receive(:read).with('VERSION').and_raise(Errno::ENOENT)
22
+ end
23
+
24
+ it "raises an VersionReader error" do
25
+ expect { subject.normal }.to raise_error(VersionReader::FileError)
26
+ end
27
+
28
+ it "returns an empty string if error raising has been disabled" do
29
+ subject.raise_errors = false
30
+ subject.normal.should eq('Versionfile VERSION not found')
31
+ end
32
+
33
+ end
34
+
35
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/version_reader', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Raffael Schmid"]
6
+ gem.email = ["raffael@yux.ch"]
7
+ gem.description = %q{Easily read your VERSION file and display it in different formats}
8
+ gem.summary = %q{Reads your VERSION file and gives the ability to display it in an easy way}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "version_reader"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = VersionReader.new(File.expand_path('../VERSION', __FILE__)).normal
17
+
18
+ gem.add_development_dependency 'rspec'
19
+ gem.add_development_dependency 'watchr'
20
+ gem.add_development_dependency 'version_bumper'
21
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: version_reader
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Raffael Schmid
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-14 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
+ - !ruby/object:Gem::Dependency
31
+ name: watchr
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: version_bumper
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Easily read your VERSION file and display it in different formats
63
+ email:
64
+ - raffael@yux.ch
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - .rspec
71
+ - .rvmrc
72
+ - .watchr
73
+ - Gemfile
74
+ - Gemfile.lock
75
+ - README.md
76
+ - Rakefile
77
+ - VERSION
78
+ - lib/version_reader.rb
79
+ - lib/version_reader/flavor.rb
80
+ - lib/version_reader/flavor/rails.rb
81
+ - lib/version_reader/railtie.rb
82
+ - spec/integration/version_reader_spec.rb
83
+ - spec/spec_helper.rb
84
+ - spec/version_reader/flavor/rails_spec.rb
85
+ - spec/version_reader_spec.rb
86
+ - version_reader.gemspec
87
+ homepage: ''
88
+ licenses: []
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 1.8.24
108
+ signing_key:
109
+ specification_version: 3
110
+ summary: Reads your VERSION file and gives the ability to display it in an easy way
111
+ test_files:
112
+ - spec/integration/version_reader_spec.rb
113
+ - spec/spec_helper.rb
114
+ - spec/version_reader/flavor/rails_spec.rb
115
+ - spec/version_reader_spec.rb