Class: Heighliner::Config
- Inherits:
-
Object
- Object
- Heighliner::Config
- Defined in:
- lib/heighliner/config.rb
Constant Summary collapse
- POSSIBLE_STEERFILES =
%w[ Steerfile Heighliner.config heighliner.config ].freeze
Class Attribute Summary collapse
-
.config ⇒ Object
readonly
Returns the value of attribute config.
-
.config_dir ⇒ Object
readonly
Returns the value of attribute config_dir.
-
.config_file ⇒ Object
readonly
Returns the value of attribute config_file.
-
.info_out ⇒ Object
Returns the value of attribute info_out.
-
.out ⇒ Object
Returns the value of attribute out.
-
.steerfile ⇒ Object
readonly
Returns the value of attribute steerfile.
-
.work_dir ⇒ Object
readonly
Returns the value of attribute work_dir.
Class Method Summary collapse
- .always_verbose? ⇒ Boolean
- .load(work_dir, use_steerfile: true) ⇒ Object
- .load_config ⇒ Object
-
.migrate_dotted_config_files ⇒ Object
Up until version 0.5.1, heighliner used dotfiles for all of it configuration.
Class Attribute Details
.config ⇒ Object (readonly)
Returns the value of attribute config.
9 10 11 |
# File 'lib/heighliner/config.rb', line 9 def config @config end |
.config_dir ⇒ Object (readonly)
Returns the value of attribute config_dir.
9 10 11 |
# File 'lib/heighliner/config.rb', line 9 def config_dir @config_dir end |
.config_file ⇒ Object (readonly)
Returns the value of attribute config_file.
9 10 11 |
# File 'lib/heighliner/config.rb', line 9 def config_file @config_file end |
.info_out ⇒ Object
Returns the value of attribute info_out.
6 7 8 |
# File 'lib/heighliner/config.rb', line 6 def info_out @info_out end |
.out ⇒ Object
Returns the value of attribute out.
6 7 8 |
# File 'lib/heighliner/config.rb', line 6 def out @out end |
.steerfile ⇒ Object (readonly)
Returns the value of attribute steerfile.
9 10 11 |
# File 'lib/heighliner/config.rb', line 9 def steerfile @steerfile end |
.work_dir ⇒ Object (readonly)
Returns the value of attribute work_dir.
9 10 11 |
# File 'lib/heighliner/config.rb', line 9 def work_dir @work_dir end |
Class Method Details
.always_verbose? ⇒ Boolean
62 63 64 |
# File 'lib/heighliner/config.rb', line 62 def always_verbose? @config[:always_verbose] end |
.load(work_dir, use_steerfile: true) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/heighliner/config.rb', line 15 def load(work_dir, use_steerfile: true) @work_dir = work_dir @config_dir = "#{ENV['HOME']}/.heighliner" migrate_dotted_config_files FileUtils.mkdir_p @config_dir @config_file = "#{@config_dir}/config.yml" @config = { envnames: {}, envs: {}, networkname: 'heighliner_net', shared_names: { nginx: 'heighliner-nginx', chrome: 'heighliner-chrome', dns: 'heighliner-dns', certs: 'heighliner-certs' }, largest_port: 9000, always_verbose: false } load_config if use_steerfile POSSIBLE_STEERFILES.each do |x| @fname = x if File.exist?(x) end Optimist.die <<~ERROR if @fname.nil? No Steerfile in current directory. Possible names are #{POSSIBLE_STEERFILES.join(', ')}" ERROR @steerfile = Steerfile.new("#{@work_dir}/#{@fname}") end @config end |
.load_config ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/heighliner/config.rb', line 81 def load_config loaded = YAML.load_file(@config_file) if File.exist?(@config_file) config_shared_names = @config[:shared_names] if @config loaded_shared_names = loaded[:shared_names] if loaded @config = { **(@config || {}), **(loaded || {}), shared_names: { **(config_shared_names || {}), **(loaded_shared_names || {}) } } end |
.migrate_dotted_config_files ⇒ Object
Up until version 0.5.1, heighliner used dotfiles for all of it configuration. It makes sense of hide the configuration directory itself but hiding the files inside of it just causes confusion.
Heighliner 0.5.2 started using non-dotted files instead. This method renames the old files in case you have just upgraded from an older version.
72 73 74 75 76 77 78 79 |
# File 'lib/heighliner/config.rb', line 72 def migrate_dotted_config_files return unless File.exist?("#{@config_dir}/.config.yml") Dir["#{@config_dir}/**/.*"].each do |x| dest = x.sub(%r{/\.([a-z.]+)$}, '/\1') FileUtils.mv x, dest end end |