class Sleet::Config
Constants
- ConfigOption
- HIDDEN_UNLESS_IN_CLI_OPTIONS
- OPTION_FILENAME
Attributes
cli_hash[R]
dir[R]
Public Class Methods
new(dir:, cli_hash: {})
click to toggle source
# File lib/sleet/config.rb, line 9 def initialize(dir:, cli_hash: {}) @dir = dir @cli_hash = cli_hash end
Public Instance Methods
branch()
click to toggle source
# File lib/sleet/config.rb, line 34 def branch options_hash[:branch] end
circle_ci_token()
click to toggle source
# File lib/sleet/config.rb, line 42 def circle_ci_token options_hash[:circle_ci_token] end
input_file()
click to toggle source
# File lib/sleet/config.rb, line 18 def input_file options_hash[:input_file] end
output_file()
click to toggle source
# File lib/sleet/config.rb, line 22 def output_file options_hash[:output_file] end
print!()
click to toggle source
# File lib/sleet/config.rb, line 46 def print! puts Terminal::Table.new headings: %w[Option Value Source], rows: table_rows end
project()
click to toggle source
# File lib/sleet/config.rb, line 30 def project options_hash[:project] end
source_dir()
click to toggle source
# File lib/sleet/config.rb, line 14 def source_dir options_hash[:source_dir] end
username()
click to toggle source
# File lib/sleet/config.rb, line 26 def username options_hash[:username] end
workflows()
click to toggle source
# File lib/sleet/config.rb, line 38 def workflows options_hash[:workflows] end
Private Instance Methods
build_option_hash(source, options)
click to toggle source
# File lib/sleet/config.rb, line 128 def build_option_hash(source, options) options.map do |key, value| [key, ConfigOption.new(value, source)] end.to_h end
cli_options()
click to toggle source
# File lib/sleet/config.rb, line 80 def cli_options build_option_hash('CLI', cli_hash) end
default_dir()
click to toggle source
# File lib/sleet/config.rb, line 122 def default_dir Rugged::Repository.discover(Dir.pwd).path + '..' rescue Rugged::RepositoryError '.' end
default_hash()
click to toggle source
# File lib/sleet/config.rb, line 112 def default_hash { 'source_dir' => File.expand_path(default_dir), 'input_file' => '.rspec_example_statuses', 'output_file' => '.rspec_example_statuses', 'show_sensitive' => false, 'print_config' => true } end
default_options()
click to toggle source
# File lib/sleet/config.rb, line 108 def default_options build_option_hash 'default', default_hash end
directories()
click to toggle source
# File lib/sleet/config.rb, line 104 def directories @directories ||= dir.split('/') end
file_hashes()
click to toggle source
# File lib/sleet/config.rb, line 90 def file_hashes files.map { |f| [f, ::YAML.load_file(f) || {}] } end
file_options()
click to toggle source
# File lib/sleet/config.rb, line 84 def file_options file_hashes.map do |file, options| build_option_hash(file, options) end.reduce({}, :merge) end
files()
click to toggle source
# File lib/sleet/config.rb, line 94 def files paths_to_search.select { |f| File.file?(f) } end
options()
click to toggle source
# File lib/sleet/config.rb, line 54 def options @options ||= default_options.merge(file_options).merge(cli_options) end
options_hash()
click to toggle source
# File lib/sleet/config.rb, line 58 def options_hash @options_hash ||= Thor::CoreExt::HashWithIndifferentAccess.new(options.map { |k, o| [k, o.value] }.to_h) end
paths_to_search()
click to toggle source
# File lib/sleet/config.rb, line 98 def paths_to_search directories.each_index.map do |i| (directories[0..i] + [OPTION_FILENAME]).join('/') end end
table_options()
click to toggle source
# File lib/sleet/config.rb, line 74 def table_options options.reject do |key, _option| HIDDEN_UNLESS_IN_CLI_OPTIONS.include?(key) && !cli_hash.key?(key) end end
table_rows()
click to toggle source
# File lib/sleet/config.rb, line 62 def table_rows table_options.map do |key, option| if key.to_sym == :workflows [key, Terminal::Table.new(headings: ['Job Name', 'Output File'], rows: option.value.to_a), option.source] elsif key.to_sym == :circle_ci_token && !options['show_sensitive'].value [key, '**REDACTED**', option.source] else [key, option.value, option.source] end end end