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.
8 9 10 |
# File 'lib/travis/client/env_var.rb', line 8 def repository @repository end |
Instance Method Details
#[](key) ⇒ Object
54 55 56 57 |
# File 'lib/travis/client/env_var.rb', line 54 def [](key) return super if key.is_a? Integer detect { |e| e.name == key.to_s } end |
#[]=(key, value) ⇒ Object
59 60 61 62 |
# File 'lib/travis/client/env_var.rb', line 59 def []=(key, value) return super if key.is_a? Integer upsert(key.to_s, value) end |
#__getobj__ ⇒ Object Also known as: list
20 21 22 |
# File 'lib/travis/client/env_var.rb', line 20 def __getobj__ super || (self.list = @generator.call) end |
#add(name, value, options = {}) ⇒ Object
37 38 39 40 41 |
# File 'lib/travis/client/env_var.rb', line 37 def add(name, value, = {}) body = JSON.dump(:env_var => .merge(:name => name, :value => value)) result = session.post(EnvVar.path(self), body) self.list += [result['env_var']] end |
#list=(list) ⇒ Object
16 17 18 |
# File 'lib/travis/client/env_var.rb', line 16 def list=(list) __setobj__ list.dup.freeze end |
#reload ⇒ Object
24 25 26 27 |
# File 'lib/travis/client/env_var.rb', line 24 def reload __setobj__ nil self end |
#repository_id ⇒ Object
33 34 35 |
# File 'lib/travis/client/env_var.rb', line 33 def repository_id repository.id end |
#session ⇒ Object
29 30 31 |
# File 'lib/travis/client/env_var.rb', line 29 def session repository.session end |
#upsert(name, value, options = {}) ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/travis/client/env_var.rb', line 43 def upsert(name, value, = {}) entries = select { |e| e.name == name } if entries.any? entries.first.update(.merge(:value => value)) entries[1..-1].each { |e| e.delete } else add(name, value, ) end reload end |