Class: Bashly::Settings

Inherits:
Object
  • Object
show all
Extended by:
AssetHelper
Defined in:
lib/bashly/settings.rb

Constant Summary collapse

COMPLETION_SHELLS =
%w[bash zsh].freeze

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from AssetHelper

asset, asset_content

Class Attribute Details

.argfile_varObject



44
45
46
# File 'lib/bashly/settings.rb', line 44

def argfile_var
  @argfile_var ||= get :argfile_var
end

.commands_dirObject



48
49
50
# File 'lib/bashly/settings.rb', line 48

def commands_dir
  @commands_dir ||= get :commands_dir
end

.compact_short_flagsObject



52
53
54
# File 'lib/bashly/settings.rb', line 52

def compact_short_flags
  @compact_short_flags ||= get :compact_short_flags
end

.completionsObject



56
57
58
# File 'lib/bashly/settings.rb', line 56

def completions
  @completions ||= get :completions
end

.config_pathObject



82
83
84
# File 'lib/bashly/settings.rb', line 82

def config_path
  @config_path ||= get(:config_path) % { source_dir: source_dir }
end

.conjoined_flag_argsObject



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

def conjoined_flag_args
  @conjoined_flag_args ||= get :conjoined_flag_args
end

.enable_bash_version_bouncerObject



92
93
94
# File 'lib/bashly/settings.rb', line 92

def enable_bash_version_bouncer
  @enable_bash_version_bouncer ||= get :enable_bash_version_bouncer
end

.enable_deps_arrayObject



96
97
98
# File 'lib/bashly/settings.rb', line 96

def enable_deps_array
  @enable_deps_array ||= get :enable_deps_array
end

.enable_env_var_names_arrayObject



100
101
102
# File 'lib/bashly/settings.rb', line 100

def enable_env_var_names_array
  @enable_env_var_names_array ||= get :enable_env_var_names_array
end

.enable_header_commentObject



104
105
106
# File 'lib/bashly/settings.rb', line 104

def enable_header_comment
  @enable_header_comment ||= get :enable_header_comment
end

.enable_inspect_argsObject



108
109
110
# File 'lib/bashly/settings.rb', line 108

def enable_inspect_args
  @enable_inspect_args ||= get :enable_inspect_args
end

.enable_sourcingObject



112
113
114
# File 'lib/bashly/settings.rb', line 112

def enable_sourcing
  @enable_sourcing ||= get :enable_sourcing
end

.enable_view_markersObject



116
117
118
# File 'lib/bashly/settings.rb', line 116

def enable_view_markers
  @enable_view_markers ||= get :enable_view_markers
end

.extra_lib_dirsObject



128
129
130
131
132
133
134
135
136
137
# File 'lib/bashly/settings.rb', line 128

def extra_lib_dirs
  @extra_lib_dirs ||= begin
    dirs = get :extra_lib_dirs
    case dirs
    when Array then dirs
    when String then dirs.split(',').map(&:strip)
    else []
    end
  end
end

.formatterObject



139
140
141
# File 'lib/bashly/settings.rb', line 139

def formatter
  @formatter ||= get :formatter
end

.function_namesObject



151
152
153
# File 'lib/bashly/settings.rb', line 151

def function_names
  @function_names ||= get :function_names
end

.lib_dirObject



155
156
157
# File 'lib/bashly/settings.rb', line 155

def lib_dir
  @lib_dir ||= get :lib_dir
end

.partials_extensionObject



159
160
161
# File 'lib/bashly/settings.rb', line 159

def partials_extension
  @partials_extension ||= get :partials_extension
end

.private_reveal_keyObject



163
164
165
# File 'lib/bashly/settings.rb', line 163

def private_reveal_key
  @private_reveal_key ||= get :private_reveal_key
end

.show_examples_on_errorObject



171
172
173
# File 'lib/bashly/settings.rb', line 171

def show_examples_on_error
  @show_examples_on_error ||= get :show_examples_on_error
end

.source_dirObject



175
176
177
# File 'lib/bashly/settings.rb', line 175

def source_dir
  @source_dir ||= get :source_dir
end

.strictObject



179
180
181
# File 'lib/bashly/settings.rb', line 179

def strict
  @strict ||= get :strict
end

.tab_indentObject



193
194
195
# File 'lib/bashly/settings.rb', line 193

def tab_indent
  @tab_indent ||= get :tab_indent
end

.target_dirObject



197
198
199
# File 'lib/bashly/settings.rb', line 197

def target_dir
  @target_dir ||= get :target_dir
end

.usage_colorsObject



201
202
203
# File 'lib/bashly/settings.rb', line 201

def usage_colors
  @usage_colors ||= get :usage_colors
end

.var_aliasesObject



205
206
207
# File 'lib/bashly/settings.rb', line 205

def var_aliases
  @var_aliases ||= get :var_aliases
end

.watch_eventedObject



209
210
211
# File 'lib/bashly/settings.rb', line 209

def watch_evented
  @watch_evented ||= get :watch_evented
end

.watch_latencyObject



213
214
215
# File 'lib/bashly/settings.rb', line 213

def watch_latency
  @watch_latency ||= get :watch_latency
end

.word_wrapObject



217
218
219
# File 'lib/bashly/settings.rb', line 217

def word_wrap
  @word_wrap ||= get :word_wrap
end

Class Method Details

.all_lib_dirsObject



40
41
42
# File 'lib/bashly/settings.rb', line 40

def all_lib_dirs
  @all_lib_dirs = [full_lib_dir] + extra_lib_dirs
end

.completion_shellsObject

Raises:



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/bashly/settings.rb', line 64

def completion_shells
  value = completions
  return [] if value.nil? || value == false || value == 'minimal'
  return COMPLETION_SHELLS if value == 'full'

  shells = value.split(',', -1).map(&:strip) if value.is_a? String
  valid = shells&.any? && shells.all? { |shell| COMPLETION_SHELLS.include? shell }
  unique = shells&.uniq == shells
  return shells if valid && unique

  raise ConfigurationError,
    "completions must be false, minimal, full, or a comma-separated list of: #{COMPLETION_SHELLS.join ', '}"
end

.completions?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/bashly/settings.rb', line 60

def completions?
  completions == 'minimal' || completion_shells.any?
end

.enabled?(feature) ⇒ Boolean

Returns:

  • (Boolean)


86
87
88
89
90
# File 'lib/bashly/settings.rb', line 86

def enabled?(feature)
  send(:"enable_#{feature}") == 'always' ||
    (send(:"enable_#{feature}") == 'production' && production?) ||
    (send(:"enable_#{feature}") == 'development' && !production?)
end

.envObject



120
121
122
# File 'lib/bashly/settings.rb', line 120

def env
  @env ||= get(:env)&.to_sym
end

.env=(value) ⇒ Object



124
125
126
# File 'lib/bashly/settings.rb', line 124

def env=(value)
  @env = value&.to_sym
end

.full_lib_dirObject



143
144
145
# File 'lib/bashly/settings.rb', line 143

def full_lib_dir
  "#{source_dir}/#{lib_dir}"
end

.function_name(key) ⇒ Object



147
148
149
# File 'lib/bashly/settings.rb', line 147

def function_name(key)
  function_names[key.to_s] || key.to_s
end

.production?Boolean

Returns:

  • (Boolean)


167
168
169
# File 'lib/bashly/settings.rb', line 167

def production?
  env == :production
end

.strict_stringObject



183
184
185
186
187
188
189
190
191
# File 'lib/bashly/settings.rb', line 183

def strict_string
  if strict.is_a? String
    strict
  elsif strict
    'set -euo pipefail'
  else
    'set -e'
  end
end