lib/travis/client/env_var.rb in travis-1.11.1 vs lib/travis/client/env_var.rb in travis-1.12.0
- old
+ new
@@ -1,5 +1,7 @@
+# frozen_string_literal: true
+
require 'travis/client'
require 'delegate'
module Travis
module Client
@@ -33,42 +35,45 @@
def repository_id
repository.id
end
def add(name, value, options = {})
- body = JSON.dump(:env_var => options.merge(:name => name, :value => value))
+ body = JSON.dump(env_var: options.merge(name:, value:))
result = session.post(EnvVar.path(self), body)
self.list += [result['env_var']]
end
def upsert(name, value, options = {})
entries = select { |e| e.name == name }
if entries.any?
- entries.first.update(options.merge(:value => value))
- entries[1..-1].each { |e| e.delete }
+ entries.first.update(options.merge(value:))
+ entries[1..].each { |e| e.delete }
else
add(name, value, options)
end
reload
end
def [](key)
return super if key.is_a? Integer
+
detect { |e| e.name == key.to_s }
end
def []=(key, value)
return super if key.is_a? Integer
+
upsert(key.to_s, value)
end
alias list __getobj__
end
def self.path(object)
- repository_id = Repository === object ? object.id : object.repository_id
- raise "repository unknown" unless repository_id
+ repository_id = object.is_a?(Repository) ? object.id : object.repository_id
+ raise 'repository unknown' unless repository_id
+
"/settings/env_vars/#{object.id if object.is_a? EnvVar}?repository_id=#{repository_id}"
end
include NotLoadable
extend HasUuid
@@ -80,12 +85,12 @@
# @!parse attr_reader :repository
has :repository
def update(options)
- options = { :value => options } unless options.is_a? Hash
- result = session.patch(EnvVar.path(self), JSON.dump(:env_var => options))
+ options = { value: options } unless options.is_a? Hash
+ result = session.patch(EnvVar.path(self), JSON.dump(env_var: options))
attributes.replace(result['env_var'].attributes)
self
end
def delete
@@ -93,10 +98,10 @@
repository.env_vars.reload
true
end
def inspect_info
- "#{name}=#{value ? value.inspect : "[secure]"}"
+ "#{name}=#{value ? value.inspect : '[secure]'}"
end
end
end
end