active_house 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/active_house/array_joinable.rb +33 -0
- data/lib/active_house/chainable.rb +8 -1
- data/lib/active_house/collectable.rb +7 -2
- data/lib/active_house/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8604e8b710205124b594cb7f226fbc04f444875
|
4
|
+
data.tar.gz: 4130c550f2386afe4cd26953e219fadbff652b98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe1797a3645326c8cd9e8e0ab90e570b4d4e00722fd2aad537706a474391d7702e3d8c3846b428f493c738da63b929c3227e6cd0a1a70c23c46983de4184b617
|
7
|
+
data.tar.gz: f699b40bfcda2ea589d047cb3624261bb1bde8024f5e0a047b4221d4a56513befa7e22a85a64c74da33aaeced0151d5e0670d0e1341aa1ae398ca60d3f6f371a
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module ActiveHouse
|
2
|
+
module ArrayJoinable
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
private
|
7
|
+
|
8
|
+
def build_array_join_query_part
|
9
|
+
unless @array_joins.empty?
|
10
|
+
"ARRAY JOIN #{@array_joins.join(', ')}"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(*)
|
16
|
+
@array_joins = []
|
17
|
+
super
|
18
|
+
end
|
19
|
+
|
20
|
+
def array_join(*fields)
|
21
|
+
raise ArgumentError, 'wrong number of arguments' if fields.empty?
|
22
|
+
formatted_fields = fields.map do |field|
|
23
|
+
if field.is_a?(Symbol) && model_class._attribute_opts.key?(field)
|
24
|
+
opts = model_class._attribute_opts.fetch(field)
|
25
|
+
opts.key?(:select) ? "#{opts[:select]} AS #{field}" : field.to_s
|
26
|
+
else
|
27
|
+
field.to_s
|
28
|
+
end
|
29
|
+
end
|
30
|
+
chain_query array_joins: (@array_joins + formatted_fields).uniq
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -6,6 +6,7 @@ require_relative 'groupable'
|
|
6
6
|
require_relative 'limitable'
|
7
7
|
require_relative 'havingable'
|
8
8
|
require_relative 'unionable'
|
9
|
+
require_relative 'array_joinable'
|
9
10
|
require 'active_support/concern'
|
10
11
|
|
11
12
|
module ActiveHouse
|
@@ -20,6 +21,7 @@ module ActiveHouse
|
|
20
21
|
include ActiveHouse::Havingable
|
21
22
|
include ActiveHouse::Limitable
|
22
23
|
include ActiveHouse::Unionable
|
24
|
+
include ActiveHouse::ArrayJoinable
|
23
25
|
|
24
26
|
included do
|
25
27
|
protected
|
@@ -39,6 +41,7 @@ module ActiveHouse
|
|
39
41
|
[
|
40
42
|
build_select_query_part,
|
41
43
|
build_from_query_part,
|
44
|
+
build_array_join_query_part,
|
42
45
|
build_where_query_part,
|
43
46
|
build_group_by_query_part,
|
44
47
|
build_having_query_part,
|
@@ -100,10 +103,13 @@ module ActiveHouse
|
|
100
103
|
limit: :limit,
|
101
104
|
having: :having,
|
102
105
|
union: :unions,
|
103
|
-
from: :subquery
|
106
|
+
from: :subquery,
|
107
|
+
array_join: :array_joins
|
104
108
|
}
|
105
109
|
end
|
106
110
|
|
111
|
+
# key - instance variable name that which store values
|
112
|
+
# value - default value for the variable
|
107
113
|
def chain_defaults
|
108
114
|
{
|
109
115
|
fields: [],
|
@@ -114,6 +120,7 @@ module ActiveHouse
|
|
114
120
|
having: [],
|
115
121
|
union: {},
|
116
122
|
subquery: nil,
|
123
|
+
array_joins: []
|
117
124
|
}
|
118
125
|
end
|
119
126
|
|
@@ -22,13 +22,18 @@ module ActiveHouse
|
|
22
22
|
!@collection.nil?
|
23
23
|
end
|
24
24
|
|
25
|
+
def to_hashes
|
26
|
+
connection.select_rows(to_query.squish)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
25
31
|
def collection
|
26
32
|
@collection ||= fetch_collection
|
27
33
|
end
|
28
34
|
|
29
35
|
def fetch_collection
|
30
|
-
|
31
|
-
result.map { |row| model_class.load!(row) }
|
36
|
+
to_hash.map { |row| model_class.load!(row) }
|
32
37
|
end
|
33
38
|
end
|
34
39
|
end
|
data/lib/active_house/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_house
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Denis Talakevich
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-10-
|
11
|
+
date: 2018-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -113,6 +113,7 @@ files:
|
|
113
113
|
- bin/console
|
114
114
|
- bin/setup
|
115
115
|
- lib/active_house.rb
|
116
|
+
- lib/active_house/array_joinable.rb
|
116
117
|
- lib/active_house/chainable.rb
|
117
118
|
- lib/active_house/collectable.rb
|
118
119
|
- lib/active_house/configuration.rb
|