Class: KManager::Resources::ResourceSet

Inherits:
Object
  • Object
show all
Includes:
KLog::Logging
Defined in:
lib/k_manager/resources/resource_set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(area) ⇒ ResourceSet

Returns a new instance of ResourceSet.



35
36
37
38
# File 'lib/k_manager/resources/resource_set.rb', line 35

def initialize(area)
  @area = area
  @resources = []
end

Instance Attribute Details

#areaObject (readonly)

Returns the value of attribute area.



32
33
34
# File 'lib/k_manager/resources/resource_set.rb', line 32

def area
  @area
end

#resourcesObject (readonly)

Returns the value of attribute resources.



33
34
35
# File 'lib/k_manager/resources/resource_set.rb', line 33

def resources
  @resources
end

Instance Method Details

#add(resource) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/k_manager/resources/resource_set.rb', line 40

def add(resource)
  return log.warn "Resource already added: #{resource.resource_path}" if find(resource)

  resource.area = area
  resources << resource
  resource
end

#add_resources(resource_list) ⇒ Object



57
58
59
60
61
# File 'lib/k_manager/resources/resource_set.rb', line 57

def add_resources(resource_list)
  resource_list.each do |resource|
    add(resource)
  end
end

#debugObject



63
64
65
66
# File 'lib/k_manager/resources/resource_set.rb', line 63

def debug
  resources.each(&:debug)
  nil
end

#find_by_uri(resource_uri) ⇒ Object



68
69
70
# File 'lib/k_manager/resources/resource_set.rb', line 68

def find_by_uri(resource_uri)
  resources.find { |r| r.resource_path == resource_uri.path }
end

#replace(resource) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/k_manager/resources/resource_set.rb', line 48

def replace(resource)
  index = find_index(resource)
  return log.warn "Resource to replace does not exist: #{resource.resource_path}" unless index

  resource.area = area
  resources[index] = resource
  resource
end