fedux_org-stdlib 0.6.5 → 0.6.6
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.
- checksums.yaml +4 -4
- data/lib/fedux_org_stdlib/app_config.rb +105 -55
- data/lib/fedux_org_stdlib/app_config/exceptions.rb +21 -0
- data/lib/fedux_org_stdlib/process_environment.rb +23 -0
- data/lib/fedux_org_stdlib/project/generators/taskjuggler.rb +6 -1
- data/lib/fedux_org_stdlib/project/plan.rb +23 -2
- data/lib/fedux_org_stdlib/project/report.rb +10 -0
- data/lib/fedux_org_stdlib/rake/project_task.rb +25 -0
- data/lib/fedux_org_stdlib/rake/shell_task.rb +15 -1
- data/lib/fedux_org_stdlib/rake/sub_task.rb +10 -1
- data/lib/fedux_org_stdlib/rake/task.rb +44 -3
- data/lib/fedux_org_stdlib/rake/version_bump_task.rb +18 -0
- data/lib/fedux_org_stdlib/version.rb +1 -1
- data/spec/app_config_spec.rb +195 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e1c1b6589229f82b454ee913a23fab92aca494a
|
4
|
+
data.tar.gz: 916a27b4cc5109c456b93db736c2d3b72b6a6006
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1bbd124f791e27d8371887e72979dc1bc7754c28cc884efb0e6a06203c1cfd1e4aafd5b0344df7b31b07eebd1c370fe28387c21c740d7a159e5f27f48a7cd1c
|
7
|
+
data.tar.gz: ea6f1b3636255e4c1ee4c61571ee15da4f24d8b6296623b8063e3b3e3b5bd1854d09dff54bd9e8b9a7282bcb30518b6bc484f64bb6c0d66e8db3a6ee517bde4f
|
@@ -1,32 +1,34 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'fedux_org_stdlib/require_files'
|
3
|
-
|
3
|
+
require 'fedux_org_stdlib/app_config/exceptions'
|
4
|
+
require 'fedux_org_stdlib/process_environment'
|
5
|
+
require 'fedux_org_stdlib/core_ext/array'
|
6
|
+
require_library %w{ json psych active_support/core_ext/string/inflections thread set active_support/hash_with_indifferent_access }
|
4
7
|
|
5
8
|
module FeduxOrgStdlib
|
6
|
-
module Exceptions
|
7
|
-
# One wants to modify a locked config
|
8
|
-
class ConfigLocked < StandardError; end
|
9
|
-
|
10
|
-
# Found config file is not readable
|
11
|
-
class ConfigFileNotReadable < StandardError; end
|
12
|
-
|
13
|
-
# No allowed config file could be found
|
14
|
-
class NoConfigFileFound < StandardError; end
|
15
|
-
end
|
16
|
-
|
17
9
|
# This class makes a config file available as an object. The config file
|
18
10
|
# needs to be `YAML` by default. It is read by `Psych` and converted to a
|
19
11
|
# hash. If you chose to use a different file format: Each config file needs
|
20
12
|
# to translatable to a hash or another data structure which responds to
|
21
|
-
# `[]` by the given `config_engine`.
|
13
|
+
# `[]` by the given `config_engine`. If no suitable config file can be found
|
14
|
+
# the config uses only the defined defaults within the class.
|
22
15
|
#
|
23
16
|
# By default it will look for a suitable config file in the given order:
|
24
17
|
#
|
25
|
-
# 1. $HOME/.config/<application_name>/<config_file
|
26
|
-
# 2. $HOME/.<application_name>/<config_file
|
27
|
-
#
|
18
|
+
# 1. $HOME/.config/<application_name>/<config_file>.yaml
|
19
|
+
# 2. $HOME/.<application_name>/<config_file>.yaml
|
20
|
+
# 2. $HOME/.<config_file>.yaml
|
21
|
+
# 2. $HOME/.<config_file>rc
|
22
|
+
# 3. /etc/.<application_name>/<config_file>.yaml
|
28
23
|
#
|
29
|
-
#
|
24
|
+
# Please keep in mind
|
25
|
+
#
|
26
|
+
# * application_name: Module of your class, e.g. "MyApplication" becomes
|
27
|
+
# "my_application"
|
28
|
+
# * config_file: Pluarized name of your class and "Config" strip
|
29
|
+
# off, e.g "ClientConfig" becomes "clients.yaml" (mind the pluralized name)
|
30
|
+
#
|
31
|
+
# Most conventions defined by me are implemented as separate methods. If one convention
|
30
32
|
# is not suitable for your use case, just overwrite the method.
|
31
33
|
#
|
32
34
|
# If you prefer to use a different path to the config file or name of the
|
@@ -43,31 +45,39 @@ module FeduxOrgStdlib
|
|
43
45
|
#
|
44
46
|
# Below you find some examples for the usage of the class:
|
45
47
|
#
|
46
|
-
# @example Create config
|
48
|
+
# @example Create config with one writer and reader
|
49
|
+
# module MyApplication
|
50
|
+
# class ClientConfig < AppConfig
|
51
|
+
# # 'data1' is the default for option1
|
52
|
+
# # if you create a file
|
53
|
+
# option :option1, 'data1'
|
54
|
+
# end
|
55
|
+
# end
|
47
56
|
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
51
|
-
#
|
57
|
+
# @example Create config with a reader only
|
58
|
+
# module MyApplication
|
59
|
+
# class ClientConfig < AppConfig
|
60
|
+
# # 'data1' is the default for option1
|
61
|
+
# # if you create a file
|
62
|
+
# option_reader :option1, 'data1'
|
63
|
+
# end
|
64
|
+
# end
|
52
65
|
#
|
53
|
-
# @example Config file
|
54
|
-
#
|
55
|
-
#
|
66
|
+
# @example Config yaml file for the classes above: clients.yaml
|
67
|
+
# ---
|
68
|
+
# option1: 'data2'
|
56
69
|
class AppConfig
|
57
|
-
|
58
|
-
# Set all neccessary class instance variables
|
59
|
-
def self.inherited(base)
|
60
|
-
base.instance_variable_set :@options, Set.new
|
61
|
-
base.instance_variable_set :@process_environment, ProcessEnvironment.new
|
62
|
-
end
|
63
|
-
|
64
70
|
class << self
|
65
|
-
|
66
|
-
#
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
+
|
72
|
+
# @api private
|
73
|
+
def options
|
74
|
+
@options ||= Set.new
|
75
|
+
end
|
76
|
+
|
77
|
+
# @api private
|
78
|
+
def process_environment
|
79
|
+
@process_environment ||= ProcessEnvironment.new
|
80
|
+
end
|
71
81
|
|
72
82
|
# Define a reader for option
|
73
83
|
#
|
@@ -81,11 +91,17 @@ module FeduxOrgStdlib
|
|
81
91
|
config.fetch(option.to_sym, default_value)
|
82
92
|
end
|
83
93
|
|
84
|
-
|
94
|
+
self.options << option
|
85
95
|
end
|
86
96
|
|
87
97
|
# Define a writer for option
|
88
98
|
#
|
99
|
+
# Please make sure that you define a reader as well. Otherwise you cannot
|
100
|
+
# access the option. Under normal conditions it does not make sense to
|
101
|
+
# use this method.
|
102
|
+
#
|
103
|
+
# @api private
|
104
|
+
#
|
89
105
|
# @param [Symbol] option
|
90
106
|
# Name of option
|
91
107
|
#
|
@@ -100,7 +116,7 @@ module FeduxOrgStdlib
|
|
100
116
|
end
|
101
117
|
end
|
102
118
|
|
103
|
-
|
119
|
+
self.options << option
|
104
120
|
end
|
105
121
|
|
106
122
|
# Define a writer and a reader for option
|
@@ -118,12 +134,17 @@ module FeduxOrgStdlib
|
|
118
134
|
|
119
135
|
private
|
120
136
|
|
137
|
+
# @!attribute [r] config
|
138
|
+
# Holds the config
|
121
139
|
attr_reader :config
|
122
140
|
|
123
141
|
public
|
124
142
|
|
125
143
|
# Create a new instance of config
|
126
144
|
#
|
145
|
+
# It tries to find a suitable configuration file. If it doesn't find one
|
146
|
+
# the config is empty and uses the defaults defined within a config class
|
147
|
+
#
|
127
148
|
# @param [String] file
|
128
149
|
# Path where config file is stored. The file will be read by the
|
129
150
|
# `config_engine`.
|
@@ -141,23 +162,30 @@ module FeduxOrgStdlib
|
|
141
162
|
# The config instance. If the resulting data structure created by the
|
142
163
|
# config_engine does not respond to `:[]` an empty config object will be
|
143
164
|
# created.
|
144
|
-
def initialize(
|
145
|
-
|
165
|
+
def initialize(
|
166
|
+
file: available_config_file,
|
167
|
+
config_engine: Psych,
|
168
|
+
logger: FeduxOrgStdlib::Logging::Logger.new
|
169
|
+
)
|
170
|
+
@logger = logger
|
146
171
|
|
147
|
-
|
172
|
+
unless file
|
173
|
+
logger.debug "No configuration file found at #{allowed_config_file_paths.to_list}, using an empty config."
|
174
|
+
@config = HashWithIndifferentAccess.new
|
148
175
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
176
|
+
return
|
177
|
+
end
|
178
|
+
|
179
|
+
begin
|
180
|
+
yaml = Psych.load_file(file, safe: true)
|
181
|
+
rescue StandardError => e
|
182
|
+
fail Exceptions::ConfigFileNotReadable, JSON.dump(message: e.message, file: file)
|
155
183
|
end
|
156
184
|
|
157
185
|
if yaml.respond_to? :[]
|
158
|
-
@config = yaml.symbolize_keys
|
186
|
+
@config = HashWithIndifferentAccess.new(yaml.symbolize_keys)
|
159
187
|
else
|
160
|
-
@config =
|
188
|
+
@config = HashWithIndifferentAccess.new
|
161
189
|
end
|
162
190
|
end
|
163
191
|
|
@@ -175,7 +203,7 @@ module FeduxOrgStdlib
|
|
175
203
|
result << sprintf("%20s | %s", 'option', 'value')
|
176
204
|
result << sprintf("%s + %s", '-' * 20, '-' * 80)
|
177
205
|
|
178
|
-
|
206
|
+
self.class.options.each do |o|
|
179
207
|
result << sprintf("%20s | %s", o, Array(public_send(o)).join(', '))
|
180
208
|
end
|
181
209
|
|
@@ -191,7 +219,15 @@ module FeduxOrgStdlib
|
|
191
219
|
# you want to use a different file name you need to overwrite this
|
192
220
|
# method.
|
193
221
|
def config_file
|
194
|
-
"#{config_name}
|
222
|
+
"#{config_name}#{config_file_suffix}"
|
223
|
+
end
|
224
|
+
|
225
|
+
# The suffix of the config file
|
226
|
+
#
|
227
|
+
# @return [String]
|
228
|
+
# The suffix of the config file
|
229
|
+
def config_file_suffix
|
230
|
+
'.yaml'
|
195
231
|
end
|
196
232
|
|
197
233
|
# The base name of the config
|
@@ -206,7 +242,11 @@ module FeduxOrgStdlib
|
|
206
242
|
#
|
207
243
|
# This will result in `client` as base name for the config file.
|
208
244
|
def config_name
|
209
|
-
|
245
|
+
unless (name = class_name.sub(/Config/, '').underscore.pluralize).blank?
|
246
|
+
return name
|
247
|
+
end
|
248
|
+
|
249
|
+
fail Exceptions::ClassNameIsMissing, JSON.dump(klass: class_name)
|
210
250
|
end
|
211
251
|
|
212
252
|
# The name of your application
|
@@ -223,7 +263,7 @@ module FeduxOrgStdlib
|
|
223
263
|
#
|
224
264
|
# my_application
|
225
265
|
def application_name
|
226
|
-
|
266
|
+
module_name.underscore
|
227
267
|
end
|
228
268
|
|
229
269
|
# The paths where to look for the config file
|
@@ -235,11 +275,21 @@ module FeduxOrgStdlib
|
|
235
275
|
[
|
236
276
|
::File.expand_path(::File.join(self.class.process_environment.fetch('HOME'), '.config', application_name, config_file)),
|
237
277
|
::File.expand_path(::File.join(self.class.process_environment.fetch('HOME'), format('.%s', application_name), config_file)),
|
278
|
+
::File.expand_path(::File.join(self.class.process_environment.fetch('HOME'), format('.%s', config_file))),
|
279
|
+
::File.expand_path(::File.join(self.class.process_environment.fetch('HOME'), format('.%src', config_name))),
|
238
280
|
::File.expand_path(::File.join('/etc', application_name, config_file)),
|
239
281
|
# ::File.expand_path("../../../../files/#{config_file}", __FILE__),
|
240
282
|
]
|
241
283
|
end
|
242
284
|
|
285
|
+
def class_name
|
286
|
+
self.class.name.to_s.demodulize
|
287
|
+
end
|
288
|
+
|
289
|
+
def module_name
|
290
|
+
self.class.to_s.deconstantize
|
291
|
+
end
|
292
|
+
|
243
293
|
def available_config_file
|
244
294
|
allowed_config_file_paths.find { |f| ::File.exists? f }
|
245
295
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module FeduxOrgStdlib
|
3
|
+
class AppConfig
|
4
|
+
module Exceptions
|
5
|
+
# One wants to modify a locked config
|
6
|
+
class ConfigLocked < StandardError; end
|
7
|
+
|
8
|
+
# Found config file is not readable
|
9
|
+
class ConfigFileNotReadable < StandardError; end
|
10
|
+
|
11
|
+
# No allowed config file could be found
|
12
|
+
class NoConfigFileFound < StandardError; end
|
13
|
+
|
14
|
+
# If no module is given on class
|
15
|
+
class NamespaceIsMissing < StandardError; end
|
16
|
+
|
17
|
+
# If no class name is present
|
18
|
+
class ClassNameIsMissing < StandardError; end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module FeduxOrgStdlib
|
3
|
+
class ProcessEnvironment
|
4
|
+
private
|
5
|
+
|
6
|
+
attr_reader :environment
|
7
|
+
|
8
|
+
public
|
9
|
+
|
10
|
+
def initialize(environment = ENV)
|
11
|
+
@environment = environment
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
def fetch(key, default_value = nil)
|
16
|
+
environment.to_hash.symbolize_keys.fetch(key.to_sym, default_value).to_s
|
17
|
+
end
|
18
|
+
|
19
|
+
def write(key, value)
|
20
|
+
environment[key.to_s] = value
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -8,6 +8,12 @@ module FeduxOrgStdlib
|
|
8
8
|
module Project
|
9
9
|
module Generators
|
10
10
|
class Taskjuggler
|
11
|
+
# Generate report
|
12
|
+
#
|
13
|
+
# @param [String] directory
|
14
|
+
# The directory where the report should be generated
|
15
|
+
# @param [Plan] plan
|
16
|
+
# The project plan to use
|
11
17
|
def generate_report(directory, plan)
|
12
18
|
FeduxOrgStdlib::Project.logger.debug "Start generating report."
|
13
19
|
|
@@ -29,7 +35,6 @@ module FeduxOrgStdlib
|
|
29
35
|
FeduxOrgStdlib::Project.logger.info "Generating report succeeded."
|
30
36
|
end
|
31
37
|
end
|
32
|
-
|
33
38
|
end
|
34
39
|
end
|
35
40
|
end
|
@@ -5,19 +5,40 @@ module FeduxOrgStdlib
|
|
5
5
|
|
6
6
|
private
|
7
7
|
|
8
|
-
attr_reader :main_file,
|
8
|
+
attr_reader :main_file,
|
9
|
+
:additional_files
|
9
10
|
|
10
11
|
public
|
11
12
|
|
12
|
-
|
13
|
+
# Create a new project plan
|
14
|
+
#
|
15
|
+
# @param [String] main_file
|
16
|
+
# The main project file
|
17
|
+
# @param [Array] additional_files
|
18
|
+
# Additional files containing information about project plan
|
19
|
+
def initialize(
|
20
|
+
main_file: File.join(Dir.getwd, 'plan.tjp'),
|
21
|
+
additional_files: []
|
22
|
+
)
|
13
23
|
@main_file = main_file
|
14
24
|
@additional_files = Array(additional_files)
|
15
25
|
end
|
16
26
|
|
27
|
+
# Does the plan needs to be compiled
|
28
|
+
#
|
29
|
+
# @param [String] base_file
|
30
|
+
# The output file which should be used to determine if the report is
|
31
|
+
# older then the project plan
|
32
|
+
# @return [true,false]
|
33
|
+
# Result of comparism
|
17
34
|
def needs_to_be_compiled?(base_file)
|
18
35
|
(Array(main_file) + additional_files).any? { |f| File.mtime(f) > File.mtime(base_file) }
|
19
36
|
end
|
20
37
|
|
38
|
+
# Output a textual representation of self
|
39
|
+
#
|
40
|
+
# @return [String]
|
41
|
+
# The path to the main file of the project plan
|
21
42
|
def to_s
|
22
43
|
main_file
|
23
44
|
end
|
@@ -19,6 +19,14 @@ module FeduxOrgStdlib
|
|
19
19
|
|
20
20
|
public
|
21
21
|
|
22
|
+
# Create a new report
|
23
|
+
#
|
24
|
+
# @param [Plan] plan
|
25
|
+
# Project plan to be used for report
|
26
|
+
# @param [String] output_file
|
27
|
+
# The main output file for the report
|
28
|
+
# @param [Generator] generator
|
29
|
+
# A generator to be used to be generator the report
|
22
30
|
def initialize(
|
23
31
|
plan:,
|
24
32
|
output_file:,
|
@@ -30,6 +38,7 @@ module FeduxOrgStdlib
|
|
30
38
|
@generator = generator
|
31
39
|
end
|
32
40
|
|
41
|
+
# Generate report
|
33
42
|
def generate
|
34
43
|
prepare_environment
|
35
44
|
|
@@ -40,6 +49,7 @@ module FeduxOrgStdlib
|
|
40
49
|
end
|
41
50
|
end
|
42
51
|
|
52
|
+
# Open report in web browser
|
43
53
|
def open
|
44
54
|
Launchy.open(output_file)
|
45
55
|
end
|
@@ -13,6 +13,31 @@ module FeduxOrgStdlib
|
|
13
13
|
# The report to be generated
|
14
14
|
attr_reader :report
|
15
15
|
|
16
|
+
# Create a new project task
|
17
|
+
#
|
18
|
+
# @param [String] report_file
|
19
|
+
# The main report file
|
20
|
+
# @param [String] plan_file
|
21
|
+
# The main plan file
|
22
|
+
# @param [Array] additional_files
|
23
|
+
# A list of additional files for the project plan
|
24
|
+
#
|
25
|
+
# @example Create new task
|
26
|
+
# FeduxOrgStdlib::Rake::ProjectTask.new
|
27
|
+
#
|
28
|
+
# @example Create new task using a different report file
|
29
|
+
# FeduxOrgStdlib::Rake::ProjectTask.new(
|
30
|
+
# report_file: File.join(Dir.getwd, 'reports', 'Index.html')
|
31
|
+
# )
|
32
|
+
#
|
33
|
+
# @example Create new task using a different project plan and adding additional files
|
34
|
+
# FeduxOrgStdlib::Rake::ProjectTask.new(
|
35
|
+
# plan_file: File.join(Dir.getwd, 'project1.tjp'),
|
36
|
+
# additional_files: %W{
|
37
|
+
# #{File.join(Dir.getwd, 'resources.tjp')}
|
38
|
+
# #{File.join(Dir.getwd, 'leaves.tjp')}
|
39
|
+
# }
|
40
|
+
# )
|
16
41
|
def initialize(
|
17
42
|
report_file: File.join(Dir.getwd, 'reports', 'Overview.html'),
|
18
43
|
plan_file: File.join(Dir.getwd, 'plan.tjp'),
|
@@ -17,7 +17,21 @@ module FeduxOrgStdlib
|
|
17
17
|
# Use bundler to run command
|
18
18
|
attr_reader :use_bundler
|
19
19
|
|
20
|
-
|
20
|
+
# Create a new shell task
|
21
|
+
#
|
22
|
+
# @param [String] command
|
23
|
+
# The command to be executed
|
24
|
+
#
|
25
|
+
# @param [true,false] use_bundler
|
26
|
+
# Should the command be prefixed with `bundle exec`
|
27
|
+
#
|
28
|
+
# @see Task
|
29
|
+
# For other arguments accepted
|
30
|
+
def initialize(
|
31
|
+
command:,
|
32
|
+
use_bundler: false,
|
33
|
+
**args
|
34
|
+
)
|
21
35
|
super(**args)
|
22
36
|
|
23
37
|
@use_bundler = use_bundler
|
@@ -5,13 +5,22 @@ module FeduxOrgStdlib
|
|
5
5
|
module Rake
|
6
6
|
# Sub Task
|
7
7
|
#
|
8
|
+
# This class can be used to call other defined rake-tasks
|
9
|
+
#
|
8
10
|
# @see Rakefile
|
9
11
|
class SubTask < Task
|
10
12
|
# @!attribute [r] command
|
11
13
|
# The command to be executed
|
12
14
|
attr_reader :sub_tasks
|
13
15
|
|
14
|
-
|
16
|
+
# Create a new sub task task
|
17
|
+
#
|
18
|
+
# @param [Array] sub_tasks
|
19
|
+
# A list of sub tasks, e.g. 'namespace1:task1', 'task2'
|
20
|
+
def initialize(
|
21
|
+
sub_tasks:,
|
22
|
+
**args
|
23
|
+
)
|
15
24
|
super(**args)
|
16
25
|
|
17
26
|
@sub_tasks = Array(sub_tasks)
|
@@ -9,6 +9,9 @@ module FeduxOrgStdlib
|
|
9
9
|
module Rake
|
10
10
|
# Rake Task
|
11
11
|
#
|
12
|
+
# This class is mainly used as basis for more specific class like
|
13
|
+
# {Shelltask} or {Projecttask}.
|
14
|
+
#
|
12
15
|
# @see Rakefile
|
13
16
|
class Task < ::Rake::TaskLib
|
14
17
|
include ::Rake::DSL if defined?(::Rake::DSL)
|
@@ -31,7 +34,45 @@ module FeduxOrgStdlib
|
|
31
34
|
attr_reader :task_arguments, :task_block, :logger, :working_directory
|
32
35
|
|
33
36
|
# Create task instance
|
34
|
-
|
37
|
+
#
|
38
|
+
# @param [String] description
|
39
|
+
# A description for the task
|
40
|
+
#
|
41
|
+
# @param [String] name
|
42
|
+
# The name for the task (including namespace), e.g. namespace1:task1
|
43
|
+
#
|
44
|
+
# @param [Array] arguments
|
45
|
+
# Arguments for the task. Look
|
46
|
+
# [here](http://viget.com/extend/protip-passing-parameters-to-your-rake-tasks)
|
47
|
+
# for a better description on how to use arguments in rake tasks
|
48
|
+
#
|
49
|
+
# @param [true,false] define_in_ci_mode
|
50
|
+
# Should the task be defined and therefor available when in Continous
|
51
|
+
# Integration (CI)-mode + all needed dependencies (gems etc.)? It is
|
52
|
+
# best not to include some rubygems (debugger etc.) when running in
|
53
|
+
# CI-mode. CI-mode is detected by looking for a defined environment variable
|
54
|
+
# 'CI' (ENV['CI']).
|
55
|
+
#
|
56
|
+
# @param [true,false] activate_ci_mode
|
57
|
+
# Activate CI-mode when task is called.
|
58
|
+
#
|
59
|
+
# @param [Array] dependencies
|
60
|
+
# An array of other tasks this task depends on.
|
61
|
+
#
|
62
|
+
# @yield
|
63
|
+
# A block which is called before the "run_task"-method is called. The
|
64
|
+
# parameters it taskes depends on the number of parameters the block
|
65
|
+
# can take. If the block is defined which two parameters, it takes two
|
66
|
+
# parameters from the paramter 'arguments'.
|
67
|
+
def initialize(
|
68
|
+
description:,
|
69
|
+
name: self.class.to_s.split(/::/).slice(-2..-1).join(':').gsub(/Task$/, '').underscore,
|
70
|
+
arguments: [],
|
71
|
+
define_in_ci_mode: true,
|
72
|
+
activate_ci_mode: false,
|
73
|
+
dependencies: [],
|
74
|
+
&task_block
|
75
|
+
)
|
35
76
|
before_initialize
|
36
77
|
|
37
78
|
@description = description
|
@@ -53,8 +94,6 @@ module FeduxOrgStdlib
|
|
53
94
|
|
54
95
|
define_task unless running_in_ci_mode?
|
55
96
|
define_task if define_in_ci_mode? and running_in_ci_mode?
|
56
|
-
|
57
|
-
activate_ci_mode if activate_ci_mode?
|
58
97
|
end
|
59
98
|
|
60
99
|
private
|
@@ -75,6 +114,8 @@ module FeduxOrgStdlib
|
|
75
114
|
desc description unless ::Rake.application.last_comment
|
76
115
|
|
77
116
|
task name, *task_arguments do |_, task_args|
|
117
|
+
activate_ci_mode if activate_ci_mode?
|
118
|
+
|
78
119
|
RakeFileUtils.__send__(:verbose, verbose) do
|
79
120
|
task_block.call(*[self, task_args].slice(0, task_block.arity)) if task_block.respond_to? :call
|
80
121
|
run_task verbose
|
@@ -6,6 +6,24 @@ module FeduxOrgStdlib
|
|
6
6
|
module Rake
|
7
7
|
# Version Bump Task
|
8
8
|
#
|
9
|
+
# @example Create new version task for bumping the major number X.0.0
|
10
|
+
# FeduxOrgStdlib::Rake::VersionBumpTask.new(
|
11
|
+
# name: 'version:bump:major',
|
12
|
+
# description: 'Bump major version part'
|
13
|
+
# ) { |t| t.bump_version :major }
|
14
|
+
#
|
15
|
+
# @example Create new version task for bumping the minor number 0.X.0
|
16
|
+
# FeduxOrgStdlib::Rake::VersionBumpTask.new(
|
17
|
+
# name: 'version:bump:minor',
|
18
|
+
# description: 'Bump minor version part'
|
19
|
+
# ) { |t| t.bump_version :minor }
|
20
|
+
#
|
21
|
+
# @example Create new version task for bumping the tiny number 0.0.X
|
22
|
+
# FeduxOrgStdlib::Rake::VersionBumpTask.new(
|
23
|
+
# name: 'version:bump:tiny',
|
24
|
+
# description: 'Bump tiny version part'
|
25
|
+
# ) { |t| t.bump_version :tiny }
|
26
|
+
#
|
9
27
|
# @see Rakefile
|
10
28
|
class VersionBumpTask < Task
|
11
29
|
include Versionable
|
data/spec/app_config_spec.rb
CHANGED
@@ -4,4 +4,199 @@ require 'fedux_org_stdlib/app_config'
|
|
4
4
|
|
5
5
|
RSpec.describe AppConfig do
|
6
6
|
|
7
|
+
context 'options' do
|
8
|
+
it 'creates readers and writers' do
|
9
|
+
with_environment 'HOME' => working_directory do
|
10
|
+
config_klass = Class.new(AppConfig) do
|
11
|
+
option :opt1, nil
|
12
|
+
|
13
|
+
def class_name
|
14
|
+
'TestConfig'
|
15
|
+
end
|
16
|
+
|
17
|
+
def module_name
|
18
|
+
'MyApplication'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
config = config_klass.new
|
23
|
+
expect(config.opt1).to be_nil
|
24
|
+
|
25
|
+
config.opt1 = 'blub'
|
26
|
+
expect(config.opt1).to eq 'blub'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'creates readers' do
|
31
|
+
with_environment 'HOME' => working_directory do
|
32
|
+
config_klass = Class.new(AppConfig) do
|
33
|
+
option_reader :opt1, nil
|
34
|
+
|
35
|
+
def class_name
|
36
|
+
'TestConfig'
|
37
|
+
end
|
38
|
+
|
39
|
+
def module_name
|
40
|
+
'MyApplication'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
config = config_klass.new
|
45
|
+
expect(config.opt1).to be_nil
|
46
|
+
|
47
|
+
expect {
|
48
|
+
config.opt1 = 'blub'
|
49
|
+
}.to raise_error NoMethodError
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'config files' do
|
56
|
+
it 'looks at ~/.test.yaml' do
|
57
|
+
with_environment 'HOME' => working_directory do
|
58
|
+
create_file '.tests.yaml', <<-EOS.strip_heredoc
|
59
|
+
---
|
60
|
+
opt1: hello world
|
61
|
+
EOS
|
62
|
+
|
63
|
+
config_klass = Class.new(AppConfig) do
|
64
|
+
option_reader :opt1, nil
|
65
|
+
|
66
|
+
def class_name
|
67
|
+
'TestConfig'
|
68
|
+
end
|
69
|
+
|
70
|
+
def module_name
|
71
|
+
'MyApplication'
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
config = config_klass.new
|
76
|
+
expect(config.opt1).to eq 'hello world'
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'looks at ~/.config/my_application/tests.yaml' do
|
81
|
+
with_environment 'HOME' => working_directory do
|
82
|
+
create_file '.config/my_application/tests.yaml', <<-EOS.strip_heredoc
|
83
|
+
---
|
84
|
+
opt1: hello world
|
85
|
+
EOS
|
86
|
+
|
87
|
+
config_klass = Class.new(AppConfig) do
|
88
|
+
option_reader :opt1, nil
|
89
|
+
|
90
|
+
def class_name
|
91
|
+
'TestConfig'
|
92
|
+
end
|
93
|
+
|
94
|
+
def module_name
|
95
|
+
'MyApplication'
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
config = config_klass.new
|
100
|
+
expect(config.opt1).to eq 'hello world'
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
it 'looks at ~/.my_application/tests.yaml' do
|
105
|
+
with_environment 'HOME' => working_directory do
|
106
|
+
create_file '.my_application/tests.yaml', <<-EOS.strip_heredoc
|
107
|
+
---
|
108
|
+
opt1: hello world
|
109
|
+
EOS
|
110
|
+
|
111
|
+
config_klass = Class.new(AppConfig) do
|
112
|
+
option_reader :opt1, nil
|
113
|
+
|
114
|
+
def class_name
|
115
|
+
'TestConfig'
|
116
|
+
end
|
117
|
+
|
118
|
+
def module_name
|
119
|
+
'MyApplication'
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
config = config_klass.new
|
124
|
+
expect(config.opt1).to eq 'hello world'
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'looks at ~/.tests.yaml' do
|
129
|
+
with_environment 'HOME' => working_directory do
|
130
|
+
create_file '.tests.yaml', <<-EOS.strip_heredoc
|
131
|
+
---
|
132
|
+
opt1: hello world
|
133
|
+
EOS
|
134
|
+
|
135
|
+
config_klass = Class.new(AppConfig) do
|
136
|
+
option_reader :opt1, nil
|
137
|
+
|
138
|
+
def class_name
|
139
|
+
'TestConfig'
|
140
|
+
end
|
141
|
+
|
142
|
+
def module_name
|
143
|
+
'MyApplication'
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
config = config_klass.new
|
148
|
+
expect(config.opt1).to eq 'hello world'
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'looks at ~/.testsrc' do
|
153
|
+
with_environment 'HOME' => working_directory do
|
154
|
+
create_file '.testsrc', <<-EOS.strip_heredoc
|
155
|
+
---
|
156
|
+
opt1: hello world
|
157
|
+
EOS
|
158
|
+
|
159
|
+
config_klass = Class.new(AppConfig) do
|
160
|
+
option_reader :opt1, nil
|
161
|
+
|
162
|
+
def class_name
|
163
|
+
'TestConfig'
|
164
|
+
end
|
165
|
+
|
166
|
+
def module_name
|
167
|
+
'MyApplication'
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
config = config_klass.new
|
172
|
+
expect(config.opt1).to eq 'hello world'
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
context '#to_s' do
|
177
|
+
it 'outputs a list of variables' do
|
178
|
+
with_environment 'HOME' => working_directory do
|
179
|
+
config_klass = Class.new(AppConfig) do
|
180
|
+
option :opt1, 'test1'
|
181
|
+
option :opt2, 'test2'
|
182
|
+
|
183
|
+
def class_name
|
184
|
+
'TestConfig'
|
185
|
+
end
|
186
|
+
|
187
|
+
def module_name
|
188
|
+
'MyApplication'
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
config = config_klass.new
|
193
|
+
expect(config.to_s).to eq <<-EOS.strip_heredoc.chomp
|
194
|
+
option | value
|
195
|
+
-------------------- + --------------------------------------------------------------------------------
|
196
|
+
opt1 | test1
|
197
|
+
opt2 | test2
|
198
|
+
EOS
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
7
202
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fedux_org-stdlib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Max Meyer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -48,6 +48,7 @@ files:
|
|
48
48
|
- fedux_org-stdlib.gemspec
|
49
49
|
- lib/fedux_org_stdlib.rb
|
50
50
|
- lib/fedux_org_stdlib/app_config.rb
|
51
|
+
- lib/fedux_org_stdlib/app_config/exceptions.rb
|
51
52
|
- lib/fedux_org_stdlib/ci.rb
|
52
53
|
- lib/fedux_org_stdlib/colors/html_color.rb
|
53
54
|
- lib/fedux_org_stdlib/command.rb
|
@@ -74,6 +75,7 @@ files:
|
|
74
75
|
- lib/fedux_org_stdlib/models/class_based_model.rb
|
75
76
|
- lib/fedux_org_stdlib/models/exceptions.rb
|
76
77
|
- lib/fedux_org_stdlib/models/filesystem_based_model.rb
|
78
|
+
- lib/fedux_org_stdlib/process_environment.rb
|
77
79
|
- lib/fedux_org_stdlib/project.rb
|
78
80
|
- lib/fedux_org_stdlib/project/generators/taskjuggler.rb
|
79
81
|
- lib/fedux_org_stdlib/project/logger.rb
|