Class: Bundlegem::Configurator
- Inherits:
-
Object
- Object
- Bundlegem::Configurator
- Defined in:
- lib/bundlegem/configurator.rb
Instance Attribute Summary collapse
-
#config_file_data ⇒ Object
Returns the value of attribute config_file_data.
-
#user_defined_templates ⇒ Object
Returns the value of attribute user_defined_templates.
-
#user_downloaded_templates ⇒ Object
Returns the value of attribute user_downloaded_templates.
Instance Method Summary collapse
- #built_in_templates ⇒ Object
- #create_config_file_if_needed! ⇒ Object
- #create_new_template(template_name) ⇒ Object
- #default_template ⇒ Object
- #default_template=(val) ⇒ Object
- #get_user_defined_templates ⇒ Object
-
#get_user_downloaded_templates ⇒ Object
not implemented yet.
-
#initialize ⇒ Configurator
constructor
A new instance of Configurator.
Constructor Details
#initialize ⇒ Configurator
Returns a new instance of Configurator.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/bundlegem/configurator.rb', line 9 def initialize @config_directory_root = "#{ENV['HOME']}/.bundlegem" @config_file = "#{@config_directory_root}/config" @user_defined_templates_path = "#{@config_directory_root}/templates" create_config_file_if_needed! @user_defined_templates = get_user_defined_templates @user_downloaded_templates = get_user_downloaded_templates # load configurations from config file @config_file_data = YAML.load_file @config_file end |
Instance Attribute Details
#config_file_data ⇒ Object
Returns the value of attribute config_file_data.
7 8 9 |
# File 'lib/bundlegem/configurator.rb', line 7 def config_file_data @config_file_data end |
#user_defined_templates ⇒ Object
Returns the value of attribute user_defined_templates.
7 8 9 |
# File 'lib/bundlegem/configurator.rb', line 7 def user_defined_templates @user_defined_templates end |
#user_downloaded_templates ⇒ Object
Returns the value of attribute user_downloaded_templates.
7 8 9 |
# File 'lib/bundlegem/configurator.rb', line 7 def user_downloaded_templates @user_downloaded_templates end |
Instance Method Details
#built_in_templates ⇒ Object
32 33 34 |
# File 'lib/bundlegem/configurator.rb', line 32 def built_in_templates end |
#create_config_file_if_needed! ⇒ Object
68 69 70 71 |
# File 'lib/bundlegem/configurator.rb', line 68 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 |
#create_new_template(template_name) ⇒ Object
73 74 75 |
# File 'lib/bundlegem/configurator.rb', line 73 def create_new_template(template_name) puts "i'm still a stub" end |
#default_template ⇒ Object
23 24 25 |
# File 'lib/bundlegem/configurator.rb', line 23 def default_template @config_file_data["default_template"] end |
#default_template=(val) ⇒ Object
27 28 29 30 |
# File 'lib/bundlegem/configurator.rb', line 27 def default_template=(val) @config_file_data["default_template"] = val File.write(@config_file, "# Comments made to this file will not be preserved\n#{YAML.dump(@config_file_data)}") end |
#get_user_defined_templates ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/bundlegem/configurator.rb', line 41 def get_user_defined_templates user_definition_directory = @user_defined_templates_path template_dirs = Dir.entries(user_definition_directory).select do |entry| File.directory?(File.join(user_definition_directory, entry)) and !(entry =='.' || entry == '..') end pairs = [] template_dirs.each do |dir| # open the dir and read the .bundlegem file to see what class of file it is # If there's no .bundlegem file in there, mark it misc begin f = File.read("#{@user_defined_templates_path}/#{dir}/.bundlegem") /category:\s*([\w\s]*$)/ =~ f category = $1.chomp rescue category = "MISC" end category = "MISC" if category.nil? pairs << {category => dir } end pairs end |
#get_user_downloaded_templates ⇒ Object
not implemented yet
37 38 39 |
# File 'lib/bundlegem/configurator.rb', line 37 def get_user_downloaded_templates [] end |