Class: Rubolite::Client

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/rubolite/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(admin) ⇒ Client

Returns a new instance of Client.



9
10
11
12
# File 'lib/rubolite/client.rb', line 9

def initialize(admin)
  @admin = admin
  @ssh_keys = {}
end

Instance Attribute Details

#adminObject (readonly)

Returns the value of attribute admin.



5
6
7
# File 'lib/rubolite/client.rb', line 5

def admin
  @admin
end

#ssh_keysObject (readonly)

Returns the value of attribute ssh_keys.



5
6
7
# File 'lib/rubolite/client.rb', line 5

def ssh_keys
  @ssh_keys
end

Instance Method Details

#add_group(name, users) ⇒ Object



22
23
24
# File 'lib/rubolite/client.rb', line 22

def add_group(name, users)
  groups[name] = users
end

#add_repo(repo) ⇒ Object



26
27
28
# File 'lib/rubolite/client.rb', line 26

def add_repo(repo)
  repos << repo
end

#add_ssh_key(user, ssh_key) ⇒ Object



30
31
32
# File 'lib/rubolite/client.rb', line 30

def add_ssh_key(user, ssh_key)
  ssh_keys[user] = ssh_key
end

#commit!Object



46
47
48
49
50
# File 'lib/rubolite/client.rb', line 46

def commit!
  return unless commitable?
  admin.git.add(".")
  admin.git.commit "Modified configuration by rubolite"
end

#commitable?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/rubolite/client.rb', line 70

def commitable?
  admin.git.status.changed.size > 0
end

#groupsObject



18
19
20
# File 'lib/rubolite/client.rb', line 18

def groups
  @groups ||= admin.parser.groups
end

#push!Object



52
53
54
# File 'lib/rubolite/client.rb', line 52

def push!
  admin.git.push(admin.repo_origin)
end

#reposObject



14
15
16
# File 'lib/rubolite/client.rb', line 14

def repos
  @repos ||= admin.parser.repos
end

#reset!Object



63
64
65
66
67
68
# File 'lib/rubolite/client.rb', line 63

def reset!
  admin.reset!
  @repos = nil
  @groups = nil
  @ssh_keys = {}
end

#save!Object



34
35
36
37
# File 'lib/rubolite/client.rb', line 34

def save!
  admin.writer.write!
  reset!
end

#save_and_push!Object



56
57
58
59
60
61
# File 'lib/rubolite/client.rb', line 56

def save_and_push!
  save!
  save_ssh_keys!
  commit!
  push!
end

#save_ssh_keys!Object



39
40
41
42
43
44
# File 'lib/rubolite/client.rb', line 39

def save_ssh_keys!
  ssh_keys.each do |user, key|
    key.write_for user, "#{admin.path}/keydir"
  end
  reset!
end