fedux_org-stdlib 0.1.3 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -5,6 +5,7 @@ gemspec
5
5
  gem 'launchy'
6
6
  gem 'command_exec'
7
7
  gem 'taskjuggler'
8
+ gem 'versionomy'
8
9
 
9
10
  group :test do
10
11
  gem 'rake'
@@ -0,0 +1,55 @@
1
+ require 'open3'
2
+
3
+ require 'fedux_org/stdlib/environment'
4
+ require 'fedux_org/stdlib/command/command_result'
5
+
6
+ module FeduxOrg
7
+ module Stdlib
8
+ module Command
9
+ module RunCommand
10
+ include Environment
11
+
12
+ # Execute command
13
+ #
14
+ # @param [String] cmd
15
+ # the command
16
+ #
17
+ # @param [Hash] options
18
+ # the options for command execution
19
+ #
20
+ # @option options [Hash] env ({])
21
+ # the environment variables for the command ('VAR' => 'CONTENT')
22
+ #
23
+ # @option options [String] stdin (nil)
24
+ # the string for stdin of the command
25
+ #
26
+ # @option options [TrueClass,FalseClass] binmode (false)
27
+ # should the stdin be read a binary or not
28
+ #
29
+ # @return [CommandResult]
30
+ # the result of the command execution
31
+ #
32
+ # @return [CommandResult]
33
+ # the result of the command execution
34
+ def run_command(cmd,options={})
35
+ opts = {
36
+ env: nil,
37
+ stdin: nil,
38
+ binmode: false,
39
+ working_directory: Dir.getwd,
40
+ }.merge options
41
+
42
+ env = opts[:env] || ENV.to_hash
43
+ stdin = opts[:stdin]
44
+ binmode = opts[:binmode]
45
+ working_directory = opts[:working_directory]
46
+
47
+ result = CommandResult.new
48
+ result.stdout, result.stderr, result.status = Open3.capture3(env, cmd, stdin_data: stdin, chdir: working_directory, binmode: binmode)
49
+
50
+ result
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,35 @@
1
+ module FeduxOrg
2
+ module Stdlib
3
+ module Command
4
+ module Which
5
+
6
+ # Search for command
7
+ # @param [String] cmd
8
+ # name of command or path to command (will be reduced to basename and then searched in PATH)
9
+ #
10
+ # @param [Array,String] paths
11
+ # a string containing paths separated by "File::PATH_SEPARATOR" or an array of paths
12
+ #
13
+ # @param [Array,String] pathexts
14
+ # a string containing pathexts separated by ";" or an array of pathexts
15
+ #
16
+ # @return [String]
17
+ # path to command
18
+ def which(cmd, paths=ENV['PATH'].split(File::PATH_SEPARATOR), pathexts=ENV['PATHEXT'].to_s.split( /;/ ) )
19
+ return nil if cmd.blank?
20
+
21
+ cmd = File.basename( cmd )
22
+ pathexts = [''] if pathexts.blank?
23
+
24
+ Array( paths ).each do |path|
25
+ Array( pathexts ).each do |ext|
26
+ exe = File.join(path, "#{cmd}#{ext.to_s}")
27
+ return exe if File.executable? exe
28
+ end
29
+ end
30
+ nil
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -1,88 +1,11 @@
1
- begin
2
- require 'active_support/core_ext/string/inflections'
3
- require 'active_support/core_ext/object/blank'
4
- rescue LoadError
5
- $stderr.puts 'You need to install the "activesupport"-gem to make that library work.'
6
- exit 1
7
- end
8
-
9
- require 'open3'
10
-
11
- require 'fedux_org/stdlib/environment'
12
- require 'fedux_org/stdlib/command/command_result'
1
+ require_relative 'command/run_command'
2
+ require_relative 'command/which'
13
3
 
14
4
  module FeduxOrg
15
5
  module Stdlib
16
6
  module Command
17
- include Environment
18
-
19
- # Execute command
20
- #
21
- # @param [String] cmd
22
- # the command
23
- #
24
- # @param [Hash] options
25
- # the options for command execution
26
- #
27
- # @option options [Hash] env ({])
28
- # the environment variables for the command ('VAR' => 'CONTENT')
29
- #
30
- # @option options [String] stdin (nil)
31
- # the string for stdin of the command
32
- #
33
- # @option options [TrueClass,FalseClass] binmode (false)
34
- # should the stdin be read a binary or not
35
- #
36
- # @return [CommandResult]
37
- # the result of the command execution
38
- #
39
- # @return [CommandResult]
40
- # the result of the command execution
41
- def run_command(cmd,options={})
42
- opts = {
43
- env: nil,
44
- stdin: nil,
45
- binmode: false,
46
- working_directory: Dir.getwd,
47
- }.merge options
48
-
49
- env = opts[:env] || ENV.to_hash
50
- stdin = opts[:stdin]
51
- binmode = opts[:binmode]
52
- working_directory = opts[:working_directory]
53
-
54
- result = CommandResult.new
55
- result.stdout, result.stderr, result.status = Open3.capture3(env, cmd, stdin_data: stdin, chdir: working_directory, binmode: binmode)
56
-
57
- result
58
- end
59
-
60
- # Search for command
61
- # @param [String] cmd
62
- # name of command or path to command (will be reduced to basename and then searched in PATH)
63
- #
64
- # @param [Array,String] paths
65
- # a string containing paths separated by "File::PATH_SEPARATOR" or an array of paths
66
- #
67
- # @param [Array,String] pathexts
68
- # a string containing pathexts separated by ";" or an array of pathexts
69
- #
70
- # @return [String]
71
- # path to command
72
- def which(cmd, paths=ENV['PATH'].split(File::PATH_SEPARATOR), pathexts=ENV['PATHEXT'].to_s.split( /;/ ) )
73
- return nil if cmd.blank?
74
-
75
- cmd = File.basename( cmd )
76
- pathexts = [''] if pathexts.blank?
77
-
78
- Array( paths ).each do |path|
79
- Array( pathexts ).each do |ext|
80
- exe = File.join(path, "#{cmd}#{ext.to_s}")
81
- return exe if File.executable? exe
82
- end
83
- end
84
- nil
85
- end
7
+ include RunCommand
8
+ include Which
86
9
  end
87
10
  end
88
11
  end
@@ -1,8 +1,15 @@
1
+ require 'fedux_org/stdlib/command/which'
2
+
3
+ resolver = Class.new do
4
+ include FeduxOrg::Stdlib::Command::Which
5
+ end
6
+
1
7
  namespace :test do
2
8
  desc 'Run tests in "travis mode"'
3
9
  task :travis_specs do
4
10
  ENV['CI'] = 'true'
5
- sh 'rspec spec'
6
- sh 'cucumber -p all'
11
+
12
+ sh 'rspec spec' if resolver.new.which( 'rspec' )
13
+ sh 'cucumber -p all' if resolver.new.which( 'cucumber' )
7
14
  end
8
15
  end
@@ -16,36 +16,59 @@ unless ENV.to_hash.has_key? 'CI'
16
16
  exit 1
17
17
  end
18
18
 
19
+ require 'fedux_org/stdlib/logging/logger'
20
+
19
21
  namespace :version do
20
- desc 'bump version of library to new version'
21
- task :bump do
22
+ @logger = FeduxOrg::Stdlib::Logging::Logger.new
22
23
 
23
- new_version = ENV['VERSION'] || ENV['version']
24
+ def bump_version( type )
25
+ version_update do |file|
26
+ file.bump( type )
27
+ end
28
+ end
24
29
 
25
- raise Exception, "You need to define a version via \"VERSION=<version>\" or \"version=<version>\"." unless new_version
30
+ def version_update( &block )
31
+ file = FeduxOrg::Stdlib::VersionManagement::RubygemVersionFile.read( version_file )
32
+ old_version = file.version
33
+ block.call( file )
34
+ new_version = file.version
35
+
36
+ file.write( version_file )
37
+ @logger.info( "Updated version. It was \"#{old_version}\". It is now \"#{new_version}\"." )
38
+ end
26
39
 
27
- raw_module_names = File.open(version_file, "r").readlines.grep(/module/)
28
- module_names = raw_module_names.collect { |n| n.chomp.match(/module\s+(\S+)/) {$1} }
40
+ desc "Bump x.1.1"
41
+ task :bump_major do
42
+ bump_version( :major )
43
+ end
29
44
 
30
- template = <<-EOF
31
- #main <%= @modules.first %>
32
- <% @modules.each do |m| %>
33
- module <%= m %>
34
- <% end %>
35
- VERSION = '<%= @version %>'
36
- <% @modules.size.times do |m| %>
45
+ desc "Bump 1.x.1"
46
+ task :bump_minor do
47
+ bump_version( :minor )
37
48
  end
38
- <% end %>
39
- EOF
40
49
 
41
- version_string = Erubis::Eruby.new(template).evaluate(modules: module_names, version: new_version)
50
+ desc "Bump 1.1.x"
51
+ task :bump_tiny do
52
+ bump_version( :tiny )
53
+ end
42
54
 
43
- File.open(version_file, "w") do |f|
44
- f.write version_string.strip_heredoc
45
- end
55
+ desc 'bump version of library to new version'
56
+ task :bump do
57
+ new_version = ENV['VERSION'] || ENV['version']
58
+ raise Exception, "You need to define a version via \"VERSION=<version>\" or \"version=<version>\"." unless new_version
46
59
 
47
- sh "git add #{version_file}"
48
- sh "git commit -m 'version bump to #{new_version}'"
60
+ begin
61
+ version_update do |file|
62
+ file.version = new_version
63
+ file.write( version_file )
64
+
65
+ @logger.info( 'Adding new version file to repository.' )
66
+ sh "git add #{version_file}"
67
+ sh "git commit -m 'version bump to #{new_version}'"
68
+ end
69
+ rescue
70
+ @logger.fatal( 'Nothing has changed since your last commit or has been added to the index. Therefor nothing needs to be commited.' )
71
+ end
49
72
  end
50
73
  end
51
74
  end
@@ -1,17 +1,9 @@
1
1
  require_relative 'base'
2
+ require 'fedux_org/stdlib/version_management/rubygem_version_file'
2
3
 
3
4
  namespace :version do
4
5
  desc 'show version of library'
5
6
  task :show do
6
-
7
- raw_version = File.open(version_file, "r").readlines.grep(/VERSION/).first
8
-
9
- if raw_version
10
- version = raw_version.chomp.match(/VERSION\s+=\s+["']([^'"]+)["']/) { $1 }
11
- puts version
12
- else
13
- warn "Could not parse version file \"#{version_file}\""
14
- end
15
-
7
+ $stderr.puts FeduxOrg::Stdlib::VersionManagement::RubygemVersionFile.read( version_file ).version
16
8
  end
17
9
  end
@@ -1,6 +1,6 @@
1
1
  #main FeduxOrg
2
2
  module FeduxOrg
3
- module Stdlib
4
- VERSION = '0.1.3'
5
- end
3
+ module Stdlib
4
+ VERSION = '0.2.1'
5
+ end
6
6
  end
@@ -0,0 +1,15 @@
1
+ require_relative 'ruby_library'
2
+
3
+ module FeduxOrg
4
+ module Stdlib
5
+ module VersionManagement
6
+ class LibraryBuilder
7
+
8
+ def build_from( *args )
9
+ RubyLibrary.new( *args )
10
+ end
11
+
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ module FeduxOrg
2
+ module Stdlib
3
+ module VersionManagement
4
+ class RubyLibrary
5
+
6
+ attr_reader :module_names
7
+
8
+ def initialize( module_names )
9
+ @module_names = module_names
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,90 @@
1
+ begin
2
+ require 'active_support/core_ext/string/strip'
3
+ rescue LoadError
4
+ $stderr.puts 'You need to install the "activesupport"-gem to make that rake task work.'
5
+ exit 1
6
+ end
7
+
8
+ begin
9
+ require 'erubis'
10
+ rescue LoadError
11
+ $stderr.puts 'You need to install the "erubis"-gem to make that rake task work.'
12
+ exit 1
13
+ end
14
+
15
+ require 'forwardable'
16
+
17
+ require_relative 'rubygem_version_file_parser'
18
+ require_relative 'version_builder'
19
+ require_relative 'library_builder'
20
+
21
+ module FeduxOrg
22
+ module Stdlib
23
+ module VersionManagement
24
+
25
+ class RubygemVersionFile
26
+ extend Forwardable
27
+ def_delegators :@version, :bump
28
+
29
+ def initialize( version, library )
30
+ @version = version
31
+ @library = library
32
+ end
33
+
34
+ def version
35
+ @version.to_s
36
+ end
37
+
38
+ def version=(v)
39
+ @version.update( v )
40
+ end
41
+
42
+ def write(path)
43
+ File.write( path, to_s )
44
+ end
45
+
46
+ def self.read( path, parser=RubygemVersionFileParser.new,version_builder=VersionBuilder.new, library_builder=LibraryBuilder.new )
47
+ parser.parse( path )
48
+
49
+ version = version_builder.build_from( parser.version )
50
+ library = library_builder.build_from( parser.modules )
51
+
52
+ RubygemVersionFile.new( version, library )
53
+ end
54
+
55
+ def to_s
56
+ klass = Class.new do
57
+ attr_reader :version, :library
58
+
59
+ def initialize( version, module_names )
60
+ @version = version
61
+ @module_names = module_names
62
+ end
63
+
64
+ def prefix(n)
65
+ ' ' * 2 * n
66
+ end
67
+ end
68
+
69
+ Erubis::Eruby.new(template).evaluate( klass.new( @version, @library.module_names ) )
70
+ end
71
+
72
+ private
73
+
74
+ def template
75
+ <<-EOF.strip_heredoc
76
+ #main <%= @module_names.first %>
77
+ <% @module_names.each_with_index do |m,i| -%>
78
+ <%= prefix( i ) %>module <%= m %>
79
+ <% end -%>
80
+ <%= prefix( @module_names.size ) %>VERSION = '<%= @version %>'
81
+ <% ( @module_names.size - 1 ).downto(0) do |i| -%>
82
+ <%= prefix( i ) %>end
83
+ <% end -%>
84
+ EOF
85
+ end
86
+
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,18 @@
1
+ module FeduxOrg
2
+ module Stdlib
3
+ module VersionManagement
4
+ class RubygemVersionFileParser
5
+
6
+ attr_reader :version, :modules
7
+
8
+ def parse( file )
9
+ data = File.read( file )
10
+
11
+ @version = data.match(/(?:VERSION|Version)\s+=\s+["']([^'"]+)["']/) { $1 }
12
+ @modules = data.scan( /^\s*module\s+([A-Z][A-Za-z0-9]+(?:::[A-Z][A-Z0-9a-z]+)*)$/x ).flatten
13
+ end
14
+
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,33 @@
1
+ begin
2
+ require 'versionomy'
3
+ rescue LoadError
4
+ $stderr.puts 'You need to install the "versionomy"-gem to make that rake task work.'
5
+ exit 1
6
+ end
7
+
8
+ require 'forwardable'
9
+
10
+ module FeduxOrg
11
+ module Stdlib
12
+ module VersionManagement
13
+ class Version
14
+ extend Forwardable
15
+
16
+ def_delegators :@version, :to_s
17
+
18
+ def initialize(version)
19
+ @version = Versionomy.parse( version )
20
+ end
21
+
22
+ def update( *args )
23
+ initialize( *args )
24
+ end
25
+
26
+ def bump(type)
27
+ @version = @version.bump(type)
28
+ end
29
+
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,15 @@
1
+ require_relative 'version'
2
+
3
+ module FeduxOrg
4
+ module Stdlib
5
+ module VersionManagement
6
+ class VersionBuilder
7
+
8
+ def build_from( *args )
9
+ Version.new( *args )
10
+ end
11
+
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ require 'fedux_org/stdlib/command/run_command'
4
+
5
+ describe Command::RunCommand do
6
+
7
+ context '#run_command' do
8
+ klass = Class.new do
9
+ include Command::RunCommand
10
+ end
11
+
12
+ it 'captures stdout' do
13
+ result = klass.new.run_command( 'echo hello_world' )
14
+
15
+ expect( result.stdout.chomp ).to eq( 'hello_world' )
16
+ end
17
+
18
+ it 'captures stderr' do
19
+ result = klass.new.run_command( 'echo hello_world >&2' )
20
+
21
+ expect( result.stderr.chomp ).to eq( 'hello_world' )
22
+ end
23
+
24
+ it 'captures exit status' do
25
+ result = klass.new.run_command( 'echo hello_world >&2' )
26
+
27
+ expect( result.status.exitstatus ).to eq( 0 )
28
+ end
29
+ end
30
+ end
@@ -1,33 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Command do
4
- context '#run_command' do
5
- klass = Class.new do
6
- include Command
7
- end
8
-
9
- it 'captures stdout' do
10
- result = klass.new.run_command( 'echo hello_world' )
11
-
12
- expect( result.stdout.chomp ).to eq( 'hello_world' )
13
- end
14
-
15
- it 'captures stderr' do
16
- result = klass.new.run_command( 'echo hello_world >&2' )
3
+ require 'fedux_org/stdlib/command/which'
17
4
 
18
- expect( result.stderr.chomp ).to eq( 'hello_world' )
19
- end
20
-
21
- it 'captures exit status' do
22
- result = klass.new.run_command( 'echo hello_world >&2' )
23
-
24
- expect( result.status.exitstatus ).to eq( 0 )
25
- end
26
- end
5
+ describe Command::Which do
27
6
 
28
- context '#which', :focus do
7
+ context '#which' do
29
8
  klass = Class.new do
30
- include Command
9
+ include Command::Which
31
10
  end
32
11
 
33
12
  it 'returns full path for a valid command' do
data/spec/spec_helper.rb CHANGED
@@ -1,14 +1,14 @@
1
1
  #encoding: utf-8
2
2
  $LOAD_PATH << File.expand_path( '../../lib', __FILE__ )
3
3
 
4
- unless ENV['TRAVIS_CI'] == 'true'
4
+ unless ENV['CI'] == 'true'
5
5
  require 'pry'
6
6
  require 'debugger'
7
7
  require 'ap'
8
8
  require 'benchmark'
9
9
  end
10
10
 
11
- unless ENV['TRAVIS_CI'] == 'true'
11
+ unless ENV['CI'] == 'true'
12
12
  require 'simplecov'
13
13
  SimpleCov.start
14
14
  SimpleCov.command_name 'rspec'
@@ -43,3 +43,4 @@ RSpec.configure do |c|
43
43
  end
44
44
 
45
45
  require 'active_support/core_ext/kernel/reporting'
46
+ require 'active_support/core_ext/string/strip'
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+ require 'fedux_org/stdlib/version_management/library_builder'
3
+
4
+ describe FeduxOrg::Stdlib::VersionManagement::LibraryBuilder do
5
+ context '#build_from' do
6
+ it 'accepts a version string and builds a version object' do
7
+ library = FeduxOrg::Stdlib::VersionManagement::LibraryBuilder.new.build_from( [ 'MyModules' ] )
8
+ expect( library.module_names ).to eq( [ 'MyModules' ] )
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+ require 'fedux_org/stdlib/version_management/ruby_library'
3
+
4
+ describe FeduxOrg::Stdlib::VersionManagement::RubyLibrary do
5
+ context '#module_names' do
6
+ it 'nows about module names' do
7
+ lib = FeduxOrg::Stdlib::VersionManagement::RubyLibrary.new( ['MyModule', 'MyClass' ] )
8
+ expect( lib.module_names ).to eq( ['MyModule', 'MyClass' ] )
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+ require 'fedux_org/stdlib/version_management/rubygem_version_file_parser'
3
+
4
+ describe FeduxOrg::Stdlib::VersionManagement::RubygemVersionFileParser do
5
+
6
+ let( :parser ) { FeduxOrg::Stdlib::VersionManagement::RubygemVersionFileParser.new }
7
+
8
+ context '#parse' do
9
+ it 'extracts version number' do
10
+ version_file = create_file( 'version.rb', <<-EOS.strip_heredoc
11
+ #main MyLibrary
12
+ module MyLibrary
13
+ VERSION = '0.0.0'
14
+ end
15
+ EOS
16
+ )
17
+
18
+ parser.parse( version_file )
19
+
20
+ expect( parser.version ).to eq( '0.0.0' )
21
+ end
22
+
23
+ it 'extracts modules' do
24
+ version_file = create_file( 'version.rb', <<-EOS.strip_heredoc
25
+ #main MyLibrary
26
+ module MyLibrary
27
+ VERSION = '0.0.0'
28
+ end
29
+ EOS
30
+ )
31
+
32
+ parser.parse( version_file )
33
+
34
+ expect( parser.modules ).to eq( [ 'MyLibrary' ] )
35
+ end
36
+
37
+ it 'extracts nested modules as well' do
38
+ version_file = create_file( 'version.rb', <<-EOS.strip_heredoc
39
+ #main MyLibrary
40
+ module MyLibrary
41
+ module MyClass
42
+ VERSION = '0.0.0'
43
+ end
44
+ end
45
+ EOS
46
+ )
47
+
48
+ parser.parse( version_file )
49
+
50
+ expect( parser.modules ).to eq( [ 'MyLibrary', 'MyClass' ] )
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,117 @@
1
+ require 'spec_helper'
2
+ require 'fedux_org/stdlib/version_management/rubygem_version_file'
3
+
4
+ describe FeduxOrg::Stdlib::VersionManagement::RubygemVersionFile do
5
+
6
+ context '#to_s' do
7
+
8
+ it 'outputs the content for version file' do
9
+ version = double( 'Version' )
10
+ expect(version).to receive( :to_s ).and_return( '0.0.0' )
11
+
12
+ library = double( 'RubyLibrary' )
13
+ expect(library).to receive( :module_names ).and_return( [ 'MyLibrary' ] )
14
+
15
+ version_file = FeduxOrg::Stdlib::VersionManagement::RubygemVersionFile.new( version, library )
16
+ expect( version_file.to_s ).to eq(<<-EOS.strip_heredoc
17
+ #main MyLibrary
18
+ module MyLibrary
19
+ VERSION = '0.0.0'
20
+ end
21
+ EOS
22
+ )
23
+ end
24
+
25
+ it 'outputs the content for version file for a more deeply nested module' do
26
+ version = double( 'Version' )
27
+ expect(version).to receive( :to_s ).and_return( '0.0.0' )
28
+
29
+ library = double( 'RubyLibrary' )
30
+ expect(library).to receive( :module_names ).and_return( [ 'MyLibrary', 'MyClass' ] )
31
+
32
+ version_file = FeduxOrg::Stdlib::VersionManagement::RubygemVersionFile.new( version, library )
33
+ expect( version_file.to_s ).to eq(<<-EOS.strip_heredoc
34
+ #main MyLibrary
35
+ module MyLibrary
36
+ module MyClass
37
+ VERSION = '0.0.0'
38
+ end
39
+ end
40
+ EOS
41
+ )
42
+ end
43
+ end
44
+
45
+ context '#write' do
46
+ it 'writes the generated version file to disk' do
47
+ version = double( 'Version' )
48
+ expect(version).to receive( :to_s ).and_return( '0.0.0' )
49
+
50
+ library = double( 'RubyLibrary' )
51
+ expect(library).to receive( :module_names ).and_return( [ 'MyLibrary', 'MyClass' ] )
52
+ version_file = FeduxOrg::Stdlib::VersionManagement::RubygemVersionFile.new( version, library )
53
+
54
+ switch_to_working_directory do
55
+ version_file.write( 'version.rb' )
56
+ expect( File ).to be_exists( 'version.rb' )
57
+ end
58
+ end
59
+
60
+ context '#read' do
61
+ it 'reads a version file and handover parsing to parser' do
62
+ version = double( 'Version' )
63
+ library = double( 'Library' )
64
+
65
+ version_builder = double( 'VersionBuilder' )
66
+ expect( version_builder ).to receive( :build_from ).with( '0.0.0' ).and_return( version )
67
+
68
+ library_builder = double( 'LibraryBuilder' )
69
+ expect( library_builder ).to receive( :build_from ).with( [ 'MyModule' ] ).and_return( library )
70
+
71
+ parser = double( 'Parser' )
72
+ expect( parser ).to receive( :parse )
73
+ expect( parser ).to receive( :version ).and_return( '0.0.0' )
74
+ expect( parser ).to receive( :modules ).and_return( [ 'MyModule' ] )
75
+
76
+ version_file = create_file( 'version.rb', <<-EOS.strip_heredoc
77
+ #main MyLibrary
78
+ module MyLibrary
79
+ VERSION = '0.0.0'
80
+ end
81
+ EOS
82
+ )
83
+
84
+ result = FeduxOrg::Stdlib::VersionManagement::RubygemVersionFile.read( version_file, parser, version_builder, library_builder )
85
+
86
+ expect( result ).to be_kind_of( FeduxOrg::Stdlib::VersionManagement::RubygemVersionFile )
87
+ end
88
+ end
89
+
90
+ context '#version' do
91
+ it "returns the version for the file" do
92
+ version = double( 'Version' )
93
+ expect(version).to receive( :to_s ).and_return( '0.0.0' )
94
+
95
+ library = double( 'RubyLibrary' )
96
+
97
+ version_file = FeduxOrg::Stdlib::VersionManagement::RubygemVersionFile.new( version, library )
98
+ expect( version_file.version ).to eq('0.0.0' )
99
+ end
100
+ end
101
+
102
+ context '#bump' do
103
+ it "bumps versions" do
104
+ version = double( 'Version' )
105
+ expect(version).to receive( :bump ).with( :major )
106
+ expect(version).to receive( :to_s ).and_return( '1.0.0' )
107
+
108
+ library = double( 'RubyLibrary' )
109
+
110
+ version_file = FeduxOrg::Stdlib::VersionManagement::RubygemVersionFile.new( version, library )
111
+ version_file.bump( :major )
112
+
113
+ expect( version_file.version ).to eq('1.0.0' )
114
+ end
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+ require 'fedux_org/stdlib/version_management/version_builder'
3
+
4
+ describe FeduxOrg::Stdlib::VersionManagement::VersionBuilder do
5
+ context '#build_from' do
6
+ it 'accepts a version string and builds a version object' do
7
+ version = FeduxOrg::Stdlib::VersionManagement::VersionBuilder.new.build_from( '0.0.0' )
8
+ expect( version.to_s ).to eq( '0.0.0' )
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,42 @@
1
+ #https://github.com/dazuma/versionomy
2
+ require 'spec_helper'
3
+ require 'fedux_org/stdlib/version_management/version'
4
+
5
+ describe FeduxOrg::Stdlib::VersionManagement::Version do
6
+ context '#to_s' do
7
+ it 'returns a string representation of version' do
8
+ version = FeduxOrg::Stdlib::VersionManagement::Version.new( '1.1.1' )
9
+ expect( version.to_s ).to eq( '1.1.1' )
10
+ end
11
+ end
12
+
13
+ context '#update' do
14
+ it "updates an with an new version number" do
15
+ version = FeduxOrg::Stdlib::VersionManagement::Version.new( '1.1.1' )
16
+ version.update( '2.0.0' )
17
+ end
18
+ end
19
+
20
+ context '#bump' do
21
+ it 'bumps major version' do
22
+ version = FeduxOrg::Stdlib::VersionManagement::Version.new( '1.1.1' )
23
+ version = version.bump( :major )
24
+
25
+ expect( version.to_s ).to eq( '2.0.0' )
26
+ end
27
+
28
+ it 'bumps minor version' do
29
+ version = FeduxOrg::Stdlib::VersionManagement::Version.new( '1.1.1' )
30
+ version = version.bump( :minor )
31
+
32
+ expect( version.to_s ).to eq( '1.2.0' )
33
+ end
34
+
35
+ it 'bumps tiny version' do
36
+ version = FeduxOrg::Stdlib::VersionManagement::Version.new( '1.1.1' )
37
+ version = version.bump( :tiny )
38
+
39
+ expect( version.to_s ).to eq( '1.1.2' )
40
+ end
41
+ end
42
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fedux_org-stdlib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-22 00:00:00.000000000 Z
12
+ date: 2013-11-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -85,6 +85,8 @@ files:
85
85
  - lib/fedux_org/stdlib/colors/html_color.rb
86
86
  - lib/fedux_org/stdlib/command.rb
87
87
  - lib/fedux_org/stdlib/command/command_result.rb
88
+ - lib/fedux_org/stdlib/command/run_command.rb
89
+ - lib/fedux_org/stdlib/command/which.rb
88
90
  - lib/fedux_org/stdlib/environment.rb
89
91
  - lib/fedux_org/stdlib/filesystem.rb
90
92
  - lib/fedux_org/stdlib/filesystem/exceptions.rb
@@ -131,12 +133,19 @@ files:
131
133
  - lib/fedux_org/stdlib/rake/version/show.rb
132
134
  - lib/fedux_org/stdlib/rake/version/show_shortcut.rb
133
135
  - lib/fedux_org/stdlib/version.rb
136
+ - lib/fedux_org/stdlib/version_management/library_builder.rb
137
+ - lib/fedux_org/stdlib/version_management/ruby_library.rb
138
+ - lib/fedux_org/stdlib/version_management/rubygem_version_file.rb
139
+ - lib/fedux_org/stdlib/version_management/rubygem_version_file_parser.rb
140
+ - lib/fedux_org/stdlib/version_management/version.rb
141
+ - lib/fedux_org/stdlib/version_management/version_builder.rb
134
142
  - rakefiles/default.rake
135
143
  - rakefiles/travis.rake
136
144
  - script/console
137
145
  - script/terminal
138
146
  - spec/colors/html_color_spec.rb
139
- - spec/command_spec.rb
147
+ - spec/command/run_command_spec.rb
148
+ - spec/command/which_spec.rb
140
149
  - spec/environment_spec.rb
141
150
  - spec/examples/models/class_based/forbidden_keyword.rb
142
151
  - spec/examples/models/class_based/ignore/ignored.rb
@@ -162,6 +171,12 @@ files:
162
171
  - spec/project/report_spec.rb
163
172
  - spec/project/taskjuggler_spec.rb
164
173
  - spec/spec_helper.rb
174
+ - spec/version_management/library_builder_spec.rb
175
+ - spec/version_management/ruby_library_spec.rb
176
+ - spec/version_management/rubygem_version_file_parser_spec.rb
177
+ - spec/version_management/rubygem_version_file_spec.rb
178
+ - spec/version_management/version_builder_spec.rb
179
+ - spec/version_management/version_spec.rb
165
180
  homepage: ''
166
181
  licenses:
167
182
  - MIT
@@ -175,12 +190,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
175
190
  - - ! '>='
176
191
  - !ruby/object:Gem::Version
177
192
  version: '0'
193
+ segments:
194
+ - 0
195
+ hash: 2589077551573371235
178
196
  required_rubygems_version: !ruby/object:Gem::Requirement
179
197
  none: false
180
198
  requirements:
181
199
  - - ! '>='
182
200
  - !ruby/object:Gem::Version
183
201
  version: '0'
202
+ segments:
203
+ - 0
204
+ hash: 2589077551573371235
184
205
  requirements: []
185
206
  rubyforge_project:
186
207
  rubygems_version: 1.8.23
@@ -189,7 +210,8 @@ specification_version: 3
189
210
  summary: collection of useful libraries
190
211
  test_files:
191
212
  - spec/colors/html_color_spec.rb
192
- - spec/command_spec.rb
213
+ - spec/command/run_command_spec.rb
214
+ - spec/command/which_spec.rb
193
215
  - spec/environment_spec.rb
194
216
  - spec/examples/models/class_based/forbidden_keyword.rb
195
217
  - spec/examples/models/class_based/ignore/ignored.rb
@@ -215,4 +237,10 @@ test_files:
215
237
  - spec/project/report_spec.rb
216
238
  - spec/project/taskjuggler_spec.rb
217
239
  - spec/spec_helper.rb
240
+ - spec/version_management/library_builder_spec.rb
241
+ - spec/version_management/ruby_library_spec.rb
242
+ - spec/version_management/rubygem_version_file_parser_spec.rb
243
+ - spec/version_management/rubygem_version_file_spec.rb
244
+ - spec/version_management/version_builder_spec.rb
245
+ - spec/version_management/version_spec.rb
218
246
  has_rdoc: