fedux_org-stdlib 0.0.33 → 0.0.35
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/Gemfile +3 -0
- data/lib/fedux_org/stdlib.rb +5 -1
- data/lib/fedux_org/stdlib/environment.rb +14 -12
- data/lib/fedux_org/stdlib/project.rb +5 -0
- data/lib/fedux_org/stdlib/project/generators/taskjuggler.rb +28 -0
- data/lib/fedux_org/stdlib/project/logger.rb +13 -0
- data/lib/fedux_org/stdlib/project/plan.rb +15 -0
- data/lib/fedux_org/stdlib/project/report.rb +67 -0
- data/lib/fedux_org/stdlib/rake/project.rb +18 -0
- data/lib/fedux_org/stdlib/version.rb +1 -1
- data/spec/environment_spec.rb +59 -0
- data/spec/project/plan_spec.rb +5 -0
- data/spec/project/report_spec.rb +68 -0
- data/spec/project/taskjuggler_spec.rb +5 -0
- data/spec/spec_helper.rb +14 -0
- metadata +16 -2
data/Gemfile
CHANGED
data/lib/fedux_org/stdlib.rb
CHANGED
@@ -4,25 +4,27 @@ module FeduxOrg
|
|
4
4
|
|
5
5
|
# Set environment variable for code block
|
6
6
|
#
|
7
|
-
# @param [Hash]
|
7
|
+
# @param [Hash] new_environment_variables
|
8
8
|
# the variables which should be set for that environment
|
9
9
|
#
|
10
|
+
# @param [Hash] options
|
11
|
+
# options for environment manipulation
|
12
|
+
#
|
13
|
+
# @option options [True,False] :clear
|
14
|
+
# Should the environment clear before merge?
|
15
|
+
#
|
10
16
|
# @yield
|
11
17
|
# the block which should be run which the change environment
|
12
|
-
def isolated_environment(
|
13
|
-
|
14
|
-
old_env = ENV.to_hash
|
15
|
-
#change env
|
16
|
-
ENV.update variables
|
18
|
+
def isolated_environment(new_environment_variables, options={}, &block)
|
19
|
+
old_environment = ENV.to_hash
|
17
20
|
|
18
|
-
|
21
|
+
ENV.clear if options[:clear] == true
|
22
|
+
ENV.update new_environment_variables
|
19
23
|
|
20
|
-
|
24
|
+
block.call
|
25
|
+
ensure
|
21
26
|
ENV.clear
|
22
|
-
|
23
|
-
ENV.update old_env
|
24
|
-
|
25
|
-
block_result
|
27
|
+
ENV.update old_environment
|
26
28
|
end
|
27
29
|
end
|
28
30
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'fedux_org/stdlib/logging/logger'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'command_exec'
|
5
|
+
rescue LoadError => e
|
6
|
+
$stderr.puts "You need to install the following gems to make it work: \"command_exec\"."
|
7
|
+
exit 1
|
8
|
+
end
|
9
|
+
|
10
|
+
module FeduxOrg
|
11
|
+
module Stdlib
|
12
|
+
module Project
|
13
|
+
module Generators
|
14
|
+
|
15
|
+
class Taskjuggler
|
16
|
+
def generate_report( directory, plan_file )
|
17
|
+
FeduxOrg::Stdlib::Project.logger.debug "Start generating report."
|
18
|
+
CommandExec::Command.new( :tj3 , :parameter => "-o #{directory} #{plan_file}" ).run
|
19
|
+
FeduxOrg::Stdlib::Project.logger.info "Generating report succeeded."
|
20
|
+
rescue Exception => e
|
21
|
+
FeduxOrg::Stdlib::Project.logger.fatal "Generating report failed. Maybe you forgot to install \"the taskjuggler\"-gem or it is not available in PATH? The error message was: #{e.message}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'fedux_org/stdlib/logging/logger'
|
2
|
+
require 'fedux_org/stdlib/project/logger'
|
3
|
+
require 'fedux_org/stdlib/project/generators/taskjuggler'
|
4
|
+
|
5
|
+
require 'fileutils'
|
6
|
+
|
7
|
+
begin
|
8
|
+
require 'launchy'
|
9
|
+
rescue LoadError => e
|
10
|
+
$stderr.puts "You need to install the following gems to make it work: \"launchy\"."
|
11
|
+
exit 1
|
12
|
+
end
|
13
|
+
|
14
|
+
module FeduxOrg
|
15
|
+
module Stdlib
|
16
|
+
module Project
|
17
|
+
|
18
|
+
class Report
|
19
|
+
attr_reader :directory, :file
|
20
|
+
|
21
|
+
def initialize( plan, generator = FeduxOrg::Stdlib::Project::Generators::Taskjuggler.new,
|
22
|
+
output_directory = File.join( Dir.getwd, 'reports' ),
|
23
|
+
output_file = nil
|
24
|
+
)
|
25
|
+
@plan = plan
|
26
|
+
@output_directory = output_directory
|
27
|
+
@output_file = case output_file
|
28
|
+
when nil
|
29
|
+
File.join( @output_directory, 'Overview.html' )
|
30
|
+
else
|
31
|
+
output_file
|
32
|
+
end
|
33
|
+
@generator = generator
|
34
|
+
end
|
35
|
+
|
36
|
+
def generate
|
37
|
+
prepare_environment
|
38
|
+
|
39
|
+
if output_file_exists? and plan_is_newer_than_output_file?
|
40
|
+
FeduxOrg::Stdlib::Project.logger.warn "No need to re-generate report. The plan file \"#{@plan.file}\" is NOT newer than output \"#{@output_file}\"."
|
41
|
+
else
|
42
|
+
@generator.generate_report( @output_directory, @plan.file )
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def open
|
47
|
+
Launchy.open( @output_file )
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def prepare_environment
|
53
|
+
FileUtils.mkdir_p @output_directory
|
54
|
+
end
|
55
|
+
|
56
|
+
def output_file_exists?
|
57
|
+
File.exists? @output_file
|
58
|
+
end
|
59
|
+
|
60
|
+
def plan_is_newer_than_output_file?
|
61
|
+
File.mtime( @output_file ) > File.mtime( @plan.file)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'fedux_org/stdlib/project'
|
2
|
+
|
3
|
+
namespace :report do
|
4
|
+
|
5
|
+
plan = FeduxOrg::Stdlib::Project::Plan.new
|
6
|
+
report = FeduxOrg::Stdlib::Project::Report.new( plan )
|
7
|
+
|
8
|
+
desc "Generate report"
|
9
|
+
task :generate do
|
10
|
+
report.generate
|
11
|
+
end
|
12
|
+
|
13
|
+
desc "Show report"
|
14
|
+
task :show => :generate do
|
15
|
+
report.open
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FeduxOrg::Stdlib::Environment do
|
4
|
+
context '#isolated_environment' do
|
5
|
+
it 'runs command in isolated environment' do
|
6
|
+
klass = Class.new do
|
7
|
+
include FeduxOrg::Stdlib::Environment
|
8
|
+
|
9
|
+
def test_env
|
10
|
+
isolated_environment 'TEST_VAR' => 'this is a test' do
|
11
|
+
ENV['TEST_VAR']
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
expect( klass.new.test_env ).to eq( 'this is a test' )
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'let you define an environment before running a command' do
|
20
|
+
klass = Class.new do
|
21
|
+
include FeduxOrg::Stdlib::Environment
|
22
|
+
|
23
|
+
def test_env
|
24
|
+
isolated_environment( {}, { clear: true } ) do
|
25
|
+
|
26
|
+
#are set by the terminal and can hardly be cleared
|
27
|
+
ENV.delete( 'COLUMNS' )
|
28
|
+
ENV.delete( 'LINES' )
|
29
|
+
|
30
|
+
ENV.to_hash
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
expect( klass.new.test_env ).to eq( {} )
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'restores environment although an exception occured' do
|
39
|
+
klass = Class.new do
|
40
|
+
include FeduxOrg::Stdlib::Environment
|
41
|
+
|
42
|
+
def test_env
|
43
|
+
ENV['TEST_VAR'] = 'TEST'
|
44
|
+
|
45
|
+
begin
|
46
|
+
isolated_environment( {}, { clear: true } ) do
|
47
|
+
raise
|
48
|
+
end
|
49
|
+
rescue
|
50
|
+
end
|
51
|
+
|
52
|
+
ENV['TEST_VAR']
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
expect( klass.new.test_env ).to eq( 'TEST' )
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fedux_org/stdlib/project/report'
|
3
|
+
require 'fedux_org/stdlib/filesystem'
|
4
|
+
|
5
|
+
describe FeduxOrg::Stdlib::Project::Report do
|
6
|
+
context '#generate' do
|
7
|
+
|
8
|
+
it 'generates report' do
|
9
|
+
plan = double( 'Plan' )
|
10
|
+
allow( plan ).to receive( :file ).and_return { create_file( 'plan.tjp' ) }
|
11
|
+
|
12
|
+
generator = double( 'Generator' )
|
13
|
+
expect( generator ).to receive( :generate_report )
|
14
|
+
|
15
|
+
report = FeduxOrg::Stdlib::Project::Report.new( plan, generator )
|
16
|
+
report.generate
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'generates report only if plan file is newer than output file' do
|
20
|
+
plan_file = create_file( 'plan.tjp' )
|
21
|
+
report_file = create_file( 'reports/Overview.html' )
|
22
|
+
|
23
|
+
FileUtils.touch report_file, :mtime => Time.now - 2.hours
|
24
|
+
|
25
|
+
plan = double( 'Plan' )
|
26
|
+
allow( plan ).to receive( :file ).and_return {plan_file }
|
27
|
+
|
28
|
+
generator = double( 'Generator' )
|
29
|
+
expect( generator ).to receive( :generate_report ).once
|
30
|
+
|
31
|
+
switch_to_working_directory do
|
32
|
+
report = FeduxOrg::Stdlib::Project::Report.new( plan, generator )
|
33
|
+
report.generate
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'does not generate report if plan file is older or of eqal age than output file' do
|
38
|
+
plan_file = create_file( 'plan.tjp' )
|
39
|
+
report_file = create_file( 'reports/Overview.html' )
|
40
|
+
|
41
|
+
FileUtils.touch plan_file, :mtime => Time.now - 2.hours
|
42
|
+
|
43
|
+
plan = double( 'Plan' )
|
44
|
+
allow( plan ).to receive( :file ).and_return { plan_file }
|
45
|
+
|
46
|
+
generator = double( 'Generator' )
|
47
|
+
|
48
|
+
switch_to_working_directory do
|
49
|
+
report = FeduxOrg::Stdlib::Project::Report.new( plan, generator )
|
50
|
+
silence( :stderr ) do
|
51
|
+
report.generate
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context '#open' do
|
58
|
+
it 'can open a report in a browser' do
|
59
|
+
plan = double( 'Plan' )
|
60
|
+
generator = double( 'Generator' )
|
61
|
+
report = FeduxOrg::Stdlib::Project::Report.new( plan, generator )
|
62
|
+
|
63
|
+
expect(
|
64
|
+
report.respond_to? :open
|
65
|
+
).to be_true
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -27,4 +27,18 @@ def examples_dir
|
|
27
27
|
File.expand_path( '../examples', __FILE__ )
|
28
28
|
end
|
29
29
|
|
30
|
+
|
31
|
+
require 'fedux_org/stdlib/filesystem'
|
32
|
+
include FeduxOrg::Stdlib::Filesystem
|
33
|
+
|
34
|
+
def root_directory
|
35
|
+
FeduxOrg::Stdlib.root_directory
|
36
|
+
end
|
37
|
+
|
38
|
+
RSpec.configure do |c|
|
39
|
+
c.before( :each ) do
|
40
|
+
cleanup_working_directory
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
30
44
|
require 'active_support/core_ext/kernel/reporting'
|
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.0.
|
4
|
+
version: 0.0.35
|
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-
|
12
|
+
date: 2013-11-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -102,6 +102,11 @@ files:
|
|
102
102
|
- lib/fedux_org/stdlib/models/class_based_model.rb
|
103
103
|
- lib/fedux_org/stdlib/models/exceptions.rb
|
104
104
|
- lib/fedux_org/stdlib/models/filesystem_based_model.rb
|
105
|
+
- lib/fedux_org/stdlib/project.rb
|
106
|
+
- lib/fedux_org/stdlib/project/generators/taskjuggler.rb
|
107
|
+
- lib/fedux_org/stdlib/project/logger.rb
|
108
|
+
- lib/fedux_org/stdlib/project/plan.rb
|
109
|
+
- lib/fedux_org/stdlib/project/report.rb
|
105
110
|
- lib/fedux_org/stdlib/rake.rb
|
106
111
|
- lib/fedux_org/stdlib/rake/console.rb
|
107
112
|
- lib/fedux_org/stdlib/rake/documentation.rb
|
@@ -110,6 +115,7 @@ files:
|
|
110
115
|
- lib/fedux_org/stdlib/rake/gems/bundler.rb
|
111
116
|
- lib/fedux_org/stdlib/rake/gems/package.rb
|
112
117
|
- lib/fedux_org/stdlib/rake/library.rb
|
118
|
+
- lib/fedux_org/stdlib/rake/project.rb
|
113
119
|
- lib/fedux_org/stdlib/rake/terminal.rb
|
114
120
|
- lib/fedux_org/stdlib/rake/tests.rb
|
115
121
|
- lib/fedux_org/stdlib/rake/tests/cucumber.rb
|
@@ -129,6 +135,7 @@ files:
|
|
129
135
|
- script/terminal
|
130
136
|
- spec/colors/html_color_spec.rb
|
131
137
|
- spec/command_spec.rb
|
138
|
+
- spec/environment_spec.rb
|
132
139
|
- spec/examples/models/class_based/forbidden_keyword.rb
|
133
140
|
- spec/examples/models/class_based/ignore/ignored.rb
|
134
141
|
- spec/examples/models/class_based/ignore/valid_1.rb
|
@@ -147,6 +154,9 @@ files:
|
|
147
154
|
- spec/models/base_model_spec.rb
|
148
155
|
- spec/models/class_based_model_spec.rb
|
149
156
|
- spec/models/filesystem_based_model_spec.rb
|
157
|
+
- spec/project/plan_spec.rb
|
158
|
+
- spec/project/report_spec.rb
|
159
|
+
- spec/project/taskjuggler_spec.rb
|
150
160
|
- spec/spec_helper.rb
|
151
161
|
homepage: ''
|
152
162
|
licenses:
|
@@ -176,6 +186,7 @@ summary: collection of useful libraries
|
|
176
186
|
test_files:
|
177
187
|
- spec/colors/html_color_spec.rb
|
178
188
|
- spec/command_spec.rb
|
189
|
+
- spec/environment_spec.rb
|
179
190
|
- spec/examples/models/class_based/forbidden_keyword.rb
|
180
191
|
- spec/examples/models/class_based/ignore/ignored.rb
|
181
192
|
- spec/examples/models/class_based/ignore/valid_1.rb
|
@@ -194,5 +205,8 @@ test_files:
|
|
194
205
|
- spec/models/base_model_spec.rb
|
195
206
|
- spec/models/class_based_model_spec.rb
|
196
207
|
- spec/models/filesystem_based_model_spec.rb
|
208
|
+
- spec/project/plan_spec.rb
|
209
|
+
- spec/project/report_spec.rb
|
210
|
+
- spec/project/taskjuggler_spec.rb
|
197
211
|
- spec/spec_helper.rb
|
198
212
|
has_rdoc:
|