Class: DEIS::Config
- Includes:
- Thor::Shell
- Defined in:
- lib/rdeis/config.rb
Direct Known Subclasses
Constant Summary
Constants inherited from Storage
Storage::BASE_PATH, Storage::ENV_VAR_PATH
Constants inherited from Base
Instance Attribute Summary collapse
-
#environment ⇒ Object
Returns the value of attribute environment.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Attributes inherited from Base
#cluster, #output, #path, #proxy, #ssh
Instance Method Summary collapse
- #add(vars) ⇒ Object
-
#export(vars) ⇒ Object
vars should just be the file name.
-
#import(vars) ⇒ Object
import from a file.
-
#initialize(options) ⇒ Config
constructor
A new instance of Config.
-
#list(vars = nil, show = true) ⇒ Object
output data using thors print_table & say.
- #remove(vars) ⇒ Object
- #results(message, error_message, data, colour) ⇒ Object
-
#set(vars) ⇒ Object
set config vars for the repo.
-
#unset(vars) ⇒ Object
remove vars.
Methods inherited from Storage
file, get, load, removal_complete, save, set, subset, subunset
Methods inherited from Base
#local_profile, #local_shell, #local_shell_env_include, #log, #remote_profile, #run
Constructor Details
#initialize(options) ⇒ Config
Returns a new instance of Config.
6 7 8 9 10 11 12 |
# File 'lib/rdeis/config.rb', line 6 def initialize() @repo = DEIS::Git.name @verbose = [:verbose] @environment = [:environment] @set_selector = self.class.to_s.downcase.gsub("deis::", "") @remove_selector = "removed_"+@set_selector end |
Instance Attribute Details
#environment ⇒ Object
Returns the value of attribute environment.
4 5 6 |
# File 'lib/rdeis/config.rb', line 4 def environment @environment end |
#verbose ⇒ Object
Returns the value of attribute verbose.
4 5 6 |
# File 'lib/rdeis/config.rb', line 4 def verbose @verbose end |
Instance Method Details
#add(vars) ⇒ Object
45 46 47 |
# File 'lib/rdeis/config.rb', line 45 def add(vars) self.set(vars) end |
#export(vars) ⇒ Object
vars should just be the file name
68 69 70 71 72 73 74 75 76 |
# File 'lib/rdeis/config.rb', line 68 def export(vars) raw = DEIS::Storage.load(@repo, @environment) if ! vars.nil? && vars.length > 0 && (file = vars.first) File.open(file, "w"){|f| f.write( raw.to_json ) } say "Data for #{@repo} -> #{@environment} written to #{file}", :green else say "Please specify a file path to export to", :red end end |
#import(vars) ⇒ Object
import from a file
79 80 81 82 83 84 85 86 87 |
# File 'lib/rdeis/config.rb', line 79 def import(vars) if !vars.nil? && vars.length > 0 && (file = vars.first) && (content = File.open(file, "r"){ |f| f.read } ) content = JSON.parse(content) DEIS::Storage.save(@repo, @environment, content) say "Data imported from #{file} into #{@repo} -> #{@environment}", :green else say "Please specify a valid file", :red end end |
#list(vars = nil, show = true) ⇒ Object
output data using thors print_table & say
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rdeis/config.rb', line 15 def list(vars=nil, show=true) data = DEIS::Storage.get(@repo, @environment, @set_selector) # if vars have been set then we filter the config data to matching keys if ! vars.nil? && vars.length > 0 keys = [] DEIS::Parse.var_array(vars).each { |f| keys.push(f[:k]) } data = data.select!{ |k,v| keys.include? (k) } end self.results("#{@set_selector} for #{@repo} -> #{@environment}", "No data found" ,data, :green) if ! show.nil? to_remove = DEIS::Storage.get(@repo, @environment, @remove_selector) self.results("\n\n#{@set_selector} to be removed", nil, to_remove, :blue) if ! show.nil? # return the data set return data end |
#remove(vars) ⇒ Object
63 64 65 |
# File 'lib/rdeis/config.rb', line 63 def remove(vars) self.unset(vars) end |
#results(message, error_message, data, colour) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/rdeis/config.rb', line 89 def results(, , data, colour) if ! data.nil? && data.length > 0 say , colour say "----------------------------------", colour print_table data say "----------------------------------", colour elsif ! .nil? say , colour say , :red end end |
#set(vars) ⇒ Object
set config vars for the repo
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rdeis/config.rb', line 32 def set(vars) if vars.nil? || vars.length == 0 say "Please provide a value", :red else set = {} DEIS::Parse.var_array(vars).each do |var| set[var[:k]] = var[:v] DEIS::Storage.subset(@repo, @environment, @set_selector, var[:k], var[:v]) end self.results("Setting #{@set_selector} for #{@repo} -> #{@environment}", "Error setting #{@set_selector}", set, :green) end end |
#unset(vars) ⇒ Object
remove vars
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/rdeis/config.rb', line 50 def unset(vars) if vars.nil? || vars.length == 0 say "Please enter a key to unset", :red else unset = {} DEIS::Parse.var_array(vars).each do |var| unset[var[:k]] = "\u2713" DEIS::Storage.subunset(@repo, @environment, @set_selector, var[:k]) end self.results("Removing #{@set_selector} for #{@repo} -> #{@environment}", "Error removing #{@set_selector}", unset, :green) end end |