Class: BBC::Cosmos::Tools::Config::App
- Inherits:
-
Thor
- Object
- Thor
- BBC::Cosmos::Tools::Config::App
- Includes:
- Thor::Actions
- Defined in:
- lib/bbc/cosmos/tools/config/app.rb
Instance Method Summary collapse
- #generate(project, component_id) ⇒ Object
-
#initialize(args = [], local_options = {}, config = {}) ⇒ App
constructor
A new instance of App.
- #list(project) ⇒ Object
- #push(project, key_path = nil, component_id = nil) ⇒ Object
Constructor Details
#initialize(args = [], local_options = {}, config = {}) ⇒ App
Returns a new instance of App.
15 16 17 |
# File 'lib/bbc/cosmos/tools/config/app.rb', line 15 def initialize(args = [], = {}, config = {}) super(args, , config) end |
Instance Method Details
#generate(project, component_id) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/bbc/cosmos/tools/config/app.rb', line 24 def generate(project, component_id) begin config_base([:config]) config = config_from(project, [:env]) say "\nComponent: #{component_id}\nProject: #{project}\nEnvironement: #{options[:env]}\n", :green if [:cosmos_format] say JSON.pretty_generate(config.generate_cosmos component_id) else say JSON.pretty_generate(config.generate component_id) end rescue Exception => e error e. end end |
#list(project) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/bbc/cosmos/tools/config/app.rb', line 44 def list(project) begin config_base([:config]) config = config_from(project, [:env]) say "\nComponents: \n", :green config.components.each do |component_id| say "#{component_id}", :blue end rescue Exception => e error e. end end |
#push(project, key_path = nil, component_id = nil) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/bbc/cosmos/tools/config/app.rb', line 62 def push(project, key_path = nil, component_id = nil) begin config_base([:config]) config = config_from(project, [:env]) components = component_id.nil? ? config.components : [component_id] reply = yes?("Are you sure you want to push changes for #{components.length} components(s) to #{options[:env]}?", :blue) unless [:force] if reply || reply.nil? components.each do |id| cosmos_config = JSON.generate(config.generate_cosmos id) @api = BBC::Cosmos::Tools::Config::API.new(app_config['api'], key_path) response = @api.put sprintf(app_config['endpoint'], [:env], id), cosmos_config if response.success? say "Configuration for component '#{id}' successfully saved", :green else say "There was an error saving your config: #{response.body}", :red end end else say "Action cancelled", :red end rescue Exception => e error e. end end |