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, &block) ⇒ Object
- #fetch(name) ⇒ Object
-
#initialize(config) ⇒ Remotes
constructor
A new instance of Remotes.
Constructor Details
#initialize(config) ⇒ Remotes
Returns a new instance of Remotes.
15 16 17 |
# File 'lib/3scale_toolbox/remotes.rb', line 15 def initialize(config) @config = config end |
Class Method Details
.from_uri(uri_str) ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/3scale_toolbox/remotes.rb', line 4 def from_uri(uri_str) uri = Helper.parse_uri(uri_str) raise ThreeScaleToolbox::InvalidUrlError, "invalid url: #{uri_str}" unless uri.kind_of?(URI::HTTP) authentication = uri.user uri.user = '' { authentication: authentication, endpoint: uri.to_s } end |
Instance Method Details
#add(key, remote) ⇒ Object
34 35 36 37 38 |
# File 'lib/3scale_toolbox/remotes.rb', line 34 def add(key, remote) update do |rmts| rmts.tap { |r| r[key] = remote } end end |
#add_uri(name, uri) ⇒ Object
29 30 31 32 |
# File 'lib/3scale_toolbox/remotes.rb', line 29 def add_uri(name, uri) remote = self.class.from_uri(uri) add(name, remote) end |
#all ⇒ Object
Fetch remotes Perform validation
23 24 25 26 27 |
# File 'lib/3scale_toolbox/remotes.rb', line 23 def all rmts = (config.data :remotes) || {} raise_invalid unless validate(rmts) rmts end |
#delete(key, &block) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/3scale_toolbox/remotes.rb', line 40 def delete(key, &block) 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, &block) else r.delete(key) end end end value end |
#fetch(name) ⇒ Object
56 57 58 |
# File 'lib/3scale_toolbox/remotes.rb', line 56 def fetch(name) all.fetch(name) { raise_not_found(name) } end |