ar_report 0.0.1.alpha
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +72 -0
- data/Rakefile +2 -0
- data/ar_report.gemspec +24 -0
- data/lib/ar_report/version.rb +3 -0
- data/lib/ar_report.rb +79 -0
- data/lib/generators/ar_report/install_generator.rb +15 -0
- data/lib/generators/ar_report/templates/ar_report.yml +13 -0
- data/lib/railtie.rb +10 -0
- data/lib/settings.rb +25 -0
- data/tasks/ar_report.rake +14 -0
- metadata +123 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Manish Puri
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# ArReport
|
2
|
+
|
3
|
+
Install, Generate and email.. cant get simpler than this.. Generate basic ActiveRecord Report with ease.
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'ar_report'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install ar_report
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
This gem uses the spreadsheet and mail gem to send out reports to a email specified email address.
|
23
|
+
|
24
|
+
Once you install the gem, Use it as follows.
|
25
|
+
|
26
|
+
Run,
|
27
|
+
|
28
|
+
$ rails g ar_report:install
|
29
|
+
|
30
|
+
This will generate a config/ar_report.yml in your application directory.
|
31
|
+
|
32
|
+
When you open this file, you can specify various options fir your report like models, report_name, report_from and report_to. Following is the structure for the yml:
|
33
|
+
<pre>
|
34
|
+
ar_report:
|
35
|
+
models: #specify model name here for eg 'User' or array of models ['User', 'Post']
|
36
|
+
|
37
|
+
file_name: #specify name of the xls report to be attached
|
38
|
+
|
39
|
+
report_from: # specify email address of user from which you want to send the email.
|
40
|
+
|
41
|
+
report_to: # specify email address of users/group to whom you want to send an email to.
|
42
|
+
</pre>
|
43
|
+
|
44
|
+
Fill in al the required details and.. hey.. you are done..!
|
45
|
+
|
46
|
+
Just run the rake provided by the gem:
|
47
|
+
|
48
|
+
$ rake ar_report:generate
|
49
|
+
|
50
|
+
This will generate a xls file in your public folder.
|
51
|
+
|
52
|
+
You could also run:
|
53
|
+
|
54
|
+
$ rake ar_report:generate_and_email
|
55
|
+
|
56
|
+
This will not only generate an xls fie but will also mail it to the emai address specified in the ar_report.yml file.
|
57
|
+
|
58
|
+
Note: This gem depends on Mail gem to send out emails. So, Please specify the configs for the mail gem. Refer https://github.com/mikel/mail for details.
|
59
|
+
|
60
|
+
## Contributing
|
61
|
+
|
62
|
+
1. Fork it
|
63
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
64
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
65
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
66
|
+
5. Create new Pull Request
|
67
|
+
|
68
|
+
#ToDo
|
69
|
+
|
70
|
+
Specs.
|
71
|
+
|
72
|
+
:collision: :collision: :collision:
|
data/Rakefile
ADDED
data/ar_report.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/ar_report/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Manish Puri"]
|
6
|
+
gem.email = ["manishspuri@gmail.com"]
|
7
|
+
gem.description = %q{A wrapper to send model reports using using spreadsheet and mail gem}
|
8
|
+
gem.summary = %q{This gem will extract an excel report from a activerecord model and send a report to a specified email}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "ar_report"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = ArReport::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency 'rails'
|
19
|
+
gem.add_dependency 'spreadsheet'
|
20
|
+
|
21
|
+
gem.add_dependency 'mail'
|
22
|
+
gem.add_development_dependency 'rspec'
|
23
|
+
#gem.add_development_dependency 'sqlite3'
|
24
|
+
end
|
data/lib/ar_report.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
require "ar_report/version"
|
2
|
+
require 'yaml'
|
3
|
+
require 'settings'
|
4
|
+
require 'spreadsheet'
|
5
|
+
|
6
|
+
module ArReport
|
7
|
+
require "railtie" if defined?(Rails)
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def start(options={})
|
11
|
+
Settings.load!
|
12
|
+
generate_report
|
13
|
+
email_report if options[:mail]
|
14
|
+
schedule_report if options[:schedule]
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
def generate_report
|
19
|
+
begin
|
20
|
+
p 'Generating excel report...'
|
21
|
+
book = Spreadsheet::Workbook.new
|
22
|
+
get_valid_model_names.each do |class_name_str|
|
23
|
+
p 'Exporting.. '+ class_name_str.pluralize
|
24
|
+
sheet = book.create_worksheet :name => class_name_str
|
25
|
+
class_name=class_name_str.constantize
|
26
|
+
columns=class_name.column_names
|
27
|
+
columns.each { |x| sheet.row(0).push x}
|
28
|
+
|
29
|
+
class_eval(class_name_str).all.each_with_index do |record,i|
|
30
|
+
row_values =[]
|
31
|
+
|
32
|
+
columns.each do |column|
|
33
|
+
row_values << record.send(column)
|
34
|
+
end
|
35
|
+
|
36
|
+
row_values.each { |x|sheet.row(i+1).push x}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
spreadsheet = StringIO.new
|
40
|
+
p "Report Generated at 'public/#{get_file_name}'. Thankyou for using Ar_Report.!"
|
41
|
+
book.write "public/#{get_file_name}"
|
42
|
+
rescue
|
43
|
+
# raise "ArReport::Error: No models specified. Please add model names to config/ar_report.yml"
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
def email_report
|
50
|
+
raise "ArReport::Error: Please specify report_to and report_from email addresses in config/ar_report.yml" if (Settings.ar_report[:report_from].nil? || Settings.ar_report[:report_to].nil? )
|
51
|
+
|
52
|
+
file_name=get_file_name
|
53
|
+
mail = Mail.new do
|
54
|
+
from Settings.ar_report[:report_from]
|
55
|
+
to Settings.ar_report[:report_to]
|
56
|
+
subject Settings.ar_report[:report_to]
|
57
|
+
attachments[file_name] = File.read("#{Rails.root}/public/#{file_name}")
|
58
|
+
end
|
59
|
+
mail.deliver!
|
60
|
+
end
|
61
|
+
|
62
|
+
def get_valid_model_names
|
63
|
+
raise "No models specified. Please add model names to config/ar_report.yml" if Settings.ar_report[:models].nil?
|
64
|
+
Settings.ar_report[:models].gsub(/\s+/, "").split(',').delete_if{|a| class_eval(a).superclass!=ActiveRecord::Base rescue true}
|
65
|
+
end
|
66
|
+
|
67
|
+
def get_file_name
|
68
|
+
(Settings.ar_report[:file_name] || "ar_report_#{Date.today}") + '.xls'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module ArReport
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
source_root File.expand_path("../templates", __FILE__)
|
5
|
+
|
6
|
+
desc "Creates config file to your application."
|
7
|
+
|
8
|
+
def copy_initializer
|
9
|
+
require 'rails'
|
10
|
+
template '../templates/ar_report.yml', 'config/ar_report.yml'
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
ar_report:
|
2
|
+
models: #specify model name here for eg 'User' or array of models ['User'.'Post']
|
3
|
+
|
4
|
+
file_name: #specify name of the report to be attached
|
5
|
+
|
6
|
+
subject: #specify subject of the email to be sent.
|
7
|
+
|
8
|
+
report_from: # specify email addresses of the users/group to receive an email.
|
9
|
+
|
10
|
+
report_to: # specify email address from which you want to receive an email.
|
11
|
+
|
12
|
+
|
13
|
+
|
data/lib/railtie.rb
ADDED
data/lib/settings.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
module Settings
|
2
|
+
|
3
|
+
|
4
|
+
extend self
|
5
|
+
# again - it's a singleton, thus implemented as a self-extended module
|
6
|
+
@_settings = {}
|
7
|
+
|
8
|
+
def load!(options={})
|
9
|
+
@_settings = YAML::load(ERB.new(Rails.root.join("config", "ar_report.yml").read).result).with_indifferent_access
|
10
|
+
@_settings = newsets[options[:env].to_sym] if \
|
11
|
+
options[:env] && \
|
12
|
+
newsets[options[:env].to_sym]
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
def method_missing(name, *args, &block)
|
19
|
+
@_settings.with_indifferent_access[name.to_sym] ||
|
20
|
+
fail(NoMethodError, "unknown configuration root #{name}", caller)
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# Author Manish Puri
|
2
|
+
# Task to setup mailer
|
3
|
+
namespace :ar_report do
|
4
|
+
task :generate => :environment do
|
5
|
+
ArReport.start
|
6
|
+
end
|
7
|
+
|
8
|
+
task :generate_and_mail => :environment do
|
9
|
+
p 'Please note ar_report relies on mail gem to send out emails. Please make sure you have specified the SMTP settings
|
10
|
+
as required by the mail gem.'
|
11
|
+
ArReport.start(:mail=>true)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ar_report
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.alpha
|
5
|
+
prerelease: 6
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Manish Puri
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-02-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: spreadsheet
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: mail
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rspec
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: A wrapper to send model reports using using spreadsheet and mail gem
|
79
|
+
email:
|
80
|
+
- manishspuri@gmail.com
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- .gitignore
|
86
|
+
- Gemfile
|
87
|
+
- LICENSE
|
88
|
+
- README.md
|
89
|
+
- Rakefile
|
90
|
+
- ar_report.gemspec
|
91
|
+
- lib/ar_report.rb
|
92
|
+
- lib/ar_report/version.rb
|
93
|
+
- lib/generators/ar_report/install_generator.rb
|
94
|
+
- lib/generators/ar_report/templates/ar_report.yml
|
95
|
+
- lib/railtie.rb
|
96
|
+
- lib/settings.rb
|
97
|
+
- tasks/ar_report.rake
|
98
|
+
homepage: ''
|
99
|
+
licenses: []
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ! '>'
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: 1.3.1
|
116
|
+
requirements: []
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 1.8.23
|
119
|
+
signing_key:
|
120
|
+
specification_version: 3
|
121
|
+
summary: This gem will extract an excel report from a activerecord model and send
|
122
|
+
a report to a specified email
|
123
|
+
test_files: []
|