Module: Planter

Extended by:
Color, Prompt
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

Class Method Summary collapse

Methods included from Prompt

choice, file_what?, yn

Methods included from Color

attributes, coloring?, rgb, support?, uncolor

Class Attribute Details

.accept_defaultsObject

Accept all defaults



90
91
92
# File 'lib/planter.rb', line 90

def accept_defaults
  @accept_defaults
end

.base_dirObject



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

.dateObject

Current date



75
76
77
# File 'lib/planter.rb', line 75

def date
  @date
end

.debugObject

Debug mode



66
67
68
# File 'lib/planter.rb', line 66

def debug
  @debug
end

.overwriteObject

Overwrite files



72
73
74
# File 'lib/planter.rb', line 72

def overwrite
  @overwrite
end

.patternsHash

Patterns reader, file handling config

Returns:

  • (Hash)

    hash of file patterns



169
170
171
# File 'lib/planter.rb', line 169

def patterns
  @patterns ||= process_patterns
end

.targetObject

Target



69
70
71
# File 'lib/planter.rb', line 69

def target
  @target
end

.templateObject

Template name



78
79
80
# File 'lib/planter.rb', line 78

def template
  @template
end

.variablesObject

Variable key/values



84
85
86
# File 'lib/planter.rb', line 84

def variables
  @variables
end

Class Method Details

.configPlanter::Config

Reader for the configuration object

Returns:



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

Parameters:

  • string (String)

    The message string

  • notification_type (Symbol) (defaults to: :info)

    The notification type (:debug, :error, :warn, :info)

  • exit_code (Integer) (defaults to: nil)

    If provided, exit with code after delivering message

  • newline (Boolean) (defaults to: true)

    If true, add a newline to the message

  • above_spinner (Boolean) (defaults to: false)

    If true, print above the spinner

Returns:

  • (Boolean)

    true if message was printed



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

Parameters:

  • cmd (String)

    The shell command



159
160
161
162
# File 'lib/planter.rb', line 159

def pass_fail(cmd)
  _, status = Open3.capture2("#{cmd} &> /dev/null")
  status.exitstatus.zero?
end

.spinnerTTY::Spinner

Global progress indicator reader, will init if nil

Returns:

  • (TTY::Spinner)

    Spinner object



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