Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.bundle
.config
.idea
.rspec_status
.yardoc
Gemfile.lock
InstalledFiles
Expand Down
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
--color
--order random
--require spec_helper
42 changes: 42 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
AllCops:
TargetRubyVersion: 2.4

inherit_gem:
rubocop_defaults: .rubocop.yml

inherit_from: .rubocop_todo.yml

inherit_mode:
merge:
- Exclude

Lint/UnusedMethodArgument:
Exclude:
- 'lib/compendium/abstract_chart_provider.rb'

RSpec/ExampleLength:
Max: 10

Style/DateTime:
Exclude:
- 'spec/compendium/param_types/date_spec.rb'

Style/FormatString:
EnforcedStyle: sprintf

Style/FormatStringToken:
EnforcedStyle: unannotated

Style/IfUnlessModifier:
Exclude:
- 'Gemfile'

Style/MethodMissingSuper:
Exclude:
- 'lib/compendium/presenters/settings/query.rb'

Style/RescueModifier:
Enabled: false

Style/SymbolArray:
MinSize: 3
33 changes: 33 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2018-08-14 15:01:45 -0400 using RuboCop version 0.58.2.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 16
Metrics/AbcSize:
Max: 33

# Offense count: 3
Metrics/CyclomaticComplexity:
Max: 7

# Offense count: 14
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 15

# Offense count: 2
Metrics/PerceivedComplexity:
Max: 9

# Offense count: 6
RSpec/AnyInstance:
Exclude:
- 'spec/compendium/dsl/query_spec.rb'
- 'spec/compendium/presenters/chart_spec.rb'
- 'spec/compendium/queries/collection_spec.rb'
- 'spec/compendium/queries/query_spec.rb'
- 'spec/compendium/report_spec.rb'
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ language: ruby
cache:
- bundler
rvm:
- 2.2.9
- 2.3.6
- 2.4.3
- 2.5.0
- 2.2.10
- 2.3.7
- 2.4.4
- 2.5.1
before_install: gem install bundler -v 1.16.1
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## Future
* Removed support for Ruby < 2.2
* Added support for Ruby 2.5
* Changed `collect: :active_record` query option to `sql: true`
* Replaced `mount_compendium` with `mount Compendium::Engine => '/path'`

## 1.2.2
* Allow report options to be hidden
* Allow the collection in a CollectionQuery to be generated at report runtime using a proc
Expand Down
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ source 'https://rubygems.org'
# Specify your gem's dependencies in compendium.gemspec
gemspec

group :development do
gem 'rubocop_defaults', git: 'https://github.com/dvandersluis/rubocop_defaults.git'
end

if RUBY_VERSION >= '2.4'
gem 'json', github: 'flori/json', branch: 'v1.8'
end
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class MyReport < Compendium::Report
end
end

# Define a query which collects data by using AR directly
query :on_hand_inventory, collect: :active_record do |params|
# Define a query which doesn't execute SQL (for instance if you want to return AR models)
query :on_hand_inventory, execute_sql: false do |params|
Items.where(in_stock: true)
end

Expand Down Expand Up @@ -84,7 +84,7 @@ If validation is set up on any options, calling `valid?` on the report will vali

```ruby
class MyReport < Compendium::Report
options :starting_on, :date, validates: { presence: true }
option :starting_on, :date, validates: { presence: true }
end

r = MyReport.new
Expand Down Expand Up @@ -144,7 +144,13 @@ end

#### Collection Queries

Sometimes you'll want to run a collection over a collection of data; for this, you can use a **collection query**. A collection query will perform the same query for each element of a hash or array, or for each result of a query. A collection is specified via `collection: [...]`, `collection: { ... }` or `collection: query` (note not a symbol but an actual query object).
Sometimes you'll want to run the same query over a collection of data; for this, you can use a **collection query**. A collection query will perform the same query for each element of a hash or array, or for each result of a query. A collection is specified via `collection:`, where the value is an array, hash, proc, or `Queries::Query`.

```ruby
query :popular_orders, collection: popular_items do |params, id|
Orders.where(item_id: id)
end
```

### Tying into your Rails application

Expand Down
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require "bundler/gem_tasks"
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec)
task :default => :spec
task :default => :spec
12 changes: 12 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Upgrading Compendium

## Upgrading to >= 2.0.0

### Queries
* The `collect` option has been replaced with `sql` (default `false`), in order to decouple queries from
active record. Replace `collect: :active_record` with `sql: false`.

### Rails
#### Routes
* The `mount_compendium` routing monkey patch was removed in favour of actual routes. The actual routes
are slightly less configurable. Replace `mount_compendium` with `mount Compendium::Engine => '/path'`
30 changes: 0 additions & 30 deletions app/classes/compendium/presenters/base.rb

This file was deleted.

84 changes: 0 additions & 84 deletions app/classes/compendium/presenters/chart.rb

This file was deleted.

32 changes: 0 additions & 32 deletions app/classes/compendium/presenters/csv.rb

This file was deleted.

32 changes: 0 additions & 32 deletions app/classes/compendium/presenters/metric.rb

This file was deleted.

Loading