active_repository 0.2.5 → 0.2.6
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.
- checksums.yaml +8 -8
- data/lib/active_repository/sql_query_executor.rb +14 -0
- data/lib/active_repository/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MGU1NzgzYmJjNzk1OWFkY2M0ZjYwMWFiOTBmNjJjYzY4MDBlMjk5OQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OGJkZDk3ZGUyNDBmOWY4NGU0MmU2ZTE5Y2M5ZDYxNWYxYzY3YTI2ZQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NGZmZjQ3ZmIzY2Q1Y2Q3ZmQ1NTVlNzQyNTU4MDUxNzgzNzdiOGExMjAxMDdi
|
10
|
+
NzViZWI4MjNjZTAxZTNkOWRkNWZlMDcxZmExNDQ0OGU1MWQyODdlNTAzNDNm
|
11
|
+
MmMxODhhOTMyMTAwMmEzNWExYjAzNjIxMjRhYWYzNjU4Nzk0M2U=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YjEwYmRiNDMwMzBiYmI1NWQ0Y2VhMTE2YzliMzZkOTY0YmE2MDAzZjhlNzZl
|
14
|
+
NzUyMjBlMjVmNTgxNzljNzUzZDdiY2NjMTYxMDMwYmM1M2I4NjJiZDU1M2Jj
|
15
|
+
ZmVlYTViYjlhZTg3MjFkZjJlYzA5ZTA5YjBjNDNhYTkwZTJlOWI=
|
@@ -19,6 +19,8 @@ module ActiveHash #:nodoc:
|
|
19
19
|
# Recursive method that divides the query in sub queries, executes each part individually
|
20
20
|
# and finally relates its results as specified in the query.
|
21
21
|
def execute(klass, query)
|
22
|
+
query = query.gsub(/\[.*?\]/) { |substr| substr.gsub(' ', '') }
|
23
|
+
|
22
24
|
@operator, @sub_query, @objects = process_first(klass, query, query.split(" ")[1].downcase)
|
23
25
|
|
24
26
|
@operator.nil? ? @objects : @objects.send(@operator, execute(klass, @sub_query)).sort_by{ |o| o.id }
|
@@ -85,6 +87,16 @@ module ActiveHash #:nodoc:
|
|
85
87
|
end
|
86
88
|
end
|
87
89
|
|
90
|
+
# Executes SQL is filter
|
91
|
+
def execute_in(klass, sub_query)
|
92
|
+
klass.all.select do |o|
|
93
|
+
field = o.send(sub_query.first)
|
94
|
+
values = sub_query[2].gsub(/\(|\[|\]|\)/, '').split(/,|, /)
|
95
|
+
|
96
|
+
values.include?(field.to_s)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
88
100
|
# Executes the #sub_quey defined operator filter
|
89
101
|
def execute_operator(klass, sub_query)
|
90
102
|
klass.all.select do |o|
|
@@ -107,6 +119,8 @@ module ActiveHash #:nodoc:
|
|
107
119
|
execute_between(klass, sub_query)
|
108
120
|
when "is"
|
109
121
|
execute_is(klass, sub_query)
|
122
|
+
when "in"
|
123
|
+
execute_in(klass, sub_query)
|
110
124
|
else
|
111
125
|
execute_operator(klass, sub_query)
|
112
126
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_repository
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Caio Torres
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_hash
|