class MiseEnPlace::Mise
Constants
- CONFIG_FILENAME
- CONFIG_PATH
Public Class Methods
new(options={})
click to toggle source
# File lib/mise_en_place/mise.rb, line 14 def initialize(options={}) @options = OpenStruct.new options @top_level_dir = Pathname(@options.project_name) request_and_overwrite if File.exist? @top_level_dir FileUtils.mkdir_p(@top_level_dir) end
Public Instance Methods
build_file_structure(yaml=fetch_yaml, path=@top_level_dir)
click to toggle source
# File lib/mise_en_place/mise.rb, line 43 def build_file_structure(yaml=fetch_yaml, path=@top_level_dir) path = Pathname(path) return unless yaml yaml.each do |file| if file.is_a?(Hash) file.values.each do |sub_file| build_file_structure(sub_file, path + file.keys.first) end else # cast to Array to avoid type checking between Array or String Array[file].each do |sub_file| create_file_or_dir(sub_file, path) end end end end
fetch_yaml(config_path=@options.config)
click to toggle source
# File lib/mise_en_place/mise.rb, line 25 def fetch_yaml(config_path=@options.config) begin full_yaml = YAML.load_file(config_path || find_config) unless full_yaml warn_no_project_type return end project_type = options.project_type || "default" full_yaml = full_yaml.reduce(:merge)[project_type] warn_no_project_type unless full_yaml return full_yaml rescue Errno::ENOENT, TypeError puts "\ Please make sure a file named #{CONFIG_FILENAME} exists in your current directory or any of its parent directories or specify a path with the --config option" exit(false) end end
options()
click to toggle source
# File lib/mise_en_place/mise.rb, line 21 def options @options end
Private Instance Methods
ask_to_build_config()
click to toggle source
# File lib/mise_en_place/mise.rb, line 116 def ask_to_build_config puts "Could not find a config file. Would you like to create one now? [Y/n]" gets.chomp.downcase end
ask_to_overwrite()
click to toggle source
# File lib/mise_en_place/mise.rb, line 121 def ask_to_overwrite puts "A folder with #{@top_level_dir} already exists. Overwrite? [y/N]" gets.chomp.downcase end
command_line_args()
click to toggle source
# File lib/mise_en_place/mise.rb, line 135 def command_line_args ARGV end
create_file_or_dir(file_or_dir, path)
click to toggle source
# File lib/mise_en_place/mise.rb, line 77 def create_file_or_dir(file_or_dir, path) full_path = Pathname(path + file_or_dir) if is_dir?(file_or_dir) FileUtils.mkdir_p(full_path) else FileUtils.mkdir_p(path) FileUtils.touch(full_path) end end
find_config()
click to toggle source
# File lib/mise_en_place/mise.rb, line 91 def find_config path = Pathname(Dir.pwd) while path != Pathname("/") return path + CONFIG_FILENAME if File.exist? path + CONFIG_FILENAME path = path.parent end return request_and_build_config end
is_dir?(file_or_dir)
click to toggle source
# File lib/mise_en_place/mise.rb, line 87 def is_dir?(file_or_dir) Pathname(file_or_dir).extname == "" end
request_and_build_config()
click to toggle source
# File lib/mise_en_place/mise.rb, line 100 def request_and_build_config input = ask_to_build_config if input == "" || input == "y" File.open(CONFIG_PATH, 'w') do |f| f.puts "---" f.puts "- default:" end unless File.exist? CONFIG_PATH puts "File created at #{CONFIG_PATH}. Add your desired project structure under default and run MiseEnPlace again." return CONFIG_PATH else return nil end end
request_and_overwrite()
click to toggle source
# File lib/mise_en_place/mise.rb, line 126 def request_and_overwrite input = ask_to_overwrite if input == "y" return true else exit(false) end end
warn_no_project_type()
click to toggle source
# File lib/mise_en_place/mise.rb, line 62 def warn_no_project_type puts "\ Could not find a valid yaml structure for your project. Make sure that a default structure or one for your project type exists in your config file. Try something like this: --- - default: - file_structure_here " puts "\ - #{options.project_type} - file_structure_here" if options.project_type exit(false) return end