| 
									
										
										
										
											2015-08-21 19:03:53 +03:00
										 |  |  | require "db/mongo/models/model_with_provider" | 
					
						
							| 
									
										
										
										
											2018-04-04 22:44:39 +03:00
										 |  |  | require "db/validators/name" | 
					
						
							| 
									
										
										
										
											2015-02-12 13:01:05 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-06 12:20:30 +03:00
										 |  |  | module Devops | 
					
						
							|  |  |  |   module Model | 
					
						
							| 
									
										
										
										
											2018-04-04 22:44:39 +03:00
										 |  |  |     class StackTemplateBase | 
					
						
							| 
									
										
										
										
											2015-02-12 13:01:05 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-04 22:44:39 +03:00
										 |  |  |       include ::Mongoid::Document | 
					
						
							|  |  |  |       include ::Mongoid::Timestamps::CreatedInt | 
					
						
							|  |  |  |       include ::ActiveModel::Validations | 
					
						
							| 
									
										
										
										
											2015-08-21 19:03:53 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-04 22:44:39 +03:00
										 |  |  |       store_in collection: "stack_templates" | 
					
						
							| 
									
										
										
										
											2015-11-03 11:46:54 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-04 22:44:39 +03:00
										 |  |  |       include ModelWithProviderAccount | 
					
						
							| 
									
										
										
										
											2015-11-03 11:46:54 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-04 22:44:39 +03:00
										 |  |  |       field :_id, as: :id, overwrite: true, type: String | 
					
						
							|  |  |  |       field :owner, type: String | 
					
						
							|  |  |  |       field :template_body, type: String | 
					
						
							|  |  |  |       # should be a hash like {'param_name' => {type: 'String', description: 'Description'}} | 
					
						
							|  |  |  |       field :available_parameters, type: Hash, default: {} | 
					
						
							| 
									
										
										
										
											2015-08-21 19:03:53 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-04 22:44:39 +03:00
										 |  |  |       validates :owner, :template_body, presence: true | 
					
						
							|  |  |  |       validates :id, uniqueness: true, on: :create | 
					
						
							|  |  |  |       validates :id, name: true, presence: true | 
					
						
							| 
									
										
										
										
											2015-02-12 13:01:05 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-04 22:44:39 +03:00
										 |  |  |       def to_hash | 
					
						
							|  |  |  |         attributes.tap { |hash| hash['id'] = hash.delete('_id') } | 
					
						
							| 
									
										
										
										
											2015-03-06 12:20:30 +03:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2015-02-12 13:01:05 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-28 18:15:06 +03:00
										 |  |  |       def parse_parameters | 
					
						
							|  |  |  |         {} | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-06 12:20:30 +03:00
										 |  |  |       # attrs should include: | 
					
						
							|  |  |  |       # - id (String) | 
					
						
							|  |  |  |       # - provider (String) | 
					
						
							| 
									
										
										
										
											2015-04-16 17:54:40 +03:00
										 |  |  |       # - template_body (String) | 
					
						
							| 
									
										
										
										
											2015-03-06 12:20:30 +03:00
										 |  |  |       def self.create(attrs) | 
					
						
							| 
									
										
										
										
											2016-01-28 18:15:06 +03:00
										 |  |  |         template = new(attrs) | 
					
						
							|  |  |  |         template.available_parameters = template.parse_parameters | 
					
						
							|  |  |  |         template | 
					
						
							| 
									
										
										
										
											2015-03-06 12:20:30 +03:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2015-02-12 13:01:05 +03:00
										 |  |  |   end | 
					
						
							|  |  |  | end |