fluke/devops-service/db/mongo/models/stack_template/stack_template_base.rb

70 lines
2.2 KiB
Ruby
Raw Normal View History

2015-02-12 13:01:05 +03:00
require 'tempfile'
require 'securerandom'
2015-08-21 19:03:53 +03:00
require "db/mongo/models/model_with_provider"
2015-08-24 14:57:15 +03:00
require "db/validators/stack_template/template_content"
2015-02-12 13:01:05 +03:00
2015-03-06 12:20:30 +03:00
module Devops
module Model
class StackTemplateBase < MongoModel
2015-02-12 13:01:05 +03:00
2015-08-21 19:03:53 +03:00
include ModelWithProvider
2015-09-14 10:22:05 +03:00
attr_accessor :id, :template_body, :provider, :owner
2015-02-12 13:01:05 +03:00
2015-03-06 12:20:30 +03:00
types id: {type: String, empty: false},
provider: {type: String, empty: false},
2015-09-14 10:22:05 +03:00
template_body: {type: String, empty: false},
owner: {type: String, empty: false}
2015-02-12 13:01:05 +03:00
2015-12-04 12:43:07 +03:00
set_field_validators :id, [::Validators::FieldValidator::NotNil,
2015-11-03 11:46:54 +03:00
::Validators::FieldValidator::FieldType::String,
2015-12-04 12:43:07 +03:00
::Validators::FieldValidator::NotEmpty,]
::Validators::FieldValidator::Name
2015-11-03 11:46:54 +03:00
2015-12-04 12:43:07 +03:00
set_field_validators :provider, [::Validators::FieldValidator::NotNil,
2015-11-03 11:46:54 +03:00
::Validators::FieldValidator::FieldType::String,
2015-12-04 12:43:07 +03:00
::Validators::FieldValidator::NotEmpty]
2015-11-03 11:46:54 +03:00
2015-12-04 12:43:07 +03:00
set_field_validators :template_body, [::Validators::FieldValidator::NotNil,
2015-11-03 11:46:54 +03:00
::Validators::FieldValidator::FieldType::String,
2015-12-04 12:43:07 +03:00
::Validators::FieldValidator::NotEmpty]
2015-11-03 11:46:54 +03:00
2015-12-04 12:43:07 +03:00
set_field_validators :owner, [::Validators::FieldValidator::NotNil,
2015-11-03 11:46:54 +03:00
::Validators::FieldValidator::FieldType::String,
2015-12-04 12:43:07 +03:00
::Validators::FieldValidator::NotEmpty]
2015-11-03 11:46:54 +03:00
2015-08-21 19:03:53 +03:00
set_validators ::Validators::StackTemplate::TemplateContent
2015-03-06 12:20:30 +03:00
def initialize(attrs)
self.id = attrs['id']
self.template_body = attrs['template_body']
2015-03-06 12:20:30 +03:00
self.provider = attrs['provider']
2015-09-14 10:22:05 +03:00
self.owner = attrs['owner']
2015-03-06 12:20:30 +03:00
self
end
2015-02-12 13:01:05 +03:00
2015-03-06 12:20:30 +03:00
def to_hash_without_id
{
provider: provider,
2015-09-14 10:22:05 +03:00
template_body: template_body,
owner: owner
2015-03-06 12:20:30 +03:00
}
end
2015-02-12 13:01:05 +03:00
2015-03-06 12:20:30 +03:00
# attrs should include:
# - id (String)
# - provider (String)
# - template_body (String)
2015-03-06 12:20:30 +03:00
def self.create(attrs)
new(attrs)
end
2015-02-12 13:01:05 +03:00
2015-03-06 12:20:30 +03:00
def self.build_from_bson(attrs)
attrs['id'] = attrs["_id"]
self.new(attrs)
end
2015-02-12 13:01:05 +03:00
2015-03-06 12:20:30 +03:00
end
2015-02-12 13:01:05 +03:00
end
end