module ConfC
Constants
- INTERRUPT_HANDLER
- VERSION
Public Class Methods
ask_choose_files(existent_files)
click to toggle source
Ask to choose existent files to clone.
# File lib/confc/ask_choose_files.rb, line 13 def self.ask_choose_files(existent_files) prompt = TTY::Prompt.new(interrupt: ConfC::INTERRUPT_HANDLER) prompt.multi_select("Which files that you want to #{APP_NAME}?") do |menu| menu.default(*(1..existent_files.length)) menu.choices existent_files end end
ask_overwrite(src, dest)
click to toggle source
Ask to overwrite `dest` file with `src` file.
# File lib/confc/ask_overwrite.rb, line 11 def self.ask_overwrite(src, dest) colored_src = Rainbow(src).magenta colored_dest = Rainbow(dest).green prompt = TTY::Prompt.new(interrupt: ConfC::INTERRUPT_HANDLER) prompt.yes?( %(Do you want to overwrite "#{colored_src}" with "#{colored_dest}"?) ) end
conf_clone( files, path, options = { overwrite: false, verbose: false } )
click to toggle source
Clone given files from given path to current working directory.
# File lib/confc/conf_clone.rb, line 8 def self.conf_clone( files, path, options = { overwrite: false, verbose: false } ) results = files.map do |file| src = File.expand_path(file, path) ConfC.copy(src, options) end results.any? { |result| result } # Return true if any process succeed end
copy(src, options = { overwrite: false, verbose: false })
click to toggle source
Copy given file to current working directory.
# File lib/confc/copy.rb, line 25 def self.copy(src, options = { overwrite: false, verbose: false }) return false unless File.exist?(src) # Stop if no src file # Stop if dest file exists & prevent overwriting src_filename = File.basename(src) dest_path = File.expand_path(src_filename, Dir.pwd) return false if ConfC.should_stop_copying?(src, dest_path, options) FileUtils.copy(src, Dir.pwd) # Display verbose dest = File.expand_path(src_filename, Dir.pwd) ConfC.display_verbose(src, dest) if options[:verbose] true end
display_verbose(src, dest)
click to toggle source
Display verbose information.
# File lib/confc/display_verbose.rb, line 8 def self.display_verbose(src, dest) verbose = Rainbow('Copied "').green verbose += Rainbow(src).cyan verbose += Rainbow('" to "').green verbose += Rainbow(dest).cyan verbose += Rainbow('".').green puts verbose end
files()
click to toggle source
Get list of file to be copied.
# File lib/confc/files.rb, line 8 def self.files files_path = File.expand_path('../../files.yaml', File.dirname(__FILE__)) if File.exist?(files_path) YAML.load_file(files_path) else [] end end
get_existent_files(path, all_files)
click to toggle source
Get the existent files at given path from all file list.
# File lib/confc/get_existent_files.rb, line 6 def self.get_existent_files(path, all_files) if all_files.is_a?(Array) all_files.select do |file| file_path = File.expand_path(file, path) File.exist?(file_path) end else [] end end
gethome()
click to toggle source
Get user's home directory.
# File lib/confc/gethome.rb, line 6 def self.gethome File.expand_path '~' end
load_config()
click to toggle source
Load ConfC
configuration.
# File lib/confc/load_config.rb, line 20 def self.load_config loader = Mysticonfig::Loader.new('confc', DEFAULT_CONFIG) config = loader.load if config.empty? DEFAULT_CONFIG.symbolize_keys else # Truncate un-related config config = config.select { |k, _| DEFAULT_CONFIG.keys.include? k } config.symbolize_keys end end
should_stop_copying?( src, dest_path, options = { overwrite: false } )
click to toggle source
Should stop copying?
# File lib/confc/copy.rb, line 12 def self.should_stop_copying?( src, dest_path, options = { overwrite: false } ) # When dest file exist & no `overwrite`, ask to overwrite. File.exist?(dest_path) && !options[:overwrite] && # When answer "don't overwrite", stop!. !ConfC.ask_overwrite(src, dest_path) end
to_filenames(raw_filenames)
click to toggle source
Convert all raw file names to base file names.
# File lib/confc/to_filenames.rb, line 6 def self.to_filenames(raw_filenames) if raw_filenames.is_a?(Array) && !raw_filenames.empty? raw_filenames.map do |raw_filename| File.basename raw_filename end else [] end end