report_card 0.0.4 → 0.0.5

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: 5822cdf7b89f25ec936afa256af2e700a4d29739
4
- data.tar.gz: 7dc99f1424fde5c78c894a744e4b0576101f54c6
3
+ metadata.gz: c6cda23ee0f23eed670cc68f5a6e3746645c37d4
4
+ data.tar.gz: 4681b0afd0731b14e7bc2a25e84692a0216d1529
5
5
  SHA512:
6
- metadata.gz: c394db0e2fc9cd8a4f396ee2fd235dae06fbe3c6ac37b524522ffa4edc3db61b5c9cc1070d0680988695e366f1216a7880b138ebd367e250e500672bcf6fc37b
7
- data.tar.gz: badc5f22e1caedd6f399db6c419fd1ef502f7f9205c6dc94e0be40c0027ec0ef6aca6c709b6ce208b5369dbddc6560184a5bb4f5e36bfe4e164d39450a8df737
6
+ metadata.gz: eace107781ddb632f40f1f04406bd5fb7c6b83cb677965a3aebbb5873953905c0f318603f4d7901b5afaf8d2c0e5011e590f06d4709cfb95ba6591c2141c777f
7
+ data.tar.gz: 15c5ec29812edd3c7b976adf5aedee497a634746d6b7181db1c0a97e00074bc928363482af71d21114e9a3d4f0469354bd80092f07febd80fe38b1c3469b7f9d
@@ -6,11 +6,17 @@ module ReportCard
6
6
 
7
7
  def create
8
8
  if ReportCard::Report.exists?(params[:report_name])
9
- email = instance_eval(&ReportCard.recipient_email)
10
- ReportCard::Runner.perform_async(params[:report_name], email)
11
- redirect_to report_card_reports_path, flash: { success: 'Generating report. It will be emailed to you.' }
9
+
10
+ unless params.key?(:email_options)
11
+ params[:email_options] = {}
12
+ params[:email_options][:recipient_email] = instance_eval(&ReportCard.recipient_email)
13
+ end
14
+
15
+ flash_success = params[:flash_success] || instance_eval(&ReportCard.flash_success)
16
+ ReportCard::Runner.perform_async(params)
17
+ redirect_to :back, flash: { success: flash_success }
12
18
  else
13
- redirect_to report_card_reports_path, flash: { error: 'Could not find report' }
19
+ redirect_to :back, flash: { error: 'Could not find report' }
14
20
  end
15
21
  end
16
22
  end
@@ -1,11 +1,13 @@
1
1
  module ReportCard
2
2
  class Mailer < ActionMailer::Base
3
- def report(url, email)
3
+ def report(url, email_options)
4
4
  @url = url
5
-
6
- mail to: email,
7
- from: ReportCard.from_email,
8
- subject: 'Your report is ready'
5
+ @body = email_options['body'] || ReportCard.body
6
+ # email_options['recipient_email'] doesn't have default option here
7
+ # because it is a proc that is evaluated in ReportsController.
8
+ mail to: email_options['recipient_email'],
9
+ from: email_options['from_email'] || ReportCard.from_email,
10
+ subject: email_options['subject'] || ReportCard.subject
9
11
  end
10
12
  end
11
13
  end
@@ -1 +1 @@
1
- Download your report: <%= link_to @url, @url %>
1
+ <%= @body %> <%= link_to @url, @url %>
@@ -4,8 +4,9 @@ module ReportCard
4
4
  class Runner
5
5
  include Sidekiq::Worker
6
6
 
7
- def perform(klass_name, recipient_email)
8
- report = ReportCard::Report.find(klass_name).new
7
+ def perform(params)
8
+ report = ReportCard::Report.find(params['report_name']).new(params)
9
+ email_options = params['email_options']
9
10
 
10
11
  tempfile = Tempfile.new(['report_card', '.csv'])
11
12
  csv = CSV.open(tempfile, 'wb')
@@ -15,7 +16,7 @@ module ReportCard
15
16
  uploader = ReportCard::Uploader.new
16
17
  uploader.store!(csv)
17
18
 
18
- ReportCard::Mailer.report(uploader.url, recipient_email).deliver
19
+ ReportCard::Mailer.report(uploader.url, email_options).deliver
19
20
  end
20
21
  end
21
22
  end
@@ -7,8 +7,18 @@ module ReportCard
7
7
  self.parent_controller = 'ApplicationController'
8
8
 
9
9
  mattr_accessor :recipient_email
10
- self.recipient_email = -> { 'change-me@example.com' }
10
+ self.recipient_email = proc { 'change-me@example.com' }
11
11
 
12
12
  mattr_accessor :from_email
13
13
  self.from_email = 'change-me@example.com'
14
+
15
+ mattr_accessor :subject
16
+ self.subject = 'Your report is ready'
17
+
18
+ mattr_accessor :body
19
+ self.body = 'Download your report: '
20
+
21
+ mattr_accessor :flash_success
22
+ self.flash_success = proc { 'Generating report. It will be emailed to you.' }
23
+
14
24
  end
@@ -1,3 +1,5 @@
1
+ require 'carrierwave'
2
+
1
3
  module ReportCard
2
4
  class Engine < ::Rails::Engine
3
5
  initializer 'report_card.load_reports_in_development' do |app|
@@ -1,5 +1,7 @@
1
1
  module ReportCard
2
2
  class Report
3
+ attr_accessor :params
4
+
3
5
  class ReportNotFound < StandardError; end
4
6
 
5
7
  def self.all
@@ -18,5 +20,9 @@ module ReportCard
18
20
  def self.exists?(name)
19
21
  all.any? { |r| r.name == name }
20
22
  end
23
+
24
+ def initialize(params)
25
+ self.params = params
26
+ end
21
27
  end
22
28
  end
@@ -1,3 +1,3 @@
1
1
  module ReportCard
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
@@ -0,0 +1,15 @@
1
+  (0.1ms) begin transaction
2
+ --------------------------
3
+ ReportCardTest: test_truth
4
+ --------------------------
5
+  (0.1ms) rollback transaction
6
+  (0.1ms) begin transaction
7
+ --------------------------
8
+ ReportCardTest: test_truth
9
+ --------------------------
10
+  (0.1ms) rollback transaction
11
+  (0.1ms) begin transaction
12
+ --------------------------
13
+ ReportCardTest: test_truth
14
+ --------------------------
15
+  (0.0ms) rollback transaction
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: report_card
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Giancola
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-05 00:00:00.000000000 Z
11
+ date: 2015-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -123,7 +123,8 @@ files:
123
123
  - test/dummy/config/locales/en.yml
124
124
  - test/dummy/config/routes.rb
125
125
  - test/dummy/config/secrets.yml
126
- - test/dummy/log/development.log
126
+ - test/dummy/db/test.sqlite3
127
+ - test/dummy/log/test.log
127
128
  - test/dummy/public/404.html
128
129
  - test/dummy/public/422.html
129
130
  - test/dummy/public/500.html
@@ -151,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
152
  version: '0'
152
153
  requirements: []
153
154
  rubyforge_project:
154
- rubygems_version: 2.2.2
155
+ rubygems_version: 2.4.5
155
156
  signing_key:
156
157
  specification_version: 4
157
158
  summary: Write your domain-specific reporting code and let Report Card take care of
@@ -184,7 +185,8 @@ test_files:
184
185
  - test/dummy/config/routes.rb
185
186
  - test/dummy/config/secrets.yml
186
187
  - test/dummy/config.ru
187
- - test/dummy/log/development.log
188
+ - test/dummy/db/test.sqlite3
189
+ - test/dummy/log/test.log
188
190
  - test/dummy/public/404.html
189
191
  - test/dummy/public/422.html
190
192
  - test/dummy/public/500.html