Class: Autoproj::Sync::Config
- Inherits:
-
Object
- Object
- Autoproj::Sync::Config
- Defined in:
- lib/autoproj/sync/config.rb
Instance Method Summary collapse
- #add_remote(remote) ⇒ Object
- #delete_remote(name) ⇒ Object
- #each_enabled_remote ⇒ Object
- #each_remote ⇒ Object
- #find_remote_by_name(name) ⇒ Object
-
#initialize(ws) ⇒ Config
constructor
A new instance of Config.
- #remote_by_name(name) ⇒ Object
- #update_remote_config(name) {|new_config| ... } ⇒ Object
Constructor Details
#initialize(ws) ⇒ Config
Returns a new instance of Config.
4 5 6 |
# File 'lib/autoproj/sync/config.rb', line 4 def initialize(ws) @ws = ws end |
Instance Method Details
#add_remote(remote) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/autoproj/sync/config.rb', line 53 def add_remote(remote) name, config = remote_to_config(remote) targets = @ws.config.get('sync', Hash.new) targets[name] = config @ws.config.set('sync', targets) @ws.save_config end |
#delete_remote(name) ⇒ Object
61 62 63 64 65 66 |
# File 'lib/autoproj/sync/config.rb', line 61 def delete_remote(name) targets = @ws.config.get('sync', Hash.new) targets.delete(name) @ws.config.set('sync', targets) @ws.save_config end |
#each_enabled_remote ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/autoproj/sync/config.rb', line 18 def each_enabled_remote return enum_for(__method__) unless block_given? each_remote do |remote| yield(remote) if remote.enabled? end end |
#each_remote ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/autoproj/sync/config.rb', line 8 def each_remote return enum_for(__method__) unless block_given? targets = @ws.config.get('sync', Hash.new) targets.each do |name, config| yield Remote.from_uri(URI.parse(config['uri']), name: name, enabled: config['enabled']) end end |
#find_remote_by_name(name) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/autoproj/sync/config.rb', line 34 def find_remote_by_name(name) targets = @ws.config.get('sync', Hash.new) if config = targets[name] remote_from_config(name, config) end end |
#remote_by_name(name) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/autoproj/sync/config.rb', line 26 def remote_by_name(name) unless remote = find_remote_by_name(name) raise ArgumentError, "no remote named '#{name}', "\ "existing remotes: #{each_remote.map(&:name).sort.join(", ")}" end remote end |
#update_remote_config(name) {|new_config| ... } ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/autoproj/sync/config.rb', line 68 def update_remote_config(name) targets = @ws.config.get('sync', Hash.new) unless (config = targets[name]) raise ArgumentError, "There is no target called #{name}" end new_config = config.dup yield(new_config) if new_config != config targets[name] = new_config @ws.config.set('sync', targets) @ws.save_config end end |