active_reporting 0.4.0 → 0.4.1

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
- SHA1:
3
- metadata.gz: 7a5444ba19be4d20842e16f8e800e45837e133bd
4
- data.tar.gz: 24b59685e4cd70770a13a8a2925c85d860e782a3
2
+ SHA256:
3
+ metadata.gz: 4470ea5ed19154c0f73c4205dfb251f327a076563eeee479a8ebf1410cfd6c81
4
+ data.tar.gz: '038914792fde14a53347f7952336a68e3d2520a171dbb2a620342ba85dffc144'
5
5
  SHA512:
6
- metadata.gz: 1df566a6122ec806f231a116ffe33cf729374fe529ddf18a2763cb2462946414c60bada55a06e7fc036ef3c4fc0002f021d06b1147cb011c7810ce1b517cd82e
7
- data.tar.gz: 0ec9387af8a5918f3685732b4331377302e373ae56843305991d2c8abc24928c4a19ea79ed7d3bd6b5e979204c2a15cde3806df62a282a8714ac0d6a439fb4e6
6
+ metadata.gz: 0dafa3b0a2d8a9731f14c51e1505bdf79b79cb52fb9b9ecabe3c8006340f946b60638090b775a830a8952f7dce1c32f75608eb488894e08d899e0cc6b5b0d5e5
7
+ data.tar.gz: a4a2e65604d42d290582c50954aa66f991350bf5efbfd47887ae4534d4ed7811dc70538371cd693650124af7f1ef0843ebd4c62a84111527d35c268231a79a11
data/.gitignore CHANGED
@@ -6,5 +6,7 @@
6
6
  /doc/
7
7
  /pkg/
8
8
  /spec/reports/
9
+ .byebug_history
10
+ .ruby-version
9
11
  /tmp/
10
12
  .DS_STORE
data/.rubocop.yml CHANGED
@@ -4,6 +4,9 @@ AllCops:
4
4
  - Gemfile
5
5
  TargetRubyVersion: 2.3
6
6
 
7
+ Metrics/ClassLength:
8
+ Max: 150
9
+
7
10
  Metrics/LineLength:
8
11
  Max: 120
9
12
 
data/.travis.yml CHANGED
@@ -1,10 +1,15 @@
1
1
  sudo: false
2
2
  language: ruby
3
+ addons:
4
+ postgresql: "9.6"
3
5
  rvm:
4
- - 2.3.7
5
- - 2.4.4
6
- - 2.5.1
6
+ - 2.4.6
7
+ - 2.5.5
8
+ - 2.6.3
7
9
  env:
10
+ - RAILS=6-0 DB=sqlite
11
+ - RAILS=6-0 DB=pg
12
+ - RAILS=6-0 DB=mysql
8
13
  - RAILS=5-2 DB=sqlite
9
14
  - RAILS=5-2 DB=pg
10
15
  - RAILS=5-2 DB=mysql
@@ -14,6 +19,14 @@ env:
14
19
  - RAILS=4-2 DB=sqlite
15
20
  - RAILS=4-2 DB=pg
16
21
  - RAILS=4-2 DB=mysql
22
+ matrix:
23
+ exclude:
24
+ - rvm: 2.4.6
25
+ env: RAILS=6-0 DB=mysql
26
+ - rvm: 2.4.6
27
+ env: RAILS=6-0 DB=pg
28
+ - rvm: 2.4.6
29
+ env: RAILS=6-0 DB=sqlite
17
30
  before_script:
18
31
  - psql -c 'create database active_reporting_test;' -U postgres
19
32
  - mysql -e 'create database active_reporting_test collate utf8_general_ci;'
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## 0.4.1 (2019-05-28)
2
+
3
+ ### Features
4
+
5
+ * Hierarchical dimensions may now have custom keys in result (#16) - *andresgutgon*
6
+
7
+ ### Misc
8
+
9
+ * Test against Raisl 6.0RC
10
+ * Loosen AR requirements. The gem will install for any AR version, but only ones listed in the README are supported
11
+ * Test against active Rubies
12
+
1
13
  ## 0.4.0 (2018-05-02)
2
14
 
3
15
  ### Breaking Changes
@@ -15,7 +27,7 @@
15
27
  * Specify rescue from LoadError for ransack (#9) - *niborg*
16
28
  * Fix ransack fallback logic (#8) - *germanotm*
17
29
 
18
- ## Misc
30
+ ### Misc
19
31
 
20
32
  * Test against Rails 5.2
21
33
  * Test against Ruby 2.5
data/Gemfile CHANGED
@@ -10,14 +10,22 @@ db = ENV['DB'] || 'sqlite'
10
10
  case rails
11
11
  when '4-2'
12
12
  gem 'activerecord', '~> 4.2.0'
13
- if ENV['DB'] == 'pg'
14
- gem 'pg', '~> 0.18'
15
- end
16
- if ENV['DB'] == 'mysql'
17
- gem 'mysql2', '~> 0.3.18'
18
- end
19
13
  when '5-1'
20
14
  gem 'activerecord', '~> 5.1.0'
21
- else
15
+ when '5-2'
22
16
  gem 'activerecord', '~> 5.2.0'
17
+ when '6-0'
18
+ gem 'activerecord', '6.0.0.rc1'
19
+ end
20
+
21
+ case rails
22
+ when '4-2'
23
+ case ENV['DB']
24
+ when 'pg'
25
+ gem 'pg', '~> 0.18'
26
+ when 'mysql'
27
+ gem 'mysql2', '~> 0.3.18'
28
+ when 'sqlite'
29
+ gem 'sqlite3', '~> 1.3.0'
30
+ end
23
31
  end
data/README.md CHANGED
@@ -8,9 +8,9 @@ ActiveReporting implements various terminology used in Relational Online Analyti
8
8
 
9
9
  ActiveReporting officially supports MySQL, PostgreSQL, and SQLite.
10
10
 
11
- ActiveReporting officially supports Ruby 2.3, 2.4, and 2.5.
11
+ ActiveReporting officially supports Ruby 2.4 and later. Other versions may work, but are not supported.
12
12
 
13
- ActiveReporting officially supports Rails 4.2, 5.1, and 5.2.
13
+ ActiveReporting officially supports Rails 4.2, 5.1, and 5.2. Other versions may work, but are not supported.
14
14
 
15
15
  ## Installation
16
16
 
@@ -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, {order_date: :month}]`)
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, {order_date: :month}]`). In hierarchies you can customize the label in this way: `[{order_date: { label: :month, name: :a_custom_name_for_month }}]`. If you use a hash instead of a Symbol to define a hierarchy the `label` item must be a valid field in your table. The `name` can be whatever you want.
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
 
@@ -342,7 +342,7 @@ metric = ActiveReporting::Metric.new(
342
342
  dimension_filter: {months_ago: 1}
343
343
  )
344
344
 
345
- report = ActiveReporting.new(metric, dimension_filter: {from_region: 'North'}, dimension_identifiers: false)
345
+ report = ActiveReporting::Report.new(metric, dimension_filter: {from_region: 'North'}, dimension_identifiers: false)
346
346
  report.run
347
347
  => [{order_count: 17, sales_rep: 'Mary Sue'}]
348
348
  ```
@@ -24,8 +24,8 @@ Gem::Specification.new do |spec|
24
24
 
25
25
  spec.required_ruby_version = '>= 2.3'
26
26
 
27
- spec.add_dependency 'activerecord', '>= 4.2.0'
28
- spec.add_dependency 'activesupport', '>= 4.2.0'
27
+ spec.add_dependency 'activerecord'
28
+ spec.add_dependency 'activesupport'
29
29
 
30
30
  spec.add_development_dependency 'bundler'
31
31
  spec.add_development_dependency 'minitest', '~> 5.0'
@@ -15,16 +15,35 @@ module ActiveReporting
15
15
  Array(dimensions).map do |dim|
16
16
  dimension_name, label = dim.is_a?(Hash) ? Array(dim).flatten : [dim, nil]
17
17
  found_dimension = fact_model.dimensions[dimension_name.to_sym]
18
- raise UnknownDimension, "Dimension '#{dim}' not found on fact model '#{fact_model}'" if found_dimension.nil?
19
- new(found_dimension, label: label)
18
+
19
+ raise(UnknownDimension, "Dimension '#{dim}' not found on fact model '#{fact_model}'") if found_dimension.nil?
20
+
21
+ new(found_dimension, label_config(label))
20
22
  end
21
23
  end
22
24
 
25
+ # If you pass a symbol it means you just indicate
26
+ # the field on that dimension. With a hash you can
27
+ # customize the name of the label
28
+ #
29
+ # @param [Symbol|Hash] label
30
+ def self.label_config(label)
31
+ return { label: label } unless label.is_a?(Hash)
32
+
33
+ {
34
+ label: label[:field],
35
+ label_name: label[:name]
36
+ }
37
+ end
38
+
23
39
  # @param dimension [ActiveReporting::Dimension]
24
- # @option label [Symbol] Hierarchical dimension to be used as a label
25
- def initialize(dimension, label: nil)
40
+ # @option label [Maybe<Symbol>] Hierarchical dimension to be used as a label
41
+ # @option label_name [Maybe<Symbol|String>] Hierarchical dimension custom name
42
+ def initialize(dimension, label: nil, label_name: nil)
26
43
  @dimension = dimension
27
- determine_label(label)
44
+
45
+ determine_label_field(label)
46
+ determine_label_name(label_name)
28
47
  end
29
48
 
30
49
  # The foreign key to use in queries
@@ -40,7 +59,7 @@ module ActiveReporting
40
59
  def select_statement(with_identifier: true)
41
60
  return [degenerate_select_fragment] if type == Dimension::TYPES[:degenerate]
42
61
 
43
- ss = ["#{label_fragment} AS #{name}"]
62
+ ss = ["#{label_fragment} AS #{@label_name}"]
44
63
  ss << "#{identifier_fragment} AS #{name}_identifier" if with_identifier
45
64
  ss
46
65
  end
@@ -75,14 +94,18 @@ module ActiveReporting
75
94
 
76
95
  private ####################################################################
77
96
 
78
- def determine_label(label)
79
- @label = if label.present? && validate_hierarchical_label(label)
80
- label.to_sym
97
+ def determine_label_field(label_field)
98
+ @label = if label_field.present? && validate_hierarchical_label(label_field)
99
+ label_field.to_sym
81
100
  else
82
101
  dimension_fact_model.dimension_label || Configuration.default_dimension_label
83
102
  end
84
103
  end
85
104
 
105
+ def determine_label_name(label_name)
106
+ @label_name = label_name ? "#{name}_#{label_name}" : name
107
+ end
108
+
86
109
  def validate_hierarchical_label(hierarchical_label)
87
110
  if datetime?
88
111
  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.4.0'
4
+ VERSION = '0.4.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.4.0
4
+ version: 0.4.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: 2018-05-03 00:00:00.000000000 Z
11
+ date: 2019-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 4.2.0
19
+ version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 4.2.0
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 4.2.0
33
+ version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 4.2.0
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -185,8 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
185
185
  - !ruby/object:Gem::Version
186
186
  version: '0'
187
187
  requirements: []
188
- rubyforge_project:
189
- rubygems_version: 2.6.14
188
+ rubygems_version: 3.0.1
190
189
  signing_key:
191
190
  specification_version: 4
192
191
  summary: Add relational OLAP-like functionality for ActiveRecord