Class: Map

Inherits:
Object show all
Includes:
DataMapper::Resource
Defined in:
lib/fabric/map.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.draw(opts = {}) {|map| ... } ⇒ Object

Yields:

  • (map)


22
23
24
25
26
27
28
# File 'lib/fabric/map.rb', line 22

def self.draw(opts = {})
  map = Map.create(opts)
  yield map if block_given?
  map.read!

  map
end

Instance Method Details

#expanded_key_repository_pathObject



45
46
47
48
# File 'lib/fabric/map.rb', line 45

def expanded_key_repository_path
  File.join(Fabric.options(:map_root), self.key_repository)
  # self.key_repository
end

#grant(user_names, role_names, role_conditions = {}) ⇒ Object

This method has become too long again…

Raises:

  • (DataMapper::ObjectNotFoundError)


67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/fabric/map.rb', line 67

def grant(user_names, role_names, role_conditions = {})
  users = self.users.all
  roles = self.roles.all
  
  users = users.all(:name => user_names) unless user_names == :all
  roles = roles.all(:name => role_names) unless role_names == :all

  if role_conditions.include?(:except)
    roles = roles.all(:name.not => role_conditions[:except])
  end
  
  if role_conditions.include?(:groups)
    role_conditions[:groups].each do |group|
      users.each do |user|
        user.groups.create(:name => group)
      end
    end
  end
  
  raise DataMapper::ObjectNotFoundError if users.empty? or roles.empty?
  
  roles.each do |role|
    role.users += users
  end
end

#key_repository(repo = nil) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/fabric/map.rb', line 37

def key_repository(repo = nil)
  if repo
    self.key_repository = repo
  end
  
  @key_repository
end

#namespace(&block) ⇒ Object



93
94
95
# File 'lib/fabric/map.rb', line 93

def namespace(&block)
  self.class.draw(:parent => self, &block)
end

#read!Object



30
31
32
33
34
35
# File 'lib/fabric/map.rb', line 30

def read!
  self.roles.all.each do |role|
    role.update_user_access!
  end
  true
end

#role(name, *hosts) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/fabric/map.rb', line 50

def role(name, *hosts)
  role = self.roles.create(:name => name.to_s)
  hosts.each do |host|
    role.servers.create(:host => host)
  end

  role.save
end

#user(*names) ⇒ Object



59
60
61
62
63
64
# File 'lib/fabric/map.rb', line 59

def user(*names)
  names.each do |name|
    user = self.users.create(:name => name.to_s)
    self.load_keys_from_repository(user)
  end
end