Class: ThreeScaleToolbox::Remotes

Inherits:
Object
  • Object
show all
Defined in:
lib/3scale_toolbox/remotes.rb

Class Method Summary collapse

Instance Method Summary collapse

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

.from_uri(uri_str) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/3scale_toolbox/remotes.rb', line 4

def from_uri(uri_str)
  uri = Helper.parse_uri(uri_str)

  authentication = uri.user
  uri.user = ''
  { authentication: authentication, endpoint: uri.to_s }
end

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

#allObject

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