origin 0.0.0.alpha → 1.0.0.alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. data/Rakefile +3 -0
  2. data/lib/origin.rb +3 -4
  3. data/lib/origin/extensions.rb +25 -0
  4. data/lib/origin/extensions/array.rb +153 -0
  5. data/lib/origin/extensions/big_decimal.rb +33 -0
  6. data/lib/origin/extensions/boolean.rb +30 -0
  7. data/lib/origin/extensions/date.rb +59 -0
  8. data/lib/origin/extensions/date_time.rb +44 -0
  9. data/lib/origin/extensions/hash.rb +180 -0
  10. data/lib/origin/extensions/nil_class.rb +82 -0
  11. data/lib/origin/extensions/numeric.rb +86 -0
  12. data/lib/origin/extensions/object.rb +182 -0
  13. data/lib/origin/extensions/range.rb +66 -0
  14. data/lib/origin/extensions/regexp.rb +41 -0
  15. data/lib/origin/extensions/set.rb +28 -0
  16. data/lib/origin/extensions/string.rb +100 -0
  17. data/lib/origin/extensions/symbol.rb +74 -0
  18. data/lib/origin/extensions/time.rb +44 -0
  19. data/lib/origin/extensions/time_with_zone.rb +50 -0
  20. data/lib/origin/forwardable.rb +57 -0
  21. data/lib/origin/key.rb +74 -0
  22. data/lib/origin/macroable.rb +23 -0
  23. data/lib/origin/mergeable.rb +226 -0
  24. data/lib/origin/optional.rb +314 -29
  25. data/lib/origin/options.rb +64 -1
  26. data/lib/origin/queryable.rb +55 -12
  27. data/lib/origin/selectable.rb +613 -0
  28. data/lib/origin/selector.rb +140 -1
  29. data/lib/origin/smash.rb +85 -0
  30. data/lib/origin/version.rb +1 -1
  31. metadata +94 -62
  32. data/lib/origin/ext.rb +0 -5
  33. data/lib/origin/ext/array.rb +0 -21
  34. data/lib/origin/ext/hash.rb +0 -38
  35. data/lib/origin/ext/nil.rb +0 -9
  36. data/lib/origin/ext/object.rb +0 -25
  37. data/lib/origin/optional/batch_size.rb +0 -11
  38. data/lib/origin/optional/hint.rb +0 -15
  39. data/lib/origin/optional/limit.rb +0 -11
  40. data/lib/origin/optional/max_scan.rb +0 -11
  41. data/lib/origin/optional/no_timeout.rb +0 -11
  42. data/lib/origin/optional/only.rb +0 -15
  43. data/lib/origin/optional/read.rb +0 -11
  44. data/lib/origin/optional/return_key.rb +0 -11
  45. data/lib/origin/optional/show_disk_loc.rb +0 -11
  46. data/lib/origin/optional/skip.rb +0 -11
  47. data/lib/origin/optional/slice.rb +0 -17
  48. data/lib/origin/optional/snapshot.rb +0 -13
  49. data/lib/origin/optional/transformer.rb +0 -11
  50. data/lib/origin/optional/without.rb +0 -15
  51. data/lib/origin/selection.rb +0 -59
  52. data/lib/origin/selection/all.rb +0 -18
  53. data/lib/origin/selection/and.rb +0 -11
  54. data/lib/origin/selection/between.rb +0 -16
  55. data/lib/origin/selection/elem_match.rb +0 -18
  56. data/lib/origin/selection/exists.rb +0 -18
  57. data/lib/origin/selection/gt.rb +0 -18
  58. data/lib/origin/selection/gte.rb +0 -18
  59. data/lib/origin/selection/in.rb +0 -18
  60. data/lib/origin/selection/key.rb +0 -20
  61. data/lib/origin/selection/lt.rb +0 -18
  62. data/lib/origin/selection/lte.rb +0 -18
  63. data/lib/origin/selection/max_distance.rb +0 -11
  64. data/lib/origin/selection/mod.rb +0 -18
  65. data/lib/origin/selection/ne.rb +0 -18
  66. data/lib/origin/selection/near.rb +0 -18
  67. data/lib/origin/selection/near_sphere.rb +0 -18
  68. data/lib/origin/selection/nin.rb +0 -18
  69. data/lib/origin/selection/nor.rb +0 -11
  70. data/lib/origin/selection/or.rb +0 -11
  71. data/lib/origin/selection/size.rb +0 -18
  72. data/lib/origin/selection/strategies.rb +0 -40
  73. data/lib/origin/selection/strategies/add.rb +0 -18
  74. data/lib/origin/selection/strategies/expanded.rb +0 -15
  75. data/lib/origin/selection/strategies/intersect.rb +0 -22
  76. data/lib/origin/selection/strategies/multi.rb +0 -21
  77. data/lib/origin/selection/strategies/override.rb +0 -19
  78. data/lib/origin/selection/strategies/union.rb +0 -22
  79. data/lib/origin/selection/type.rb +0 -18
  80. data/lib/origin/selection/where.rb +0 -29
  81. data/lib/origin/selection/within_box.rb +0 -18
  82. data/lib/origin/selection/within_circle.rb +0 -18
  83. data/lib/origin/selection/within_spherical_circle.rb +0 -18
@@ -1,21 +0,0 @@
1
- # encoding: utf-8
2
- class Array
3
-
4
- def _add(object)
5
- if object.is_a?(Hash)
6
- object[object.keys.first] = _add(object.values.first)
7
- object
8
- else
9
- concat(Array(object)).uniq
10
- end
11
- end
12
-
13
- def _intersect(object)
14
- if object.is_a?(Hash)
15
- object[object.keys.first] = _intersect(object.values.first)
16
- object
17
- else
18
- self & Array(object)
19
- end
20
- end
21
- end
@@ -1,38 +0,0 @@
1
- # encoding: utf-8
2
- class Hash
3
-
4
- def _add(object)
5
- apply_strategy(:_add, object)
6
- end
7
-
8
- def _intersect(object)
9
- apply_strategy(:_intersect, object)
10
- end
11
-
12
- def _union(object)
13
- apply_strategy(:_union, object)
14
- end
15
-
16
- def deep_copy
17
- inject({}) do |copy, (key, value)|
18
- copy.tap do |clone|
19
- case value
20
- when Array, String then clone.store(key, value.dup)
21
- when Hash then clone.store(key, value.deep_copy)
22
- else
23
- clone.store(key, value)
24
- end
25
- end
26
- end
27
- end
28
-
29
- private
30
-
31
- def apply_strategy(strategy, object)
32
- tap do |hash|
33
- object.each_pair do |key, value|
34
- hash.store(key, hash[key].send(strategy, value))
35
- end
36
- end
37
- end
38
- end
@@ -1,9 +0,0 @@
1
- # encoding: utf-8
2
- class NilClass
3
-
4
- def _add(object); object end
5
-
6
- def _intersect(object); object end
7
-
8
- def _union(object); object end
9
- end
@@ -1,25 +0,0 @@
1
- # encoding: utf-8
2
- class Object
3
-
4
- def _add(object)
5
- object == self ? self : [ self, object ].flatten.uniq
6
- end
7
-
8
- def _intersect(object)
9
- if object.is_a?(Hash)
10
- object[object.keys.first] = _intersect(object.values.first)
11
- object
12
- else
13
- Array(self) & Array(object)
14
- end
15
- end
16
-
17
- def _union(object)
18
- if object.is_a?(Hash)
19
- object[object.keys.first] = _union(object.values.first)
20
- object
21
- else
22
- (Array(self) + Array(object)).uniq
23
- end
24
- end
25
- end
@@ -1,11 +0,0 @@
1
- # encoding: utf-8
2
- module Origin
3
- module Optional
4
- module BatchSize
5
-
6
- def batch_size(value = nil)
7
- option(value) { |options| options.store(:batch_size, value) }
8
- end
9
- end
10
- end
11
- end
@@ -1,15 +0,0 @@
1
- # encoding: utf-8
2
- module Origin
3
- module Optional
4
- module Hint
5
-
6
- def hint(*args)
7
- option(*args) do |options|
8
- options.store(
9
- :hint, args.inject({}){ |sub, field| sub.tap { sub[field] = 1 }}
10
- )
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,11 +0,0 @@
1
- # encoding: utf-8
2
- module Origin
3
- module Optional
4
- module Limit
5
-
6
- def limit(value = nil)
7
- option(value) { |options| options.store(:limit, value) }
8
- end
9
- end
10
- end
11
- end
@@ -1,11 +0,0 @@
1
- # encoding: utf-8
2
- module Origin
3
- module Optional
4
- module MaxScan
5
-
6
- def max_scan(value = nil)
7
- option(value) { |options| options.store(:max_scan, value) }
8
- end
9
- end
10
- end
11
- end
@@ -1,11 +0,0 @@
1
- # encoding: utf-8
2
- module Origin
3
- module Optional
4
- module NoTimeout
5
-
6
- def no_timeout
7
- clone.tap { |query| query.options.store(:timeout, false) }
8
- end
9
- end
10
- end
11
- end
@@ -1,15 +0,0 @@
1
- # encoding: utf-8
2
- module Origin
3
- module Optional
4
- module Only
5
-
6
- def only(*args)
7
- option(*args) do |options|
8
- options.store(
9
- :fields, args.inject({}){ |sub, field| sub.tap { sub[field] = 1 }}
10
- )
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,11 +0,0 @@
1
- # encoding: utf-8
2
- module Origin
3
- module Optional
4
- module Read
5
-
6
- def read(node = nil)
7
- option(node) { |options| options.store(:read, node) }
8
- end
9
- end
10
- end
11
- end
@@ -1,11 +0,0 @@
1
- # encoding: utf-8
2
- module Origin
3
- module Optional
4
- module ReturnKey
5
-
6
- def return_key
7
- clone.tap { |query| query.options.store(:return_key, true) }
8
- end
9
- end
10
- end
11
- end
@@ -1,11 +0,0 @@
1
- # encoding: utf-8
2
- module Origin
3
- module Optional
4
- module ShowDiskLoc
5
-
6
- def show_disk_loc
7
- clone.tap { |query| query.options.store(:show_disk_loc, true) }
8
- end
9
- end
10
- end
11
- end
@@ -1,11 +0,0 @@
1
- # encoding: utf-8
2
- module Origin
3
- module Optional
4
- module Skip
5
-
6
- def skip(value = nil)
7
- option(value) { |options| options.store(:skip, value) }
8
- end
9
- end
10
- end
11
- end
@@ -1,17 +0,0 @@
1
- # encoding: utf-8
2
- module Origin
3
- module Optional
4
- module Slice
5
-
6
- def slice(criterion = nil)
7
- option(criterion) do |options|
8
- options._union(
9
- :fields => criterion.inject({}) do |option, (field, val)|
10
- option.tap { |opt| opt.store(field, { "$slice" => val }) }
11
- end
12
- )
13
- end
14
- end
15
- end
16
- end
17
- end
@@ -1,13 +0,0 @@
1
- # encoding: utf-8
2
- module Origin
3
- module Optional
4
- module Snapshot
5
-
6
- def snapshot
7
- clone.tap do |query|
8
- query.options.store(:snapshot, true)
9
- end
10
- end
11
- end
12
- end
13
- end
@@ -1,11 +0,0 @@
1
- # encoding: utf-8
2
- module Origin
3
- module Optional
4
- module Transformer
5
-
6
- def transformer(block = nil)
7
- option(block) { |options| options.store(:transformer, block) }
8
- end
9
- end
10
- end
11
- end
@@ -1,15 +0,0 @@
1
- # encoding: utf-8
2
- module Origin
3
- module Optional
4
- module Without
5
-
6
- def without(*args)
7
- option(*args) do |options|
8
- options.store(
9
- :fields, args.inject({}){ |sub, field| sub.tap { sub[field] = -1 }}
10
- )
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,59 +0,0 @@
1
- # encoding: utf-8
2
- module Origin
3
- module Selection
4
-
5
- autoload :All, "origin/selection/all"
6
- autoload :And, "origin/selection/and"
7
- autoload :Between, "origin/selection/between"
8
- autoload :ElemMatch, "origin/selection/elem_match"
9
- autoload :Exists, "origin/selection/exists"
10
- autoload :Gt, "origin/selection/gt"
11
- autoload :Gte, "origin/selection/gte"
12
- autoload :In, "origin/selection/in"
13
- autoload :Key, "origin/selection/key"
14
- autoload :Lt, "origin/selection/lt"
15
- autoload :Lte, "origin/selection/lte"
16
- autoload :MaxDistance, "origin/selection/max_distance"
17
- autoload :Mod, "origin/selection/mod"
18
- autoload :Ne, "origin/selection/ne"
19
- autoload :Near, "origin/selection/near"
20
- autoload :NearSphere, "origin/selection/near_sphere"
21
- autoload :Nin, "origin/selection/nin"
22
- autoload :Nor, "origin/selection/nor"
23
- autoload :Or, "origin/selection/or"
24
- autoload :Size, "origin/selection/size"
25
- autoload :Strategies, "origin/selection/strategies"
26
- autoload :Type, "origin/selection/type"
27
- autoload :Where, "origin/selection/where"
28
- autoload :WithinBox, "origin/selection/within_box"
29
- autoload :WithinCircle, "origin/selection/within_circle"
30
- autoload :WithinSphericalCircle, "origin/selection/within_spherical_circle"
31
-
32
- include All
33
- include And
34
- include Between
35
- include ElemMatch
36
- include Exists
37
- include Gt
38
- include Gte
39
- include In
40
- include Lt
41
- include Lte
42
- include MaxDistance
43
- include Mod
44
- include Ne
45
- include Near
46
- include NearSphere
47
- include Nin
48
- include Nor
49
- include Or
50
- include Size
51
- include Strategies
52
- include Type
53
- include Where
54
- include WithinBox
55
- include WithinCircle
56
- #include WithinPolygon
57
- include WithinSphericalCircle
58
- end
59
- end
@@ -1,18 +0,0 @@
1
- # encoding: utf-8
2
- module Origin
3
- module Selection
4
- module All
5
-
6
- def all(criterion = nil)
7
- send(strategy || :_override, criterion, "$all")
8
- end
9
-
10
- ::Symbol.class_eval do
11
-
12
- def all
13
- Key.new(self, "$all")
14
- end
15
- end
16
- end
17
- end
18
- end
@@ -1,11 +0,0 @@
1
- # encoding: utf-8
2
- module Origin
3
- module Selection
4
- module And
5
-
6
- def and(*criterion)
7
- multi!(criterion, "$and")
8
- end
9
- end
10
- end
11
- end
@@ -1,16 +0,0 @@
1
- # encoding: utf-8
2
- module Origin
3
- module Selection
4
- module Between
5
-
6
- def between(criterion = nil)
7
- selection(criterion) do |selector, field, value|
8
- selector.store(
9
- field,
10
- { "$gte" => value.min, "$lte" => value.max }
11
- )
12
- end
13
- end
14
- end
15
- end
16
- end
@@ -1,18 +0,0 @@
1
- # encoding: utf-8
2
- module Origin
3
- module Selection
4
- module ElemMatch
5
-
6
- def elem_match(criterion = nil)
7
- _override(criterion, "$elemMatch")
8
- end
9
-
10
- ::Symbol.class_eval do
11
-
12
- def elem_match
13
- Key.new(self, "$elemMatch")
14
- end
15
- end
16
- end
17
- end
18
- end
@@ -1,18 +0,0 @@
1
- # encoding: utf-8
2
- module Origin
3
- module Selection
4
- module Exists
5
-
6
- def exists(criterion = nil)
7
- _override(criterion, "$exists")
8
- end
9
-
10
- ::Symbol.class_eval do
11
-
12
- def exists
13
- Key.new(self, "$exists")
14
- end
15
- end
16
- end
17
- end
18
- end