Module: Octo::Profile

Included in:
Octo
Defined in:
lib/octo/profile.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



4
5
6
# File 'lib/octo/profile.rb', line 4

def config
  @config
end

Instance Method Details

#add(type, profile, server) ⇒ Object



28
29
30
31
# File 'lib/octo/profile.rb', line 28

def add(type, profile, server)
  @config[type][profile] = [] if @config[type][profile].nil?
  @config[type][profile] << server
end

#config_fileObject



6
7
8
# File 'lib/octo/profile.rb', line 6

def config_file
  "#{Dir.home}/.octorc"
end

#list(type, profile = nil) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/octo/profile.rb', line 14

def list(type, profile = nil)
  if profile.nil?
    @config[type].keys
  else
    @config[type].each do |name, servers|
      if name == profile
        return servers
      end
    end

    return nil
  end
end

#loadObject



38
39
40
41
42
43
44
# File 'lib/octo/profile.rb', line 38

def load
  if File.exists?(config_file)
    @config = YAML.load_file(config_file)
  else
    @config = {}
  end
end

#profile_exists?(type, profile) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/octo/profile.rb', line 10

def profile_exists?(type, profile)
  @config[type].keys.include? profile
end

#rm(type, profile, server) ⇒ Object



33
34
35
36
# File 'lib/octo/profile.rb', line 33

def rm(type, profile, server)
  @config[type][profile].delete(server)
  @config[type].delete(profile) if @config[type][profile].empty?
end

#saveObject



46
47
48
49
50
# File 'lib/octo/profile.rb', line 46

def save
  File.open(config_file, 'w') do |f|
    f.write YAML.dump(@config)
  end
end