activecube 0.1.30 → 0.1.31

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 663ae546f63257569c7692d59478ffef3c954f2c9a74f53c78ae6ee31bdf093c
4
- data.tar.gz: df61b6a95415e4879d62b0eada8abcf732d9d7aeca882c72fa28ca929c567db1
3
+ metadata.gz: 6c706faf950e642b3216ee5bce134ae45c9ad1047395825426897961a2bf357e
4
+ data.tar.gz: eb49f277b4fe9ade7817fd9b3d69389ec0879ae3a92004c5d2fa85a2a19a1d70
5
5
  SHA512:
6
- metadata.gz: e25d8a4f05d9880c4c3acbf6854393556902e0339976701949ab5b56bc3d627f20a9790144c19f00903786fa0abd947c2cb866bdc5d41856483cd8e030a281d1
7
- data.tar.gz: 418d88e3f5d6249de2781faa1f27cfc42d219538eac7c2d68611735771cf8d2413ac2a1e626559d7b8f0d0248852358a58ea5400af2a561248cb1a591126e49a
6
+ metadata.gz: 5754c7e2658c9456bee51c66f21ca42da0f7198bf155b06386e845745da098c282a89cd4c388d3581421d0c9e89704accd2249c45b3c30ff32e72744d0b52fbe
7
+ data.tar.gz: e5ff2a9a0ac8706dae669b7c0355f2e04ff5f6bb2ca7415253ada1fe76d1036dbdcd8d5b9202b3c10cd19996184b52498fecd7debf4be4547af01f3b27a0e36b
data/Gemfile.lock CHANGED
@@ -9,7 +9,7 @@ GIT
9
9
  PATH
10
10
  remote: .
11
11
  specs:
12
- activecube (0.1.29)
12
+ activecube (0.1.30)
13
13
  activerecord (>= 5.2)
14
14
 
15
15
  GEM
@@ -22,5 +22,35 @@ module Activecube::Query
22
22
  "#{definition.class.name}(#{key})"
23
23
  end
24
24
 
25
+
26
+ private
27
+
28
+ def append_with! model, cube_query, table, query
29
+
30
+ if definition.respond_to?(:with_expression) &&
31
+ (with_expression = definition.with_expression(model, cube_query, table, query))
32
+ with_expression.each_pair do |key, expr|
33
+ query = try_append_with(query, key, expr)
34
+ end
35
+ end
36
+ query
37
+ end
38
+
39
+ def try_append_with(query, key, expr)
40
+ expr = Arel.sql(expr) if expr.kind_of?(String)
41
+ if (with = query.ast.with)
42
+ existing = with.expr.detect{|expr| expr.right==key }
43
+ if existing
44
+ raise "Key #{key} defined twice in WITH statement, with different expressions #{expr.to_sql} AND #{existing.left}" if existing.left!=expr.to_s
45
+ query
46
+ else
47
+ query.with(with.expr + [expr.as(key)])
48
+ end
49
+ else
50
+ query.with(expr.as(key))
51
+ end
52
+
53
+ end
54
+
25
55
  end
26
56
  end
@@ -36,6 +36,7 @@ module Activecube::Query
36
36
  end
37
37
 
38
38
  def append_query model, cube_query, table, query
39
+ query = append_with!(model, cube_query, table, query)
39
40
  attr_alias = "`#{key.to_s}`"
40
41
  expr = definition.expression model, table, self, cube_query
41
42
  query.project expr.as(attr_alias)
@@ -53,6 +54,7 @@ module Activecube::Query
53
54
 
54
55
  private
55
56
 
57
+
56
58
  def modifier_methods!
57
59
  definition.class.modifiers.each_pair do |key, modifier|
58
60
  define_singleton_method key do |*args|
@@ -32,6 +32,7 @@ module Activecube::Query
32
32
  end
33
33
 
34
34
  def append_query model, cube_query, arel_table, query
35
+ query = append_with!(model, cube_query, arel_table, query)
35
36
  query.where expression(model, arel_table, cube_query)
36
37
  end
37
38
 
@@ -60,6 +60,8 @@ module Activecube::Query
60
60
 
61
61
  def append_query model, cube_query, table, query
62
62
 
63
+ query = append_with!(model, cube_query, table, query)
64
+
63
65
  attr_alias = "`#{key.to_s}`"
64
66
  expr = (parent || definition.respond_to?(:expression)) ?
65
67
  Arel.sql(definition.expression( model, table, self, cube_query) ) :
@@ -1,3 +1,3 @@
1
1
  module Activecube
2
- VERSION = "0.1.30"
2
+ VERSION = "0.1.31"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activecube
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.30
4
+ version: 0.1.31
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aleksey Studnev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-30 00:00:00.000000000 Z
11
+ date: 2021-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord