module Parxer::InheritedResource

Public Instance Methods

for_each_ancestor_with_method(object, method_name, &block) click to toggle source
# File lib/parxer/utils/inherited_resource.rb, line 23
def for_each_ancestor_with_method(object, method_name, &block)
  object_ancestors(object).each do |klass|
    next unless klass.respond_to?(method_name)
    block.call(klass.send(method_name))
  end
end
inherited_collection(object, method_name, collection_class) click to toggle source
# File lib/parxer/utils/inherited_resource.rb, line 3
def inherited_collection(object, method_name, collection_class)
  result = collection_class.new

  for_each_ancestor_with_method(object, method_name) do |collection|
    collection.each { |item| result << item }
  end

  result
end
inherited_hash(object, method_name) click to toggle source
# File lib/parxer/utils/inherited_resource.rb, line 13
def inherited_hash(object, method_name)
  result = {}

  for_each_ancestor_with_method(object, method_name) do |hash|
    result.merge!(hash)
  end

  result
end
object_ancestors(object) click to toggle source
# File lib/parxer/utils/inherited_resource.rb, line 30
def object_ancestors(object)
  klass = object.is_a?(Class) ? object : object.class
  klass.ancestors.grep(Class).reverse
end