travis-api/lib/travis/api/v3/models/settings.rb
Joe Corcoran daf534edb7 Don't overwrite settings with defaults
Also changes the way the JSON fields are set to force ActiveRecord
to recognise the changes. Is there a better way?
2016-06-08 17:13:05 +02:00

32 lines
647 B
Ruby

module Travis::API::V3
class Models::Settings
attr_reader :repository
def initialize(repository)
@repository = repository
end
def to_h
defaults.merge(repository.settings || {})
end
def update(settings = {})
settings = to_h.merge(settings)
repository.settings.clear
settings.each { |k, v| repository.settings[k] = v }
repository.save!
end
private
def defaults
{
'builds_only_with_travis_yml' => false,
'build_pushes' => true,
'build_pull_requests' => true,
'maximum_number_of_builds' => 0
}
end
end
end