activecube 0.1.41 → 0.1.42

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 566db205500299f766f3971b9692e876926ca5ff1f65fbfea78a8c19ed4c501d
4
- data.tar.gz: 33c2890756ea8fba2d4dc28a877fcf21891a56783d63a996d5bf3c5cfde14033
3
+ metadata.gz: 7074b394ca4949bf0bedae97ac91b59ef8d742cb7c6ab77e5409345d77caa7bd
4
+ data.tar.gz: e7872e83b417e7e9d34acd329627e68d8d1424771e507fd345bd4edac0bc04e9
5
5
  SHA512:
6
- metadata.gz: 54316348e68e897854789e8a7dd3ac628fbab5b1c1b4e4fa877faff72ecbe42ebe2a589c77f31b2287af0c40dc03efd8da9467bba6eaa59466c4951cb9c6d638
7
- data.tar.gz: aed6fcd142c56ef9f56a84b9efb00bab50a7b96090d9d4379653991dc387b6ae1d7249da5170389422d57ca683b4e9f853eb3549559d1e160db5583be8dcc2bc
6
+ metadata.gz: 693c8954a658b15c5f6f314b189fbff0a13777a8a84fbf1354d70610dabc903ef7be60475a4253e5bdd72e067a4a31aaaddb0821fa4949a4347be0abd5d28c02
7
+ data.tar.gz: 2a04854410822d43e2b4e29b53c062cdf59b971137978081147133956fd1108e2bd1b633782347075e7aa81cc9d237d8da92d148f5064d4697ee20d3be56944c
data/Gemfile.lock CHANGED
@@ -9,7 +9,7 @@ GIT
9
9
  PATH
10
10
  remote: .
11
11
  specs:
12
- activecube (0.1.40)
12
+ activecube (0.1.41)
13
13
  activerecord (>= 5.2)
14
14
 
15
15
  GEM
@@ -61,6 +61,14 @@ module Activecube::Query
61
61
  self
62
62
  end
63
63
 
64
+ def desc_by_integer *args
65
+ clear_sql
66
+ args.each{|arg|
67
+ options << Ordering.new(arg, :desc, options = {with_length: true})
68
+ }
69
+ self
70
+ end
71
+
64
72
  def asc *args
65
73
  clear_sql
66
74
  args.each{|arg|
@@ -69,6 +77,14 @@ module Activecube::Query
69
77
  self
70
78
  end
71
79
 
80
+ def asc_by_integer *args
81
+ clear_sql
82
+ args.each{|arg|
83
+ options << Ordering.new(arg, :asc, options = {with_length: true})
84
+ }
85
+ self
86
+ end
87
+
72
88
  def offset *args
73
89
  clear_sql
74
90
  args.each{|arg|
@@ -138,4 +154,4 @@ module Activecube::Query
138
154
  @composed = nil
139
155
  end
140
156
  end
141
- end
157
+ end
@@ -2,15 +2,21 @@ module Activecube
2
2
  module Query
3
3
  class Ordering
4
4
 
5
- attr_reader :argument, :direction
6
- def initialize argument, direction
5
+ attr_reader :argument, :direction, :options
6
+ def initialize argument, direction, options = {}
7
7
  @argument = argument
8
8
  @direction = direction
9
+ @options = options
9
10
  end
10
11
 
11
12
  def append_query _model, _cube_query, _table, query
12
- text = argument.to_s.split(',').map{|s| quote s}.join(',')
13
- query.order(::Arel.sql(text).send(direction))
13
+ @text = argument.to_s.split(',').map{|s| quote s}.join(',')
14
+
15
+ if options[:with_length]
16
+ return by_length_order(query)
17
+ end
18
+
19
+ simple_order(query)
14
20
  end
15
21
 
16
22
  def quote s
@@ -21,6 +27,21 @@ module Activecube
21
27
  end
22
28
  end
23
29
 
30
+ private
31
+
32
+ attr_reader :text
33
+
34
+ def simple_order(query)
35
+ query.order(::Arel.sql(text).send(direction))
36
+ end
37
+
38
+ def by_length_order(query)
39
+ query.order(
40
+ ::Arel.sql("LENGTH(#{text})").send(direction),
41
+ ::Arel.sql(text).send(direction)
42
+ )
43
+ end
44
+
24
45
  end
25
46
  end
26
- end
47
+ end
@@ -5,7 +5,7 @@ module Activecube
5
5
 
6
6
  attr_reader :database, :role
7
7
 
8
- [:slice, :measure, :when, :desc, :asc, :limit, :offset].each do |method|
8
+ [:slice, :measure, :when, :desc, :desc_by_integer, :asc, :asc_by_integer, :limit, :offset].each do |method|
9
9
  define_method(method) do |*args|
10
10
  Query::CubeQuery.new(self).send method, *args
11
11
  end
@@ -1,3 +1,3 @@
1
1
  module Activecube
2
- VERSION = "0.1.41"
2
+ VERSION = "0.1.42"
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.41
4
+ version: 0.1.42
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aleksey Studnev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-03 00:00:00.000000000 Z
11
+ date: 2022-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord