Class: FoobarTemplates::Configurator

Inherits:
Object
  • Object
show all
Defined in:
lib/foobar_templates/configurator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfigurator

Returns a new instance of Configurator.



9
10
11
12
13
14
15
16
17
18
# File 'lib/foobar_templates/configurator.rb', line 9

def initialize
  @config_directory_root = "#{ENV['HOME']}/.foobar"
  @config_file = "#{@config_directory_root}/config"
  @user_defined_templates_path = "#{@config_directory_root}/templates"

  create_config_file_if_needed!

  # load configurations from config file
  @config_file_data = YAML.load_file @config_file
end

Instance Attribute Details

#config_file_dataObject

Returns the value of attribute config_file_data.



7
8
9
# File 'lib/foobar_templates/configurator.rb', line 7

def config_file_data
  @config_file_data
end

Instance Method Details

#always_perform_git_initObject



29
30
31
# File 'lib/foobar_templates/configurator.rb', line 29

def always_perform_git_init
  @config_file_data.fetch("always_perform_git_init", false)
end

#collect_user_defined_templatesObject



42
43
44
45
46
# File 'lib/foobar_templates/configurator.rb', line 42

def collect_user_defined_templates
  immediate_subdirectories(@user_defined_templates_path).flat_map do |template_dir|
    collect_templates_from_path(template_dir)
  end
end

#create_config_file_if_needed!Object



48
49
50
51
# File 'lib/foobar_templates/configurator.rb', line 48

def create_config_file_if_needed!
  FileUtils.mkdir_p @user_defined_templates_path
  FileUtils.cp("#{SOURCE_ROOT}/config/config", @config_file) unless File.exist? @config_file
end

#default_templateObject



20
21
22
# File 'lib/foobar_templates/configurator.rb', line 20

def default_template
  @config_file_data["default_template"]
end

#default_template=(val) ⇒ Object



24
25
26
27
# File 'lib/foobar_templates/configurator.rb', line 24

def default_template=(val)
  @config_file_data["default_template"] = val
  save_config!
end

#domain(key) ⇒ Object



33
34
35
# File 'lib/foobar_templates/configurator.rb', line 33

def domain(key)
  @config_file_data[key.to_s]
end

#set_domain(key, value) ⇒ Object



37
38
39
40
# File 'lib/foobar_templates/configurator.rb', line 37

def set_domain(key, value)
  @config_file_data[key.to_s] = value
  save_config!
end