Class: Travis::Client::EnvVar::List
- Inherits:
-
Array
- Object
- Array
- Travis::Client::EnvVar::List
- Defined in:
- lib/travis/client/env_var.rb
Instance Attribute Summary collapse
-
#repository ⇒ Object
readonly
Returns the value of attribute repository.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #__getobj__ ⇒ Object (also: #list)
- #add(name, value, options = {}) ⇒ Object
-
#initialize(repository, &block) ⇒ List
constructor
A new instance of List.
- #list=(list) ⇒ Object
- #reload ⇒ Object
- #repository_id ⇒ Object
- #session ⇒ Object
- #upsert(name, value, options = {}) ⇒ Object
Constructor Details
Instance Attribute Details
#repository ⇒ Object (readonly)
Returns the value of attribute repository.
10 11 12 |
# File 'lib/travis/client/env_var.rb', line 10 def repository @repository end |
Instance Method Details
#[](key) ⇒ Object
56 57 58 59 60 |
# File 'lib/travis/client/env_var.rb', line 56 def [](key) return super if key.is_a? Integer detect { |e| e.name == key.to_s } end |
#[]=(key, value) ⇒ Object
62 63 64 65 66 |
# File 'lib/travis/client/env_var.rb', line 62 def []=(key, value) return super if key.is_a? Integer upsert(key.to_s, value) end |
#__getobj__ ⇒ Object Also known as: list
22 23 24 |
# File 'lib/travis/client/env_var.rb', line 22 def __getobj__ super || (self.list = @generator.call) end |
#add(name, value, options = {}) ⇒ Object
39 40 41 42 43 |
# File 'lib/travis/client/env_var.rb', line 39 def add(name, value, = {}) body = JSON.dump(env_var: .merge(name:, value:)) result = session.post(EnvVar.path(self), body) self.list += [result['env_var']] end |
#list=(list) ⇒ Object
18 19 20 |
# File 'lib/travis/client/env_var.rb', line 18 def list=(list) __setobj__ list.dup.freeze end |
#reload ⇒ Object
26 27 28 29 |
# File 'lib/travis/client/env_var.rb', line 26 def reload __setobj__ nil self end |
#repository_id ⇒ Object
35 36 37 |
# File 'lib/travis/client/env_var.rb', line 35 def repository_id repository.id end |
#session ⇒ Object
31 32 33 |
# File 'lib/travis/client/env_var.rb', line 31 def session repository.session end |
#upsert(name, value, options = {}) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/travis/client/env_var.rb', line 45 def upsert(name, value, = {}) entries = select { |e| e.name == name } if entries.any? entries.first.update(.merge(value:)) entries[1..].each { |e| e.delete } else add(name, value, ) end reload end |