Module: NoBrainer::Criteria::Enumerable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/no_brainer/criteria/enumerable.rb
Instance Method Summary collapse
- #close ⇒ Object
- #each(options = {}, &block) ⇒ Object
-
#method_missing(name, *args, &block) ⇒ Object
TODO Make something a bit more efficent ?.
-
#respond_to?(name, include_private = false) ⇒ Boolean
TODO test that.
- #to_a ⇒ Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
TODO Make something a bit more efficent ?
29 30 31 32 |
# File 'lib/no_brainer/criteria/enumerable.rb', line 29 def method_missing(name, *args, &block) return super unless [].respond_to?(name) to_a.__send__(name, *args, &block) end |
Instance Method Details
#close ⇒ Object
13 14 15 16 17 |
# File 'lib/no_brainer/criteria/enumerable.rb', line 13 def close @close_cursor = true @cursor.close if NoBrainer::Config.driver == :em self end |
#each(options = {}, &block) ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/no_brainer/criteria/enumerable.rb', line 4 def each(={}, &block) return enum_for(:each, ) unless block run.tap { |cursor| @cursor = cursor }.each do |attrs| return close if @close_cursor block.call(instantiate_doc(attrs)) end self end |
#respond_to?(name, include_private = false) ⇒ Boolean
TODO test that
24 25 26 |
# File 'lib/no_brainer/criteria/enumerable.rb', line 24 def respond_to?(name, include_private = false) super || [].respond_to?(name) end |
#to_a ⇒ Object
19 20 21 |
# File 'lib/no_brainer/criteria/enumerable.rb', line 19 def to_a each.to_a.freeze end |