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

46 lines
1.2 KiB
Ruby
Raw Permalink Normal View History

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
def parse_parameters
{}
end
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)
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