| 
									
										
										
										
											2015-08-13 15:49:37 +03:00
										 |  |  | module Validators | 
					
						
							|  |  |  |   class DeployEnv::StackTemplate < Base | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def valid? | 
					
						
							| 
									
										
										
										
											2015-11-03 11:46:54 +03:00
										 |  |  |       return true unless @model.stack_template | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       available_stack_templates.detect do |template| | 
					
						
							|  |  |  |         template['id'] == @model.stack_template | 
					
						
							| 
									
										
										
										
											2015-08-13 15:49:37 +03:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def message | 
					
						
							|  |  |  |       "Invalid stack template '#{@model.stack_template}'." | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2015-11-03 11:46:54 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |     private | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def available_stack_templates | 
					
						
							|  |  |  |       # map to hash to simplify mocks. Later replace this method with something more suitable | 
					
						
							|  |  |  |       Devops::Db.connector.stack_templates.map(&:to_hash) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-13 15:49:37 +03:00
										 |  |  |   end | 
					
						
							|  |  |  | end |