Class: Gill::Settings::Config
- Inherits:
-
Object
- Object
- Gill::Settings::Config
- Includes:
- Helper
- Defined in:
- lib/gill/config.rb
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
-
#cache_path ⇒ String
readonly
Cache Path.
-
#config_path ⇒ Object
readonly
Returns the value of attribute config_path.
-
#home ⇒ Object
readonly
Returns the value of attribute home.
-
#repos ⇒ Object
readonly
Returns the value of attribute repos.
-
#settings ⇒ Object
readonly
Returns the value of attribute settings.
Instance Method Summary collapse
-
#categories ⇒ Hash
Gill Categories.
-
#clean_cache ⇒ Object
Clean Cache.
-
#default_path ⇒ String
Gill Default Path.
-
#file_check! ⇒ Object
Gill File Check.
-
#find_repo_paths_by_name(repo_name, pretty_print = true, &block) ⇒ String
Find Repo.
-
#initialize(home_path = nil) ⇒ Config
constructor
Initialize Gill Configuration.
-
#list_entries ⇒ Object
List Gill Cloned Repos.
-
#paths ⇒ Array
Gill Paths.
-
#settings_path ⇒ String
Gill Settings Path.
-
#source_path ⇒ String
Gill Source Path.
-
#write_cache(cache) ⇒ Object
Write Cache.
-
#write_settings(settings) ⇒ Object
Write Settings.
Methods included from Helper
#ask, #basename, #blue, #folder_empty?, #green, #parent, #red
Constructor Details
#initialize(home_path = nil) ⇒ Config
Initialize Gill Configuration
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/gill/config.rb', line 15 def initialize(home_path=nil) @home = home_path || File.('~') @settings_path = File.join(@home, '.gillrc') @cache_path = File.join(@home, '.gillcache') Dir.chdir(@home) file_check! version_check! check_default_folders! self end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
8 9 10 |
# File 'lib/gill/config.rb', line 8 def cache @cache end |
#cache_path ⇒ String (readonly)
Cache Path
65 66 67 |
# File 'lib/gill/config.rb', line 65 def cache_path @cache_path end |
#config_path ⇒ Object (readonly)
Returns the value of attribute config_path.
8 9 10 |
# File 'lib/gill/config.rb', line 8 def config_path @config_path end |
#home ⇒ Object (readonly)
Returns the value of attribute home.
8 9 10 |
# File 'lib/gill/config.rb', line 8 def home @home end |
#repos ⇒ Object (readonly)
Returns the value of attribute repos.
8 9 10 |
# File 'lib/gill/config.rb', line 8 def repos @repos end |
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
8 9 10 |
# File 'lib/gill/config.rb', line 8 def settings @settings end |
Instance Method Details
#categories ⇒ Hash
Gill Categories
47 48 49 |
# File 'lib/gill/config.rb', line 47 def categories @repos = @cache[:categories] end |
#clean_cache ⇒ Object
Clean Cache
Check the gill cache on load for missing values and remove.
130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/gill/config.rb', line 130 def clean_cache @clean_cache = Gill.config.cache @clean_cache[:categories].each do |key,value| value.each do |k,v| @clean_cache[:categories][key.to_sym].delete(k.to_sym) unless File.directory?(v[:path].to_s) end @clean_cache[:categories].delete(key.to_sym) if @clean_cache[:categories][key.to_sym].empty? end write_cache(@clean_cache) end |
#default_path ⇒ String
Gill Default Path
83 84 85 |
# File 'lib/gill/config.rb', line 83 def default_path @default_path = @settings[:default] end |
#file_check! ⇒ Object
Gill File Check
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/gill/config.rb', line 29 def file_check! if File.exists?(@settings_path) load_gill_settings else setup_gill_settings end if File.exists?(@cache_path) load_gill_cache else setup_gill_cache end end |
#find_repo_paths_by_name(repo_name, pretty_print = true, &block) ⇒ String
Find Repo
165 166 167 168 169 170 171 172 |
# File 'lib/gill/config.rb', line 165 def find_repo_paths_by_name(repo_name,pretty_print=true,&block) repos = Dir[File.join(Gill.config.source_path, '**', "*#{repo_name}*")] repos.each do |path| next unless Gill.config.paths.include?(path) yield [basename(path),path,"#{basename(parent(path))}".downcase] if block && !pretty_print STDOUT.puts "#{basename(path)} => #{green(path)}" if pretty_print end end |
#list_entries ⇒ Object
List Gill Cloned Repos
113 114 115 116 117 118 119 120 121 122 |
# File 'lib/gill/config.rb', line 113 def list_entries STDERR.puts green("\n*** Listing Cloned Repositories ***\n") categories.sort.each do |category,repos| STDERR.puts "\t#{category}:" repos.each do |repo| STDERR.puts "\t #{green(repo[0])} => " + "#{repo[1][:repo]}" end STDERR.puts "\n" end end |
#paths ⇒ Array
Gill Paths
148 149 150 151 152 153 154 155 156 |
# File 'lib/gill/config.rb', line 148 def paths @paths = [] Gill.config.categories.each do |key,value| value.each do |k,v| @paths << v[:path] end end @paths end |
#settings_path ⇒ String
Gill Settings Path
74 75 76 |
# File 'lib/gill/config.rb', line 74 def settings_path @settings_path = @settings[:settings] end |
#source_path ⇒ String
Gill Source Path
56 57 58 |
# File 'lib/gill/config.rb', line 56 def source_path @source_path = @settings[:source] end |
#write_cache(cache) ⇒ Object
Write Cache
103 104 105 106 107 |
# File 'lib/gill/config.rb', line 103 def write_cache(cache) File.open(@cache_path, 'w') do |out| YAML.dump(cache, out) end end |
#write_settings(settings) ⇒ Object
Write Settings
92 93 94 95 96 |
# File 'lib/gill/config.rb', line 92 def write_settings(settings) File.open(@settings_path, 'w') do |out| YAML.dump(settings, out) end end |