Class: CrossOrigin::Collection::View
- Inherits:
-
Mongo::Collection::View
- Object
- Mongo::Collection::View
- CrossOrigin::Collection::View
- Defined in:
- lib/cross_origin/collection.rb
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
- #count(options = {}) ⇒ Object
- #cross_views ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(collection, selector, options, model) ⇒ View
constructor
A new instance of View.
- #new(options) ⇒ Object
Constructor Details
#initialize(collection, selector, options, model) ⇒ View
Returns a new instance of View.
20 21 22 23 |
# File 'lib/cross_origin/collection.rb', line 20 def initialize(collection, selector, , model) super(collection, selector, ) @model = model end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
18 19 20 |
# File 'lib/cross_origin/collection.rb', line 18 def model @model end |
Instance Method Details
#count(options = {}) ⇒ Object
32 33 34 |
# File 'lib/cross_origin/collection.rb', line 32 def count( = {}) super + ([:super] ? 0 : cross_views.inject(0) { |count, view| count + view.count }) end |
#cross_views ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/cross_origin/collection.rb', line 36 def cross_views views = [] skip, limit = self.skip, self.limit opts = previous_view = self count = 0 CrossOrigin.configurations.each do |config| if skip || limit opts = opts.dup count += previous_view.count(super: true, skip: 0) if skip opts[:skip] = skip = (count < skip ? skip - count : 0) end if limit current_skip = skip || 0 skipped_count = (current_skip > count ? 0 : count - current_skip) opts[:limit] = limit = (limit > skipped_count ? limit - skipped_count : 0) end end views << (previous_view = config.collection_for(model).find(selector, opts).modifiers(modifiers)) end views end |
#each(&block) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/cross_origin/collection.rb', line 25 def each(&block) if block super(&block) cross_views.each { |view| view.each(&block) } end end |
#new(options) ⇒ Object
60 61 62 |
# File 'lib/cross_origin/collection.rb', line 60 def new() View.new(collection, selector, , model) end |