fluke/devops-service/db/mongo/models/deploy_env/deploy_env_base.rb

51 lines
1.3 KiB
Ruby
Raw Normal View History

2014-06-24 13:40:52 +04:00
require "db/mongo/models/mongo_model"
2015-02-12 13:01:05 +03:00
require "providers/provider_factory"
2015-08-04 12:36:10 +03:00
require "db/mongo/models/model_with_provider"
require "db/validators/deploy_env/run_list"
require "db/validators/deploy_env/expiration"
require "db/validators/deploy_env/users"
2014-06-24 13:40:52 +04:00
2015-03-06 12:20:30 +03:00
module Devops
module Model
class DeployEnvBase < MongoModel
2014-06-24 13:40:52 +04:00
2015-08-04 12:36:10 +03:00
include ModelWithProvider
2014-06-24 13:40:52 +04:00
attr_accessor :identifier, :run_list, :expires, :users
set_validators ::Validators::DeployEnv::RunList,
::Validators::DeployEnv::Expiration,
::Validators::DeployEnv::Users
2014-06-24 13:40:52 +04:00
2015-03-06 12:20:30 +03:00
def initialize d={}
self.identifier = d["identifier"]
b = d["run_list"] || []
self.run_list = b.uniq
2015-03-06 12:20:30 +03:00
self.expires = d["expires"]
self.provider = d["provider"]
b = d["users"] || []
self.users = b.uniq
2015-03-06 12:20:30 +03:00
end
2014-06-24 13:40:52 +04:00
2015-03-06 12:20:30 +03:00
def to_hash
{
"identifier" => self.identifier,
"run_list" => self.run_list,
"expires" => self.expires,
"provider" => self.provider,
"users" => self.users
}
end
2014-06-24 13:40:52 +04:00
2015-09-22 14:30:52 +03:00
def add_users users
self.users = (self.users + users).uniq
end
2015-03-06 12:20:30 +03:00
def build_error_message(message)
"Deploy environment '#{self.identifier}'. " + message
end
2015-02-12 13:01:05 +03:00
2015-03-06 12:20:30 +03:00
end
end
2014-06-24 13:40:52 +04:00
end