martyr 0.1.82.pre → 0.1.84.pre
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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6f612ed989982d638bfab8b65db92f37e47eb06
|
4
|
+
data.tar.gz: f91c1aa0fc1de054714cb75c648e202f4d667c9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e47d47725fcb74d7308e38d5cbf9a2654faad5a3f8c0ebea4958e04b7f8914d1a9a2b762861599f3e635c6d5ed706075ae90bff30a9bee47bd1098affb58363b
|
7
|
+
data.tar.gz: 082b33748653c03733759bdb4bf0e7629237c393f8df375f49c1ede2872dc2995b5d512913e51ca00bef6ad4a0748484c4f900fff2b27ec008d2c9afc2807fd7
|
@@ -80,10 +80,7 @@ module Martyr
|
|
80
80
|
|
81
81
|
# Building operator used to slice the fact
|
82
82
|
fact_scopes.add_where_operator_for_dimension(level_scope.dimension_name, level_scope.name) do |operator|
|
83
|
-
if slice_definition.null?
|
84
|
-
operator.decorate_scope {|fact_scope| fact_scope.where('0=1')}
|
85
|
-
next
|
86
|
-
end
|
83
|
+
next operator.add_where('0=1') if slice_definition.null?
|
87
84
|
|
88
85
|
common_denominator_level = operator.common_denominator_level(level_scope.level_definition)
|
89
86
|
if common_denominator_level.name == level_scope.name
|
@@ -4,6 +4,24 @@ module Martyr
|
|
4
4
|
|
5
5
|
attr_accessor :statement, :fact_alias, :typecast, :sub_queries
|
6
6
|
|
7
|
+
# A built in metric can be registered in a cube like so:
|
8
|
+
# `has_sum_metric :published_book_count, "CASE WHEN books.published THEN 1 ELSE 0 END", subquery: :book_publications_sub`
|
9
|
+
#
|
10
|
+
# Built in metrics definitions accept a typecast option, that can be used the following ways:
|
11
|
+
# - As a String or Symbol. Martyr will interpret the fact value by calling the method given as the typecast option
|
12
|
+
# `has_sum_metric :published_book_count, "CASE WHEN books.published THEN 1 ELSE 0 END",
|
13
|
+
# subquery: :book_publications_sub, typecast: :to_i`
|
14
|
+
#
|
15
|
+
# - As an Array. Martyr will interpret the fact value using the first element as the method, the rest as the arguments
|
16
|
+
# `has_max_metric :last_publication_time, "book_publications_sub.published_at", subquery: :book_publications_sub,
|
17
|
+
# typecast: [:to_time, :utc]`
|
18
|
+
#
|
19
|
+
# - As a Proc
|
20
|
+
# `has_max_metric :last_publication_time, "book_publications_sub.published_at", subquery: :book_publications_sub,
|
21
|
+
# typecast: -> (time_string) { time_string.to_time(:utc) }`
|
22
|
+
#
|
23
|
+
# - When no typecast option is given, the behaviour defaults to typecast: :to_i
|
24
|
+
|
7
25
|
def build_data_slice(*args)
|
8
26
|
Runtime::MetricDataSlice.new(self, *args)
|
9
27
|
end
|
@@ -20,7 +38,20 @@ module Martyr
|
|
20
38
|
end
|
21
39
|
|
22
40
|
def extract(fact)
|
23
|
-
fact.raw.fetch(fact_alias.to_s)
|
41
|
+
raw_fact_value = fact.raw.fetch(fact_alias.to_s)
|
42
|
+
case typecast
|
43
|
+
when NilClass
|
44
|
+
raw_fact_value.to_i
|
45
|
+
when Symbol, String, Array
|
46
|
+
raw_fact_value.send(*Array.wrap(typecast))
|
47
|
+
when Proc
|
48
|
+
typecast.call(raw_fact_value)
|
49
|
+
else
|
50
|
+
error_message = "#{typecast.class.name} typecast option not supported. Give a Symbol, String, Array or Proc"
|
51
|
+
raise RuntimeError.new(error_message)
|
52
|
+
end
|
53
|
+
rescue
|
54
|
+
nil
|
24
55
|
end
|
25
56
|
|
26
57
|
private
|
data/lib/martyr/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: martyr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.84.pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Amit Aharoni
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|