travis-api/lib/travis/api/v3/models/env_var.rb
Joe Corcoran cae6da540f Add env vars endpoints
This adds API V3 endpoints for querying, creating, modifying and
deleting environment variables.

It has no concept of encryption yet and should be considered a work in
progress.

We should also talk about the slightly off-track approach in the
EnvVars::Create service – maybe there's a way to standardise the
querying and rendering for post requests?

2016-06-21 15:34:11 +02:00

19 lines
577 B
Ruby

module Travis::API::V3
class Models::EnvVar < Travis::Settings::Model
attribute :id, Integer
attribute :name, String
attribute :value, String
attribute :public, Boolean
attribute :repository_id, Integer
def repository
@repository ||= Models::Repository.find(repository_id)
end
validates_each :id, :name do |record, attr, value|
others = record.repository.env_vars.select { |ev| ev.id != record.id }
record.errors.add(:base, :duplicate_resource) if others.find { |ev| ev.send(attr) == record.send(attr) }
end
end
end