module HasSubResources

HasSubResources provides methods for a object to contain subresources

Public Instance Methods

assign_block(name, *args, &block) click to toggle source

This overrides assign_block from HasAttributes when a block is passed to an attribute it becomes a SubResource

# File lib/geoengineer/utils/has_sub_resources.rb, line 7
def assign_block(name, *args, &block)
  sr = GeoEngineer::SubResource.new(self, name, &block)
  subresources << sr
  sr
end
attribute_missing(name) click to toggle source
# File lib/geoengineer/utils/has_sub_resources.rb, line 13
def attribute_missing(name)
  all = false
  if name.start_with?('all_')
    name = name[4..-1]
    all = true
  end
  srl = subresources.select { |s| s.type == name.to_s }

  if srl.empty?
    return [] if all
    return nil
  else
    return srl if all
    return srl.first
  end
end
delete_all_subresources(type) click to toggle source
# File lib/geoengineer/utils/has_sub_resources.rb, line 40
def delete_all_subresources(type)
  @_subresources = subresources.select { |s| s.type != type.to_s }
end
delete_subresources_where(&block) click to toggle source
# File lib/geoengineer/utils/has_sub_resources.rb, line 35
def delete_subresources_where(&block)
  # Only leave sub resources that dont
  @_subresources = subresources.reject(&block)
end
subresources() click to toggle source
# File lib/geoengineer/utils/has_sub_resources.rb, line 30
def subresources
  @_subresources = [] unless @_subresources
  @_subresources
end