Class: Gill::Settings::Config

Inherits:
Object
  • Object
show all
Includes:
Helper
Defined in:
lib/gill/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper

#ask, #basename, #blue, #folder_empty?, #green, #parent, #red

Constructor Details

#initialize(home_path = nil) ⇒ Config

Initialize Gill Configuration

Parameters:

  • home_path (String) (defaults to: nil)

    Override the default user home path.



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.expand_path('~')
  @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

#cacheObject (readonly)

Returns the value of attribute cache.



8
9
10
# File 'lib/gill/config.rb', line 8

def cache
  @cache
end

#cache_pathString (readonly)

Cache Path

Returns:

  • (String)

    Gill Cache Path



65
66
67
# File 'lib/gill/config.rb', line 65

def cache_path
  @cache_path
end

#config_pathObject (readonly)

Returns the value of attribute config_path.



8
9
10
# File 'lib/gill/config.rb', line 8

def config_path
  @config_path
end

#homeObject (readonly)

Returns the value of attribute home.



8
9
10
# File 'lib/gill/config.rb', line 8

def home
  @home
end

#reposObject (readonly)

Returns the value of attribute repos.



8
9
10
# File 'lib/gill/config.rb', line 8

def repos
  @repos
end

#settingsObject (readonly)

Returns the value of attribute settings.



8
9
10
# File 'lib/gill/config.rb', line 8

def settings
  @settings
end

Instance Method Details

#categoriesHash

Gill Categories

Returns:

  • (Hash)

    Gill Category Hash



47
48
49
# File 'lib/gill/config.rb', line 47

def categories
  @repos = @cache[:categories]
end

#clean_cacheObject

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_pathString

Gill Default Path

Returns:

  • (String)

    Gill Default Clone 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

Parameters:

  • repo_name (String)

    Repository Name

Returns:

  • (String)

    Repository Path



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_entriesObject

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

#pathsArray

Gill Paths

Returns:

  • (Array)

    Array Of Gill Repo 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_pathString

Gill Settings Path

Returns:

  • (String)

    Gill Settings Path



74
75
76
# File 'lib/gill/config.rb', line 74

def settings_path
  @settings_path = @settings[:settings]
end

#source_pathString

Gill Source Path

Returns:

  • (String)

    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

Parameters:

  • cache (Hash)

    Hash To Write To The Gill 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

Parameters:

  • settings (Hash)

    Hash To Write To The Gill 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