Module: Planter
- Defined in:
- lib/planter.rb,
lib/planter/tag.rb,
lib/planter/file.rb,
lib/planter/hash.rb,
lib/planter/array.rb,
lib/planter/color.rb,
lib/planter/plant.rb,
lib/planter/config.rb,
lib/planter/errors.rb,
lib/planter/prompt.rb,
lib/planter/script.rb,
lib/planter/string.rb,
lib/planter/numeric.rb,
lib/planter/version.rb,
lib/planter/filelist.rb,
lib/planter/fileentry.rb
Overview
Primary module for this gem.
Defined Under Namespace
Modules: Color, Errors, Prompt, Tag Classes: Config, FileEntry, FileList, Plant, Script
Constant Summary collapse
- VERSION =
Current Planter version.
'3.0.7'
Constants included from Color
Color::ATTRIBUTES, Color::ATTRIBUTE_NAMES, Color::COLORED_REGEXP, Color::ESCAPE_REGEX
Class Attribute Summary collapse
-
.accept_defaults ⇒ Object
Accept all defaults.
- .base_dir ⇒ Object
-
.date ⇒ Object
Current date.
-
.debug ⇒ Object
Debug mode.
-
.overwrite ⇒ Object
Overwrite files.
-
.patterns ⇒ Hash
Patterns reader, file handling config.
-
.target ⇒ Object
Target.
-
.template ⇒ Object
Template name.
-
.variables ⇒ Object
Variable key/values.
Class Method Summary collapse
-
.config ⇒ Planter::Config
Reader for the configuration object.
-
.notify(string, notification_type = :info, newline: true, above_spinner: false, exit_code: nil) ⇒ Boolean
Print a message on the command line.
-
.pass_fail(cmd) ⇒ Object
Execute a shell command and return a Boolean success response.
-
.spinner ⇒ TTY::Spinner
Global progress indicator reader, will init if nil.
Methods included from Prompt
Methods included from Color
attributes, coloring?, rgb, support?, uncolor
Class Attribute Details
.accept_defaults ⇒ Object
Accept all defaults
90 91 92 |
# File 'lib/planter.rb', line 90 def accept_defaults @accept_defaults end |
.base_dir ⇒ Object
150 151 152 |
# File 'lib/planter.rb', line 150 def base_dir @base_dir ||= ENV['PLANTER_BASE_DIR'] || File.join(Dir.home, '.config', 'planter') end |
.date ⇒ Object
Current date
75 76 77 |
# File 'lib/planter.rb', line 75 def date @date end |
.debug ⇒ Object
Debug mode
66 67 68 |
# File 'lib/planter.rb', line 66 def debug @debug end |
.overwrite ⇒ Object
Overwrite files
72 73 74 |
# File 'lib/planter.rb', line 72 def overwrite @overwrite end |
.patterns ⇒ Hash
Patterns reader, file handling config
169 170 171 |
# File 'lib/planter.rb', line 169 def patterns @patterns ||= process_patterns end |
.target ⇒ Object
Target
69 70 71 |
# File 'lib/planter.rb', line 69 def target @target end |
.template ⇒ Object
Template name
78 79 80 |
# File 'lib/planter.rb', line 78 def template @template end |
.variables ⇒ Object
Variable key/values
84 85 86 |
# File 'lib/planter.rb', line 84 def variables @variables end |
Class Method Details
.config ⇒ Planter::Config
Reader for the configuration object
95 96 97 |
# File 'lib/planter.rb', line 95 def config @config ||= Config.new end |
.notify(string, notification_type = :info, newline: true, above_spinner: false, exit_code: nil) ⇒ Boolean
Print a message on the command line
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/planter.rb', line 109 def notify(string, notification_type = :info, newline: true, above_spinner: false, exit_code: nil) color = case notification_type when :debug return false unless @debug '{dw}' when :error '{br}' when :warn '{by}' else '{bw}' end out = "#{color}#{string}{x}" # out = out.gsub(/\[(.*?)\]/, "{by}\\1{x}#{color}") out = "\n#{out}" if newline spinner.update(title: 'ERROR') if exit_code spinner.error if notification_type == :error above_spinner ? spinner.log(out.x) : warn(out.x) exit(exit_code) if exit_code && $stdout.isatty && (ENV['PLANTER_RSPEC'] == 'true' || ENV['PLANTER_DEBUG'] != 'true') true end |
.pass_fail(cmd) ⇒ Object
Execute a shell command and return a Boolean success response
159 160 161 162 |
# File 'lib/planter.rb', line 159 def pass_fail(cmd) _, status = Open3.capture2("#{cmd} &> /dev/null") status.exitstatus.zero? end |
.spinner ⇒ TTY::Spinner
Global progress indicator reader, will init if nil
142 143 144 145 146 147 148 |
# File 'lib/planter.rb', line 142 def spinner @spinner ||= TTY::Spinner.new('{bw}[{by}:spinner{bw}] {w}:title'.x, hide_cursor: true, format: :dots, success_mark: '{bg}✔{x}'.x, error_mark: '{br}✖{x}'.x) end |