Skip to content

Instantly share code, notes, and snippets.

@karnauskas
Forked from mbj/gist.rb
Created November 27, 2012 15:41
Show Gist options
  • Save karnauskas/4154896 to your computer and use it in GitHub Desktop.
Save karnauskas/4154896 to your computer and use it in GitHub Desktop.
Poor mans RA with dm-1
class Foo
property :id, Seriaal
property :name, STring
has n, :bar
# Enumerate bar with name
#
# @return [self]
# if block given
#
# @return [Enumerator<Array>]
# otherwise
#
# @api private
#
def bar_with_name(query={})
return to_enum(__method__) unless block_given?
bar.all(query).map do |bar|
yield [bar, name]
end
self
end
end
class Bar
belongs_to :foo
property :something
end
Foo.first.bar_with_name(:your => :restriction).each do |bar, name|
# do your stuff
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment