Created
November 27, 2012 14:44
-
-
Save mbj/4154585 to your computer and use it in GitHub Desktop.
Poor mans RA with dm-1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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).each 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 |
@dkubb, yeah this is a refactoring leftover, I started with map and than realized the each version with its lazyness is best... but did not changed the map. Thx for spotting!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@mbj you probably want to use each there not map since you don't want to return the block results.