active_reporting 0.5.0 → 0.5.1

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: 1bbb1cca5da777e98db50e52e0dd97a44e20cd9844c8d4d88cbb739485a7f22f
4
- data.tar.gz: f3d5fcc3f6e174e6eb6ca582c57add3b844cc0deb632e6f844ee9990db31c93f
3
+ metadata.gz: 07ad5ad6e21234d6441a8e97908cf854406d30e2a77b741096d0c874c85d5c42
4
+ data.tar.gz: 982a82ba6ab68d81dee8a1db785f25d993ac14b2572e698923437a4c1a37bd1e
5
5
  SHA512:
6
- metadata.gz: b57b0e82ebb5d1d645383d3aa88551b43c999c1443d0ecac6544d83295d6d1745f2956696499a5ce3ff249f8d91251e298a77e3921a68722d6842ffb7e90e705
7
- data.tar.gz: 3fcec68b2de1a822ecef745f7b75ca6aaa7ae9587d7a25ce5ae5234a26e1d083bab01da4ccd70bafd47a9382810fb0932cb287ca7b18d20916789f4e0809b045
6
+ metadata.gz: 0f7a37f152776e1d9fbc2440b71cb045464063f759c88cfff5d6dc0302ab8e9f6ea7aeed4c35375b5ad25861132dfb1ba4ebad57da6051ba75680beb309c3665
7
+ data.tar.gz: 0c07b8989e32d26ca39105630ffe74b83207425449d412f344461c194926e0efed64da367449898295de62a3618910f7a249e94ee91efe0290b3332d1b820319
@@ -1,8 +1,19 @@
1
+ ## 0.5.1 (2020-06-31)
2
+
3
+ ### Features
4
+
5
+ * Allow dimensions defined in a `Metric` to use LEFT OUTER JOINs via a new `:join_method` option (#32) - *germanotm*
6
+
7
+ ### Misc
8
+
9
+ * Fixed warning about initialized variables
10
+ * Fixed Ruby 2.7 warning
11
+
1
12
  ## 0.5.0 (2020-06-30)
2
13
 
3
14
  ### Bug Fixes
4
15
 
5
- * Fix Missing quotation marks in column names causing SLQ errors on MYSQL - *germanotm*
16
+ * Fix Missing quotation marks in column names causing SQL errors on MYSQL (#30) - *germanotm*
6
17
 
7
18
  ### Misc
8
19
 
data/Gemfile CHANGED
@@ -11,5 +11,5 @@ case rails
11
11
  when '5-2'
12
12
  gem 'activerecord', '~> 5.2.0'
13
13
  when '6-0'
14
- gem 'activerecord', '6.0.0'
14
+ gem 'activerecord', '~> 6.0.0'
15
15
  end
data/README.md CHANGED
@@ -285,7 +285,7 @@ my_metric = ActiveReporting::Metric.new(
285
285
 
286
286
  `aggregate` - The SQL aggregate used to calculate the metric. Supported aggregates include count, max, min, avg, and sum. (Default: `:count`)
287
287
 
288
- `dimensions` - An array of dimensions used for the metric. When given just a symbol, the default dimension label will be used for the dimension. You may specify a hierarchy level by using a hash. (Examples: `[:sales_rep, {sale_date: :month}]`). In hierarchies you can customize the label in this way: `[{sale_date: { field: :month, name: :a_custom_name_for_month }}]`. If you use a hash instead of a Symbol to define a hierarchy the `field` item must be a valid field in your table. The `name` can be whatever label you want.
288
+ `dimensions` - An array of dimensions used for the metric. When given just a symbol, the default dimension label will be used for the dimension. You may specify a hierarchy level by using a hash. (Examples: `[:sales_rep, {sale_date: :month}]`). In hierarchies you can customize the label in this way: `[{sale_date: { field: :month, name: :a_custom_name_for_month }}]`. If you use a hash instead of a Symbol to define a hierarchy the `field` item must be a valid field in your table. The `name` can be whatever label you want. You can choose the join_method with the dimension. The default value for join_method is :joins which does a standard "INNER JOIN", but you can pass a :left_outer_joins to use "LEFT OUTER JOIN" instead. Ex: `[{sales_rep: { join_method: :left_outer_joins }}]`
289
289
 
290
290
  `dimension_filter` - A hash were the keys are dimension filter names and the values are the values passed into the filter.
291
291
 
@@ -41,4 +41,5 @@ module ActiveReporting
41
41
  UnknownDimension = Class.new(StandardError)
42
42
  UnknownDimensionFilter = Class.new(StandardError)
43
43
  UnknownMetric = Class.new(StandardError)
44
+ UnknownJoinMethod = Class.new(StandardError)
44
45
  end
@@ -85,6 +85,7 @@ module ActiveReporting
85
85
  #
86
86
  # @return [Symbol]
87
87
  def self.dimension_label
88
+ @dimension_label ||= nil
88
89
  @dimension_label || Configuration.default_dimension_label
89
90
  end
90
91
 
@@ -155,6 +156,7 @@ module ActiveReporting
155
156
  #
156
157
  # @return [Boolean]
157
158
  def self.ransack_fallback
159
+ @ransack_fallback ||= false
158
160
  @ransack_fallback || Configuration.ransack_fallback
159
161
  end
160
162
  private_class_method :ransack_fallback
@@ -52,7 +52,8 @@ module ActiveReporting
52
52
  def statement
53
53
  parts = {
54
54
  select: select_statement,
55
- joins: dimension_joins,
55
+ joins: dimension_joins(ReportingDimension::JOIN_METHODS[:joins]),
56
+ left_outer_joins: dimension_joins(ReportingDimension::JOIN_METHODS[:left_outer_joins]),
56
57
  group: group_by_statement,
57
58
  having: having_statement,
58
59
  order: order_by_statement
@@ -84,8 +85,9 @@ module ActiveReporting
84
85
  end
85
86
  end
86
87
 
87
- def dimension_joins
88
- @dimensions.select { |d| d.type == :standard }.map { |d| d.name.to_sym }
88
+ def dimension_joins(join_method)
89
+ @dimensions.select { |d| d.type == Dimension::TYPES[:standard] && d.join_method == join_method }.
90
+ map { |d| d.name.to_sym }
89
91
  end
90
92
 
91
93
  def group_by_statement
@@ -9,6 +9,9 @@ module ActiveReporting
9
9
  # See https://www.postgresql.org/docs/10/static/functions-datetime.html#FUNCTIONS-DATETIME-TRUNC
10
10
  DATETIME_HIERARCHIES = %i[microseconds milliseconds second minute hour day week month quarter year decade
11
11
  century millennium].freeze
12
+ JOIN_METHODS = { joins: :joins, left_outer_joins: :left_outer_joins }.freeze
13
+ attr_reader :join_method
14
+
12
15
  def_delegators :@dimension, :name, :type, :klass, :association, :model, :hierarchical?, :datetime?
13
16
 
14
17
  def self.build_from_dimensions(fact_model, dimensions)
@@ -18,7 +21,7 @@ module ActiveReporting
18
21
 
19
22
  raise(UnknownDimension, "Dimension '#{dim}' not found on fact model '#{fact_model}'") if found_dimension.nil?
20
23
 
21
- new(found_dimension, label_config(label))
24
+ new(found_dimension, **label_config(label))
22
25
  end
23
26
  end
24
27
 
@@ -32,18 +35,20 @@ module ActiveReporting
32
35
 
33
36
  {
34
37
  label: label[:field],
35
- label_name: label[:name]
38
+ label_name: label[:name],
39
+ join_method: label[:join_method]
36
40
  }
37
41
  end
38
42
 
39
43
  # @param dimension [ActiveReporting::Dimension]
40
44
  # @option label [Maybe<Symbol>] Hierarchical dimension to be used as a label
41
45
  # @option label_name [Maybe<Symbol|String>] Hierarchical dimension custom name
42
- def initialize(dimension, label: nil, label_name: nil)
46
+ def initialize(dimension, label: nil, label_name: nil, join_method: nil)
43
47
  @dimension = dimension
44
48
 
45
49
  determine_label_field(label)
46
50
  determine_label_name(label_name)
51
+ determine_join_method(join_method)
47
52
  end
48
53
 
49
54
  # The foreign key to use in queries
@@ -106,6 +111,16 @@ module ActiveReporting
106
111
  @label_name = label_name ? "#{name}_#{label_name}" : name
107
112
  end
108
113
 
114
+ def determine_join_method(join_method)
115
+ if join_method.blank?
116
+ @join_method = ReportingDimension::JOIN_METHODS[:joins]
117
+ elsif ReportingDimension::JOIN_METHODS.include?(join_method)
118
+ @join_method = join_method
119
+ else
120
+ raise UnknownJoinMethod, "Method '#{join_method}' not included in '#{ReportingDimension::JOIN_METHODS.values}'"
121
+ end
122
+ end
123
+
109
124
  def validate_hierarchical_label(hierarchical_label)
110
125
  if datetime?
111
126
  validate_supported_database_for_datetime_hierarchies
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveReporting
4
- VERSION = '0.5.0'
4
+ VERSION = '0.5.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_reporting
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Drake
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-30 00:00:00.000000000 Z
11
+ date: 2020-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord