mongoid_criteria_filter 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7ccb1e7d9287a5f06206f931ef412e2dc61e981e
4
+ data.tar.gz: 1754aefeb5c11360b9b1ebc515098f9af59624ad
5
+ SHA512:
6
+ metadata.gz: 49df718323b5f297a01e7d6cd433ca65aea7078af83ad79a57bd04d8f78ef6c8daab703a010ac13565e3898cd98ae1c1cf9e8d6fe901588b71146f100860bc71
7
+ data.tar.gz: 88490f653ff02f904f3c4d8933fb1e3f64843a23733e10ade07a06944a48560899097478e33a233572499ca8ad818e6933218bfd8cbdecb2e5fec373215e95c8
@@ -0,0 +1,30 @@
1
+ # encoding: utf-8
2
+ module Mongoid
3
+ class Criteria
4
+
5
+ def add_filter(&block)
6
+ filter_callbacks << block
7
+ self
8
+ end
9
+
10
+ def each
11
+ sort_with_position(super(){}).each do |doc|
12
+ yield(doc) if block_given?
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def sort_with_position(items)
19
+ filter_callbacks.each do |filter_callback|
20
+ items = filter_callback.call items
21
+ end unless has_additional_order?
22
+ items
23
+ end
24
+
25
+ def filter_callbacks
26
+ @filter_callbacks ||= []
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+ module Origin
3
+ module Optional
4
+
5
+ alias_method :original_order_by, :order_by
6
+
7
+ def order_by(*spec)
8
+ @additional_order = (not klass.default_scopable? or scoped?)
9
+ original_order_by(*spec)
10
+ end
11
+
12
+ def has_additional_order?
13
+ defined?(@additional_order) ? @additional_order : false
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ require 'rails'
2
+ require 'mongoid'
3
+
4
+ require 'initializers/criteria'
5
+ require 'initializers/origin_optional'
6
+
7
+ module MongoidCriteriaFilter
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mongoid_criteria_filter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Vladislav Melanitskiy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mongoid
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '4.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '4.0'
41
+ description: It adds possibility for criteria callbacks (data filters)
42
+ email:
43
+ - co@rademade.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - lib/initializers/criteria.rb
49
+ - lib/initializers/origin_optional.rb
50
+ - lib/mongoid_criteria_filter.rb
51
+ homepage: https://github.com/Rademade/mongoid_criteria_filter
52
+ licenses:
53
+ - MIT
54
+ metadata: {}
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubyforge_project:
71
+ rubygems_version: 2.2.2
72
+ signing_key:
73
+ specification_version: 4
74
+ summary: Extension for mongoid.
75
+ test_files: []