dtc_rake 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c817667aaedf7106b5c94e35686711cd05a1397e
4
+ data.tar.gz: 519d634e71da52759dbf46bfd0d6d4c2297e249f
5
+ SHA512:
6
+ metadata.gz: 1e3fb74e9dc74d865c3822f206027800378089db348deece4b808fb325754aab5777e65c011612b557ec788f412f5784f6027eabaf277f28d9086473c4b3a9cf
7
+ data.tar.gz: 4aff5f658dce122c1e9ac33f97ad56b200b689ce2c2b55e2900219e813cef917fd5938367d4fb945dcae376c9cd7dbee452d4374e207ca72f302c1079a01f371
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dtc_rake.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,238 @@
1
+ # dtc_rake
2
+
3
+ Rake tasks for building apps produced by DTC.DEV team.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's `Gemfile`:
8
+
9
+ ```ruby
10
+ gem "dtc_rake", git: ""ssh://git@codebase.plus4u.net:9422/dtc.rake.git
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or build it yourself from source as:
18
+
19
+ $ git clone ssh://git@codebase.plus4u.net:9422/dtc.rake.git
20
+ $ cd dtc.rake/dtc_rake
21
+ $ rake install
22
+
23
+ # Quick Start
24
+
25
+ For a quick start just add to your appbox project's `Rakefile`:
26
+
27
+ ```ruby
28
+ require "dtc_rake"
29
+
30
+ DtcRake.configure do |config|
31
+ config.appbox_uarchive = "<uarchive_path>"
32
+ config.appbox_territory_code = "<territory_code>"
33
+ config.appbox_meta_artifact_code = "<meta_artifact_code>"
34
+ config.appbox_location_code = "<folder_code>"
35
+ end
36
+ ```
37
+
38
+ *Note: The appbox project name should be `<vendor>_<app>-appbox` and it must contain a uuApp deployment descriptor with default name `<vendor>_<app>-uuapp.json`.*
39
+
40
+ All shared tasks will be found and loaded automatically, you can verify it with `rake -T` command.
41
+
42
+ It is recommended to check whether the defaults fit your needs and change the configuration if needed.
43
+
44
+ Also set `DTC_RAKE_PASSWD` environment variable. It represents path to password file with authentication credentials (necessary for appbox creation and packs uploading). Its value can be either path relative to `uu.home` or an absolute path.
45
+
46
+ Example:
47
+
48
+ ```sh
49
+ rake upload:cmd DTC_RAKE_PASSWD=12-345-6
50
+ # or
51
+ rake upload:cmd DTC_RAKE_PASSWD=/path/to/12-345-6
52
+ ```
53
+
54
+ *Tip: If you set `DTC_RAKE_PASSWD` globally (e.g. in your `.bash_profile` or `.zshenv`), you won't have to set it everytime you use Rake tasks from this gem.*
55
+
56
+ # Documentation
57
+
58
+ TODO Link to online yardoc
59
+
60
+ ## Configuration
61
+
62
+ The following example shows all configuration options:
63
+
64
+
65
+ ```ruby
66
+ require "dtc_rake"
67
+
68
+ DtcRake.configure do |config|
69
+ # Code of application. Guessed from root_dir name if not set.
70
+ config.app = "<app_code>"
71
+
72
+ # Code of appbox artifact. Guessed from vendor, app and version in uuApp
73
+ # deployment descriptor if not set.
74
+ config.appbox_artifact_code = "<artifact_code>"
75
+
76
+ # Code of appbox location (folder or organization unit). Required.
77
+ config.appbox_location_code = "<folder_code>"
78
+
79
+ # Code of appbox meta artifact. Default value: UU.OS/RUNTIME/APP_BOX.
80
+ config.appbox_meta_artifact_code = "<meta_artifact_code>"
81
+
82
+ # Code of territory where the appbox artifact is / should be. Required.
83
+ config.appbox_territory_code = "<territory_code>"
84
+
85
+ # Path to uarchive with contents of appbox artifact. Default value: nil.
86
+ # If not set, appbox is created with empty content.
87
+ # Relative path is relative to root_dir.
88
+ config.appbox_uarchive = "<uarchive_path>"
89
+
90
+ # Path to uuApp deployment descriptor. Guessed from vendor and app if not set.
91
+ config.app_descriptor_path = "<deployment_descriptor_path>"
92
+
93
+ # Print messages in colors. Default value: true.
94
+ config.colorize = true
95
+
96
+ # Name of folder with build products. Default value: target.
97
+ # Relative path is relative to root_dir.
98
+ config.output_dir = "target"
99
+
100
+ # Appbox project root folder. Default value: current working directory.
101
+ config.root_dir = Dir.pwd
102
+
103
+ # Upload uuApp deployment descriptor to appbox artifact. Default value: false.
104
+ config.upload_app_descriptor = true
105
+
106
+ # Code of vendor. Guessed from root_dir name if not set.
107
+ config.vendor = "<vendor_code>"
108
+ end
109
+ ```
110
+
111
+ ## Explanation of Provided Tasks
112
+
113
+ ### appbox
114
+
115
+ Creates new appbox artifact.
116
+
117
+ ### build:all
118
+
119
+ Builds all available packs. Which packs get built depends on which projects exist for the app being built.
120
+
121
+ Example:
122
+
123
+ Only tasks for building command client and server would be available for app with the following structure.
124
+
125
+ ```
126
+ cds.gb
127
+ +- cds_gb
128
+ +- cds_gb-appbox
129
+ +- Rakefile
130
+ +- cds_gb-cmd
131
+ ```
132
+
133
+ ### build:cmd
134
+
135
+ Builds pack with command server. Available if project `<vendor>_<app>-cmd` exists.
136
+
137
+ ### build:dockerfiles
138
+
139
+ Builds pack with `Dockerfile`s. Available if project `<vendor>_<app>-dockerfiles` exists.
140
+
141
+ ### build:gem
142
+
143
+ Builds pack with command client Ruby gem. Available if project `<vendor>_<app>` exists.
144
+
145
+ ### build:vuc
146
+
147
+ Builds pack with visual use cases. Available if project `<vendor>_<app>-vuc` exists.
148
+
149
+ ### build:yardoc
150
+
151
+ Builds pach with command client yardoc. Available if project `<vendor>_<app>` exists.
152
+
153
+ ### upload:all
154
+
155
+ Uploads all available packs to appbox artifact. Which packs get uploaded depends on which projects exist for the app being built. See example for the `build:all` task.
156
+
157
+ ### upload:cmd
158
+
159
+ Uploads pack with command server to appbox artifact. Available if project `<vendor>_<app>-cmd` exists.
160
+
161
+ Requires `DTC_RAKE_PASSWD` to be set.
162
+
163
+ ### upload:descriptor
164
+
165
+ Uploads uuApp deployment descriptor to appbox artifact. Available if `config.upload_app_descriptor` is set to `true`.
166
+
167
+ Requires `DTC_RAKE_PASSWD` to be set.
168
+
169
+ ### upload:dockerfiles
170
+
171
+ Uploads pack with `Dockerfile`s to appbox artifact. Available if project `<vendor>_<app>-dockerfiles` exists.
172
+
173
+ Requires `DTC_RAKE_PASSWD` to be set.
174
+
175
+ ### upload:gem
176
+
177
+ Uploads pack with command client Ruby gem to appbox artifact. Available if project `<vendor>_<app>` exists.
178
+
179
+ Requires `DTC_RAKE_PASSWD` to be set.
180
+
181
+ ### upload:vuc
182
+
183
+ Uploads pack with visual use cases to appbox artifact. Available if project `<vendor>_<app>-vuc` exists.
184
+
185
+ Requires `DTC_RAKE_PASSWD` to be set.
186
+
187
+ ### upload:yardoc
188
+
189
+ Uploads pach with command client yardoc to appbox artifact. Available if project `<vendor>_<app>` exists.
190
+
191
+ Requires `DTC_RAKE_PASSWD` to be set.
192
+
193
+ # How-to
194
+
195
+ ## How to Add Custom Task
196
+
197
+ When a project requires a specific Rake task then implement it and add it to a shared task as dependency:
198
+
199
+ ```ruby
200
+ namespace :build do
201
+ desc "Builds pack with widget"
202
+ task :widget do
203
+ ...
204
+ end
205
+ end
206
+ task "build:all" => "widget"
207
+ ```
208
+
209
+ ## How to Remove a Task
210
+
211
+ If there is a task that doesn't make sense for you then you can exclude it from loading.
212
+
213
+ For example, to exclude the `upload:dockerfiles`, replace the `require`
214
+
215
+ ```ruby
216
+ require "dtc_rake"
217
+ ```
218
+
219
+ with
220
+
221
+ ```ruby
222
+ require "dtc_rake/tasks"
223
+ DtcRake::Tasks.load_tasks(exclude: ["upload_dockerfiles.rake"])
224
+ ```
225
+
226
+ To remove check that is used also as dependency for e.g. `upload:all`, it is needed to remove it also from prerequisites of task. Example how to remove `upload:dockerfiles` and do not call it when building all packs.
227
+
228
+ ```ruby
229
+ require "dtc_rake/tasks"
230
+ DtcRake::Tasks.load_tasks(exclude: ["upload_dockerfiles.rake"])
231
+ Rake::Task["upload:all"].prerequisites.delete("dockerfiles")
232
+ ```
233
+
234
+ # Development
235
+
236
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
237
+
238
+ To install this gem onto your local machine, run `bundle exec rake install`.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :build
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "dtc_rake"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/dtc_rake.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dtc_rake/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dtc_rake"
8
+ spec.version = DtcRake::VERSION
9
+ spec.authors = ["Jan Sibil"]
10
+ spec.email = ["21-1@plus4u.net"]
11
+
12
+ spec.summary = %q{Rake tasks for building apps produced by DTC.DEV team.}
13
+
14
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
15
+ f.match(%r{^(test|spec|features)/})
16
+ end
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "json", "~> 1.8.3"
22
+ spec.add_runtime_dependency "rainbow", "~> 2.1.0"
23
+ spec.add_runtime_dependency "uu_os", "~> 0.19"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.13", ">= 1.13.3"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ end
@@ -0,0 +1,112 @@
1
+ require "rake"
2
+ require "pathname"
3
+
4
+ module DtcRake
5
+ def configure(&block)
6
+ yield Config.instance
7
+ end
8
+ module_function :configure
9
+
10
+ class Config
11
+ include Singleton
12
+
13
+ def initialize
14
+ @root_dir = Dir.pwd
15
+ @output_dir = "target"
16
+ @colorize = true
17
+ @appbox_meta_artifact_code = "UU.OS/RUNTIME/APP_BOX"
18
+ @upload_app_descriptor = false
19
+ guess_vendor_and_app
20
+ end
21
+
22
+ # Code of application. Guessed from root_dir name if not set.
23
+ attr_accessor :app
24
+
25
+ # Code of appbox artifact. Guessed from vendor, app and version in uuApp
26
+ # deployment descriptor if not set.
27
+ attr_accessor :appbox_artifact_code
28
+
29
+ # Code of appbox location (folder or organization unit). Required.
30
+ attr_accessor :appbox_location_code
31
+
32
+ # Code of appbox meta artifact. Default value: UU.OS/RUNTIME/APP_BOX.
33
+ attr_accessor :appbox_meta_artifact_code
34
+
35
+ # Code of territory where the appbox artifact is / should be. Required.
36
+ attr_accessor :appbox_territory_code
37
+
38
+ # Path to uarchive with contents of appbox artifact. Default value: nil.
39
+ # If not set, appbox is created with empty content.
40
+ # Relative path is relative to root_dir.
41
+ attr_accessor :appbox_uarchive
42
+
43
+ # Path to uuApp deployment descriptor. Guessed from vendor and app if not set.
44
+ attr_accessor :app_descriptor_path
45
+
46
+ # Print messages in colors. Default value: true.
47
+ attr_accessor :colorize
48
+
49
+ # Name of folder with build products. Default value: target.
50
+ # Relative path is relative to root_dir.
51
+ attr_accessor :output_dir
52
+
53
+ # Appbox project root folder. Default value: current working directory.
54
+ attr_accessor :root_dir
55
+
56
+ # Upload uuApp deployment descriptor to appbox artifact. Default value: false.
57
+ attr_accessor :upload_app_descriptor
58
+
59
+ # Code of vendor. Guessed from root_dir name if not set.
60
+ attr_accessor :vendor
61
+
62
+ def app=(name)
63
+ @app = name.downcase unless name.nil?
64
+ end
65
+
66
+ def appbox_uarchive=(path)
67
+ unless path.nil?
68
+ path = File.join(root_dir, path) if Pathname.new(path).relative?
69
+ # File.expand_path converts path to absolute and expands "~" to real user home path
70
+ @appbox_uarchive = File.expand_path(path)
71
+ end
72
+ end
73
+
74
+ def app_descriptor_path
75
+ return @app_descriptor_path if @app_descriptor_path
76
+
77
+ default_file_path = File.expand_path(File.join(root_dir, "#{vendor}_#{app}-uuapp-deploy.json"))
78
+
79
+ Dir.chdir(root_dir) do
80
+ unless File.file?(default_file_path)
81
+ abort "uuApp deployment descriptor not found. Please create file #{default_file_path} or configure its path in Rakefile."
82
+ end
83
+ @app_descriptor_path = default_file_path
84
+ end
85
+ end
86
+
87
+ def output_dir=(path)
88
+ unless path.nil?
89
+ path = File.join(root_dir, path) if Pathname.new(path).relative?
90
+ # File.expand_path converts path to absolute and expands "~" to real user home path
91
+ @output_dir = File.expand_path(path)
92
+ end
93
+ end
94
+
95
+ def vendor=(name)
96
+ @vendor = name.downcase unless name.nil?
97
+ end
98
+
99
+ private
100
+
101
+ def guess_vendor_and_app
102
+ base_name = File.basename(root_dir)
103
+ if /([^_]+)_([^-]+)-appbox/ =~ base_name
104
+ @vendor = $1
105
+ @app = $2
106
+ else
107
+ abort "Appbox root folder (#{base_name}) does not match naming convention <vendor>_<app>-appbox." \
108
+ " Either change the folder name or configure 'vendor' and 'app' in Rakefile."
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,137 @@
1
+ require "rake"
2
+ require "dtc_rake/config"
3
+ require "dtc_rake/ui"
4
+ require "json"
5
+ require "uu/os/uesuri"
6
+
7
+ module DtcRake
8
+ class Product
9
+ include Singleton
10
+ include DtcRake::UI
11
+
12
+ # Appbox version specified in deployment descriptor.
13
+ attr_reader :version
14
+
15
+ # UESURI of the appbox artifact.
16
+ attr_reader :appbox_uri
17
+
18
+ attr_reader :gem_project, :cmd_project, :vuc_project, :dockerfiles_project
19
+
20
+ attr_reader :has_gem, :has_cmd, :has_vuc, :has_dockerfiles
21
+
22
+ attr_reader :gem_file_name, :cmd_file_name, :vuc_file_name, :yardoc_file_name, :dockerfiles_file_name
23
+ attr_reader :gem_attachment_code, :cmd_attachment_code, :vuc_attachment_code, :yardoc_attachment_code, :dockerfiles_attachment_code
24
+
25
+ def initialize
26
+ config = Config.instance
27
+ root_dir = config.root_dir
28
+ sibling_dir_path = File.expand_path(File.join(root_dir, "../#{config.vendor}_#{config.app}"))
29
+
30
+ @gem_project = sibling_dir_path
31
+ @has_gem = File.directory?(@gem_project)
32
+
33
+ @cmd_project = "#{sibling_dir_path}-cmd"
34
+ @has_cmd = File.directory?(@cmd_project)
35
+
36
+ @vuc_project = "#{sibling_dir_path}-vuc"
37
+ @has_vuc = File.directory?(@vuc_project)
38
+
39
+ @dockerfiles_project = File.expand_path(File.join(root_dir, "../docker"))
40
+ @has_dockerfiles = File.directory?(@dockerfiles_project)
41
+ end
42
+
43
+ def app_descriptor
44
+ return @app_descriptor if @app_descriptor
45
+
46
+ File.open(Config.instance.app_descriptor_path, "r") do |f|
47
+ @app_descriptor = JSON.parse(f.read, symbolize_names: true)
48
+ end
49
+ end
50
+
51
+ def version
52
+ app_descriptor[:data][:version]
53
+ end
54
+
55
+ def appbox_uri
56
+ return @appbox_uri if @appbox_uri
57
+
58
+ config = Config.instance
59
+ error("Territory code is not set. Set it in DtcRake.configure (attribute appbox_territory_code) in your Rakefile.") if config.appbox_territory_code.nil?
60
+ appbox_artifact_code = config.appbox_artifact_code || "#{config.vendor.upcase}.#{config.app.upcase}_#{version}"
61
+ appbox_uri = UU::OS::UESURI.create(territory_code: config.appbox_territory_code, artifact_code: appbox_artifact_code)
62
+ @appbox_uri = appbox_uri
63
+ end
64
+
65
+ def gem_file_name
66
+ return @gem_file_name if defined? @gem_file_name
67
+ config = Config.instance
68
+ # TODO Read version from version.rb or allow to override it from within the Rakefile
69
+ # the actual gem version differs - e.g. uu_operation_registry-1.3.0.pre.BETA.1.gem (NOT uu_operation_registry-1.3.0-BETA.1.gem)
70
+ gem_version = version.sub(/-(ALPHA|BETA|RC)/) { |match| ".pre.#{$1}" }
71
+ @gem_file_name = "#{config.vendor}_#{config.app}-#{gem_version}.gem"
72
+ end
73
+
74
+ def cmd_file_name
75
+ return @cmd_file_name if defined? @cmd_file_name
76
+ config = Config.instance
77
+ # TODO Read version from version.rb or allow to override it from within the Rakefile
78
+ @cmd_file_name = "#{config.vendor}_#{config.app}-cmd-#{version}.war"
79
+ end
80
+
81
+ def vuc_file_name
82
+ return @vuc_file_name if defined? @vuc_file_name
83
+ config = Config.instance
84
+ # TODO Read version from version.rb or allow to override it from within the Rakefile
85
+ @vuc_file_name = "#{config.vendor}_#{config.app}-vuc-#{version}.war"
86
+ end
87
+
88
+ def dockerfiles_file_name
89
+ return @dockerfiles_file_name if defined? @dockerfiles_file_name
90
+ config = Config.instance
91
+ # TODO Read version from version.rb or allow to override it from within the Rakefile
92
+ @dockerfiles_file_name = "#{config.vendor}_#{config.app}-dockerfiles-#{version}.zip"
93
+ end
94
+
95
+ def yardoc_file_name
96
+ return @yardoc_file_name if defined? @yardoc_file_name
97
+ config = Config.instance
98
+ @yardoc_file_name = "#{config.vendor}_#{config.app}-yardoc-#{version}.zip"
99
+ end
100
+
101
+ def gem_attachment_code
102
+ return @gem_attachment_code if defined? @gem_attachment_code
103
+ config = Config.instance
104
+ @gem_attachment_code = "#{config.vendor.upcase}.#{config.app.upcase}/GEM-PACK"
105
+ end
106
+
107
+ def cmd_attachment_code
108
+ return @cmd_attachment_code if defined? @cmd_attachment_code
109
+ config = Config.instance
110
+ @cmd_attachment_code = "#{config.vendor.upcase}.#{config.app.upcase}/CMD-PACK"
111
+ end
112
+
113
+ def vuc_attachment_code
114
+ return @vuc_attachment_code if defined? @vuc_attachment_code
115
+ config = Config.instance
116
+ @vuc_attachment_code = "#{config.vendor.upcase}.#{config.app.upcase}/VUC-PACK"
117
+ end
118
+
119
+ def dockerfiles_attachment_code
120
+ return @dockerfiles_attachment_code if defined? @dockerfiles_attachment_code
121
+ config = Config.instance
122
+ @dockerfiles_attachment_code = "#{config.vendor.upcase}.#{config.app.upcase}/DOCKERFILES-PACK"
123
+ end
124
+
125
+ def yardoc_attachment_code
126
+ return @yardoc_attachment_code if defined? @yardoc_attachment_code
127
+ config = Config.instance
128
+ @yardoc_attachment_code = "#{config.vendor.upcase}.#{config.app.upcase}/YARDOC-PACK"
129
+ end
130
+
131
+ def app_descriptor_attachment_code
132
+ return @app_descriptor_attachment_code if defined? @app_descriptor_attachment_code
133
+ config = Config.instance
134
+ @app_descriptor_attachment_code = "#{config.vendor.upcase}.#{config.app.upcase}/UUAPP-DEPLOY"
135
+ end
136
+ end
137
+ end
@@ -0,0 +1,28 @@
1
+ require "rake"
2
+
3
+ module DtcRake
4
+ module Tasks
5
+ def load_tasks(params = {})
6
+ # a flag - load the tasks just once, multiple loading
7
+ # leads to multiple invocation of the same task
8
+ return if defined? @tasks_loaded
9
+
10
+ params[:exclude] ||= []
11
+ params[:include] ||= ["*.rake"]
12
+ filelist = {}
13
+
14
+ [:exclude, :include].each do |key|
15
+ filelist[key] = params[key].collect { |file| Dir[File.expand_path("#{File.dirname(__FILE__)}/../tasks/#{file}")] }
16
+ filelist[key].flatten!
17
+ end
18
+
19
+ # load an include file only if it not in the exclude list
20
+ filelist[:include].each do |ext|
21
+ load ext unless filelist[:exclude].include?(ext)
22
+ end
23
+
24
+ @tasks_loaded = true
25
+ end
26
+ module_function :load_tasks
27
+ end
28
+ end
@@ -0,0 +1,49 @@
1
+ module DtcRake
2
+ module UI
3
+ def error(msg)
4
+ msg = Rainbow(msg).red if colorize?
5
+ abort msg
6
+ end
7
+ module_function :error
8
+
9
+ def announce(msg)
10
+ msg = Rainbow(msg).aqua if colorize?
11
+ puts msg
12
+ end
13
+ module_function :announce
14
+
15
+ def success(msg)
16
+ msg = Rainbow(msg).green if colorize?
17
+ puts msg
18
+ end
19
+ module_function :success
20
+
21
+ def warning(msg)
22
+ msg = Rainbow(msg).yellow if colorize?
23
+ puts msg
24
+ end
25
+ module_function :warning
26
+
27
+ def info(msg)
28
+ msg = Rainbow(msg).white if colorize?
29
+ puts msg
30
+ end
31
+ module_function :info
32
+
33
+ private
34
+
35
+ def colorize?
36
+ return @colorize if defined? @colorize
37
+
38
+ colorize = Config.instance.colorize
39
+ if colorize
40
+ begin
41
+ require "rainbow"
42
+ rescue LoadError
43
+ colorize = false
44
+ end
45
+ end
46
+ @colorize = colorize
47
+ end
48
+ end
49
+ end