Class: BBC::Cosmos::Tools::Commands::Config
- Defined in:
- lib/bbc/cosmos/tools/commands/config.rb
Instance Attribute Summary collapse
-
#cosmos_config ⇒ Object
Returns the value of attribute cosmos_config.
Attributes inherited from Base
Instance Method Summary collapse
- #generate(component) ⇒ Object
-
#initialize(args = [], local_options = {}, thor_config = {}) ⇒ Config
constructor
A new instance of Config.
- #list ⇒ Object
- #push(component_id = nil) ⇒ Object
Constructor Details
#initialize(args = [], local_options = {}, thor_config = {}) ⇒ Config
Returns a new instance of Config.
14 15 16 17 |
# File 'lib/bbc/cosmos/tools/commands/config.rb', line 14 def initialize(args = [], = {}, thor_config = {}) super(args, , thor_config) @cosmos_config = BBC::Cosmos::Tools::CosmosConfiguration.new(config) end |
Instance Attribute Details
#cosmos_config ⇒ Object
Returns the value of attribute cosmos_config.
12 13 14 |
# File 'lib/bbc/cosmos/tools/commands/config.rb', line 12 def cosmos_config @cosmos_config end |
Instance Method Details
#generate(component) ⇒ Object
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 |
# File 'lib/bbc/cosmos/tools/commands/config.rb', line 23 def generate(component) if [:write] File.open("#{component}.json", "w") do |f| f.write(JSON.pretty_generate(cosmos_config.component(component))) end end if [:output] == "machine" say JSON.pretty_generate(cosmos_config.cosmos_component(component)), :white exit 0 end begin say "#{(component)}\n" if [:cosmos_format] say JSON.pretty_generate(cosmos_config.cosmos_component(component)), :white else say JSON.pretty_generate(cosmos_config.component(component)), :white end rescue Exception => e error e. end end |
#list ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/bbc/cosmos/tools/commands/config.rb', line 52 def list if [:output] == "machine" cosmos_config.component_keys.each do |component_id| puts "#{component_id}" end exit 0 end begin say say "\n#{get_key_value('Components', '')}\n" cosmos_config.component_keys.each do |component_id| say "* #{component_id}", :white end rescue Exception => e error e. end end |
#push(component_id = nil) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/bbc/cosmos/tools/commands/config.rb', line 76 def push(component_id = nil) components = component_id.nil? ? cosmos_config.component_keys : [component_id] say "#{}\n" reply = yes?("Are you sure you want to push changes for #{components.length} components(s) to #{[:env]}?", :yellow) unless [:force] if reply || reply.nil? components.each do |id| say "\n#{get_key_value('Component', id)}\n" component_config = JSON.generate(cosmos_config.cosmos_component id) @api = BBC::Cosmos::Tools::API.new(config.app["api"], [:key_path]) response = @api.put sprintf(config.app["config_endpoint"], [:env], id), component_config if response.success? say "Successfully saved", :green else api_error response end end else error "Action cancelled" end rescue Exception => e error e. end |