Module: NeedsResources::ResourceContainer
- Included in:
- TopLevelResources
- Defined in:
- lib/needs_resources/resource_container.rb
Instance Method Summary collapse
- #[](name) ⇒ Object
- #__missing_resources__(missing) ⇒ Object
- #child_resource_name(child_name) ⇒ Object
- #missing_resources ⇒ Object
- #resources ⇒ Object
- #resources_needed ⇒ Object
Instance Method Details
#[](name) ⇒ Object
4 5 6 |
# File 'lib/needs_resources/resource_container.rb', line 4 def [](name) resources[name.to_sym] or raise MissingResourceError.new(child_resource_name name) end |
#__missing_resources__(missing) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/needs_resources/resource_container.rb', line 31 def __missing_resources__(missing) resources_needed.each do |name| if !resources[name] missing[self] = name elsif resources[name].is_a? ResourceContainer resources[name].__missing_resources__(missing) end end end |
#child_resource_name(child_name) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/needs_resources/resource_container.rb', line 8 def child_resource_name(child_name) if respond_to?(:name) "#{self.name}.#{child_name}" else child_name.to_s end end |
#missing_resources ⇒ Object
24 25 26 27 28 29 |
# File 'lib/needs_resources/resource_container.rb', line 24 def missing_resources __missing_resources__(missing = {}) missing.map do |k, v| k.child_resource_name(v) end.sort end |
#resources ⇒ Object
16 17 18 |
# File 'lib/needs_resources/resource_container.rb', line 16 def resources @resources ||= {} end |
#resources_needed ⇒ Object
20 21 22 |
# File 'lib/needs_resources/resource_container.rb', line 20 def resources_needed @resources_needed ||= Set.new end |