Class: ThreeScaleToolbox::Remotes
- Inherits:
-
Object
- Object
- ThreeScaleToolbox::Remotes
- Defined in:
- lib/3scale_toolbox/remotes.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add(key, remote) ⇒ Object
- #add_uri(name, uri) ⇒ Object
-
#all ⇒ Object
Fetch remotes Perform validation.
- #delete(key) ⇒ Object
- #fetch(name) ⇒ Object
-
#initialize(config) ⇒ Remotes
constructor
A new instance of Remotes.
Constructor Details
#initialize(config) ⇒ Remotes
Returns a new instance of Remotes.
13 14 15 |
# File 'lib/3scale_toolbox/remotes.rb', line 13 def initialize(config) @config = config end |
Class Method Details
Instance Method Details
#add(key, remote) ⇒ Object
32 33 34 35 36 |
# File 'lib/3scale_toolbox/remotes.rb', line 32 def add(key, remote) update do |rmts| rmts.tap { |r| r[key] = remote } end end |
#add_uri(name, uri) ⇒ Object
27 28 29 30 |
# File 'lib/3scale_toolbox/remotes.rb', line 27 def add_uri(name, uri) remote = self.class.from_uri(uri) add(name, remote) end |
#all ⇒ Object
Fetch remotes Perform validation
21 22 23 24 25 |
# File 'lib/3scale_toolbox/remotes.rb', line 21 def all rmts = (config.data :remotes) || {} raise_invalid unless validate(rmts) rmts end |
#delete(key) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/3scale_toolbox/remotes.rb', line 38 def delete(key) value = nil update do |rmts| # block should return rmts # but main method should return deleted value rmts.tap do |r| value = if block_given? r.delete(key, &Proc.new) else r.delete(key) end end end value end |
#fetch(name) ⇒ Object
54 55 56 |
# File 'lib/3scale_toolbox/remotes.rb', line 54 def fetch(name) all.fetch(name) { raise_not_found(name) } end |