martyr 0.1.82.pre → 0.1.84.pre

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
  SHA1:
3
- metadata.gz: 0a4dc1bc2b3d1da2c2a0ba4605148826bd0f6435
4
- data.tar.gz: 16732ae40dd7fac4a55d3a8373de0318dac88ff9
3
+ metadata.gz: c6f612ed989982d638bfab8b65db92f37e47eb06
4
+ data.tar.gz: f91c1aa0fc1de054714cb75c648e202f4d667c9d
5
5
  SHA512:
6
- metadata.gz: 3c483cc8069afa119e02e9fe9ae9c016b8e5a88016defb7f1599656dd892502283c8b1d46ab48b981267a4cfe5e5ed18acdf243b3f7d8479c9b1a31dfcf82f20
7
- data.tar.gz: fe7f4668c2fdd9a16a16b6d068787bbc742e09a72b9a677179205e5972932c49ad016bf7d71b1fc60f82a9ba8d83343cd923f01f53e0e7df252ecc9691437661
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).try(:send, typecast || :to_i)
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
@@ -1,3 +1,3 @@
1
1
  module Martyr
2
- VERSION = "0.1.82.pre"
2
+ VERSION = "0.1.84.pre"
3
3
  end
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.82.pre
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-01-04 00:00:00.000000000 Z
11
+ date: 2017-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler