Class: Materielize::ConfigSetup
- Inherits:
-
Object
- Object
- Materielize::ConfigSetup
- Defined in:
- lib/materielize.rb
Instance Attribute Summary collapse
-
#default_config_dir ⇒ Object
readonly
Returns the value of attribute default_config_dir.
-
#root_dir ⇒ Object
readonly
Returns the value of attribute root_dir.
Instance Method Summary collapse
-
#accepted_user_responses ⇒ Object
Valid single-character responses from the user.
- #default_config_dir_exists? ⇒ Boolean
- #init_cfg_files(options = {}) ⇒ Object
-
#initialize ⇒ ConfigSetup
constructor
A new instance of ConfigSetup.
-
#install ⇒ Object
Basic setup of materiel.
- #materiel_exists? ⇒ Boolean
- #uninstall {|{message: "Uninstalling: Removing #{root_path}"}| ... } ⇒ Object
-
#valid_user_response?(response) ⇒ Boolean
Confirm that the user response is valid.
Constructor Details
#initialize ⇒ ConfigSetup
Returns a new instance of ConfigSetup.
8 9 10 11 12 |
# File 'lib/materielize.rb', line 8 def initialize @root_dir = "materiel" @default_config_dir = "default_config_files" @overwrite_all = false end |
Instance Attribute Details
#default_config_dir ⇒ Object (readonly)
Returns the value of attribute default_config_dir.
6 7 8 |
# File 'lib/materielize.rb', line 6 def default_config_dir @default_config_dir end |
#root_dir ⇒ Object (readonly)
Returns the value of attribute root_dir.
6 7 8 |
# File 'lib/materielize.rb', line 6 def root_dir @root_dir end |
Instance Method Details
#accepted_user_responses ⇒ Object
Valid single-character responses from the user
63 64 65 |
# File 'lib/materielize.rb', line 63 def accepted_user_responses %w[a A n N c C] + [true, false] end |
#default_config_dir_exists? ⇒ Boolean
18 19 20 |
# File 'lib/materielize.rb', line 18 def default_config_dir_exists? Dir.exists?(sub_path(default_config_dir)) end |
#init_cfg_files(options = {}) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/materielize.rb', line 48 def init_cfg_files( = {}) @overwrite_all = {force_all: false}.merge()[:force_all] # initialize if not indicated so as to not inadvertently cause disaster on a second call or somesuch. @project_root = Dir.getwd @root = File.(default_config_dir, root_dir) begin copy([root_dir, default_config_dir]) do |item| yield(item) end rescue Interrupt => e yield({message: e., needs_confirmation: false}) end end |
#install ⇒ Object
Basic setup of materiel. Create materiel directory, default config subdirectory, throw around some READMEs, etc.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/materielize.rb', line 23 def install root_path = File.(root_dir) if !materiel_exists? yield({message: "Creating directory '#{root_path}'."}) if block_given? Dir.mkdir(root_path) else yield({message: "Directory '#{root_path}' already exists, no need to create."}) if block_given? end default_config_path = File.(default_config_dir, root_dir) if !default_config_dir_exists? yield({message: "Creating directory '#{default_config_path}'."}) if block_given? Dir.mkdir(default_config_path) else yield({message: "Directory '#{default_config_path}' already exists, no need to create."}) if block_given? end end |
#materiel_exists? ⇒ Boolean
14 15 16 |
# File 'lib/materielize.rb', line 14 def materiel_exists? Dir.exists?(root_dir) end |
#uninstall {|{message: "Uninstalling: Removing #{root_path}"}| ... } ⇒ Object
42 43 44 45 46 |
# File 'lib/materielize.rb', line 42 def uninstall root_path = File.(root_dir) yield({message: "Uninstalling: Removing #{root_path}"}) if block_given? FileUtils.rm_rf(root_path) end |
#valid_user_response?(response) ⇒ Boolean
Confirm that the user response is valid. Accepts either a string (char) response or the the whole response/messaging hash. Booleans also accepted.
69 70 71 72 73 74 75 |
# File 'lib/materielize.rb', line 69 def valid_user_response?(response) if response.is_a?(String) || response.is_a?(TrueClass)|| response.is_a?(FalseClass) accepted_user_responses.include?(response) elsif response.is_a?(Hash) accepted_user_responses.include?(response[:confirmation]) end end |