ruport 0.6.0 → 0.6.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.
- data/AUTHORS +4 -0
- data/CHANGELOG +10 -1
- data/Rakefile +1 -1
- data/examples/simple_table_interface.rb +20 -0
- data/lib/ruport.rb +87 -69
- data/lib/ruport/attempt.rb +1 -1
- data/lib/ruport/config.rb +198 -166
- data/lib/ruport/data.rb +6 -1
- data/lib/ruport/data/collection.rb +15 -8
- data/lib/ruport/data/groupable.rb +68 -6
- data/lib/ruport/data/record.rb +73 -34
- data/lib/ruport/data/record.rb~ +236 -0
- data/lib/ruport/data/set.rb +48 -13
- data/lib/ruport/data/table.rb +164 -74
- data/lib/ruport/data/table.rb.rej +67 -0
- data/lib/ruport/data/table.rb~ +153 -68
- data/lib/ruport/data/taggable.rb +37 -9
- data/lib/ruport/format.rb +1 -1
- data/lib/ruport/mailer.rb +41 -27
- data/lib/ruport/meta_tools.rb +26 -11
- data/lib/ruport/query.rb +102 -68
- data/lib/ruport/query/sql_split.rb +1 -1
- data/lib/ruport/report.rb +84 -58
- data/lib/ruport/report/graph.rb +1 -1
- data/lib/ruport/report/invoice.rb +1 -1
- data/test/test_query.rb +305 -48
- data/test/test_query.rb.rej +161 -0
- data/test/test_query.rb~ +337 -0
- data/test/test_record.rb +6 -0
- data/test/test_table.rb +18 -0
- data/test/test_table.rb~ +336 -0
- data/test/unit.log +180 -6
- metadata +8 -2
data/AUTHORS
CHANGED
@@ -31,3 +31,7 @@ Simon Claret:
|
|
31
31
|
Daniel Berger:
|
32
32
|
- we vendored and modified attempt.rb to support it directly in Report.
|
33
33
|
Original website: http://raa.ruby-lang.org/project/attempt/
|
34
|
+
|
35
|
+
Marshall T. Vandegrift:
|
36
|
+
- Fixed a bug in Record's struct-like accessors (method_missing)
|
37
|
+
- Provided performance enhancements and tests for query.rb
|
data/CHANGELOG
CHANGED
@@ -1,4 +1,13 @@
|
|
1
|
-
The current version of Ruby Reports is 0.6.
|
1
|
+
The current version of Ruby Reports is 0.6.1
|
2
|
+
|
3
|
+
changes since 0.6.0
|
4
|
+
|
5
|
+
- Fixed Table.load() bug. (Now accepts block properly)
|
6
|
+
- 100% C0 coverage for Query via Mocha. (Thanks Marshall!)
|
7
|
+
- Row by row Query iteration no longer grabs entire result set first
|
8
|
+
- Major performance enhancements to Groupable
|
9
|
+
- Reformatted and enhanced API documentation
|
10
|
+
- Added simple table interface example
|
2
11
|
|
3
12
|
changes since 0.5.4
|
4
13
|
|
data/Rakefile
CHANGED
@@ -23,7 +23,7 @@ end
|
|
23
23
|
|
24
24
|
spec = Gem::Specification.new do |spec|
|
25
25
|
spec.name = LEAN ? "lean-ruport" : "ruport"
|
26
|
-
spec.version = "0.6.
|
26
|
+
spec.version = "0.6.1"
|
27
27
|
spec.platform = Gem::Platform::RUBY
|
28
28
|
spec.summary = "A generalized Ruby report generation and templating engine."
|
29
29
|
spec.files = Dir.glob("{examples,lib,test,bin}/**/**/**/*") +
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "ruport"
|
2
|
+
class SimpleTableShortcut < Ruport::Report
|
3
|
+
|
4
|
+
prepare do
|
5
|
+
log_file "foo.log"
|
6
|
+
@table = table(%w[a b c]) do |t|
|
7
|
+
t << [1,2,3]
|
8
|
+
t << { "a" => 1, "c" => 9, "b" => 2 }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
generate do
|
13
|
+
@table.to_csv
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
SimpleTableShortcut.run(:tries => 3, :interval => 5) { |r|
|
19
|
+
puts r.results
|
20
|
+
}
|
data/lib/ruport.rb
CHANGED
@@ -1,69 +1,87 @@
|
|
1
|
-
# ruport.rb : Ruby Reports
|
2
|
-
#
|
3
|
-
# Author: Gregory T. Brown (gregory.t.brown at gmail dot com)
|
4
|
-
#
|
5
|
-
# Copyright (c) 2006, All Rights Reserved.
|
6
|
-
#
|
7
|
-
# This is free software. You may modify and redistribute this freely under
|
8
|
-
# your choice of the GNU General Public License or the Ruby License.
|
9
|
-
#
|
10
|
-
# See LICENSE and COPYING for details
|
11
|
-
#
|
12
|
-
module Ruport
|
13
|
-
|
14
|
-
VERSION = "0.6.
|
15
|
-
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
# <tt>:
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
# <tt>:
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
# can
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
#
|
54
|
-
|
55
|
-
|
56
|
-
#
|
57
|
-
#
|
58
|
-
#
|
59
|
-
#
|
60
|
-
#
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
1
|
+
# ruport.rb : Ruby Reports top level module
|
2
|
+
#
|
3
|
+
# Author: Gregory T. Brown (gregory.t.brown at gmail dot com)
|
4
|
+
#
|
5
|
+
# Copyright (c) 2006, All Rights Reserved.
|
6
|
+
#
|
7
|
+
# This is free software. You may modify and redistribute this freely under
|
8
|
+
# your choice of the GNU General Public License or the Ruby License.
|
9
|
+
#
|
10
|
+
# See LICENSE and COPYING for details
|
11
|
+
#
|
12
|
+
module Ruport
|
13
|
+
|
14
|
+
VERSION = "0.6.1"
|
15
|
+
|
16
|
+
#
|
17
|
+
# This method is Ruport's logging and error interface. It can generate
|
18
|
+
# warnings or raise fatal errors, logging +message+ to the file defined by
|
19
|
+
# <tt>Config::log_file</tt>.
|
20
|
+
#
|
21
|
+
# You can configure the logging preferences with the +options+ hash.
|
22
|
+
# Available options are:
|
23
|
+
#
|
24
|
+
# <b><tt>:status</tt></b>:: Sets the severity level. This defaults to
|
25
|
+
# <tt>:warn</tt>, which will invoke
|
26
|
+
# <tt>Logger#warn</tt>. A status of
|
27
|
+
# <tt>:fatal</tt> will invoke
|
28
|
+
# <tt>Logger#fatal</tt> and raise an exception.
|
29
|
+
# <b><tt>:output</tt></b>:: Optional 2nd output. By default, <tt>log()</tt>
|
30
|
+
# will print warnings to <tt>$stderr</tt> in
|
31
|
+
# addition to <tt>Config::log_file</tt>. You
|
32
|
+
# can redirect this to any I/O object with this
|
33
|
+
# option.
|
34
|
+
# <b><tt>:level</tt></b>:: Set this to <tt>:log_only</tt> to disable
|
35
|
+
# secondary output. If you want to globally
|
36
|
+
# override this setting for all calls to
|
37
|
+
# <tt>log()</tt> (which can be useful for
|
38
|
+
# debugging), you can set
|
39
|
+
# <tt>Config::enable_paranoia</tt>.
|
40
|
+
# <b><tt>:exception</tt></b>:: The +Exception+ to throw on failure. This
|
41
|
+
# defaults to +RunTimeError+.
|
42
|
+
#
|
43
|
+
def self.log(message, options={})
|
44
|
+
options = {:status => :warn, :output => $stderr}.merge(options)
|
45
|
+
options[:output].puts "[!!] #{message}" unless
|
46
|
+
options[:level].eql?(:log_only) and not Ruport::Config.paranoid?
|
47
|
+
Ruport::Config::logger.send(options[:status],message) if Config.logger
|
48
|
+
if options[:status].eql? :fatal
|
49
|
+
raise(options[:exception] || RuntimeError, message)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# Alias for <tt>Ruport.log</tt>.
|
54
|
+
def self.complain(*args); Ruport.log(*args) end
|
55
|
+
|
56
|
+
#
|
57
|
+
# This method yields a <tt>Ruport::Config</tt> object, allowing you to
|
58
|
+
# set the configuration options for your application.
|
59
|
+
#
|
60
|
+
# Example:
|
61
|
+
#
|
62
|
+
# Ruport.configure do |c|
|
63
|
+
#
|
64
|
+
# c.source :default,
|
65
|
+
# :dsn => "dbi:mysql:foo",
|
66
|
+
# :user => "clyde",
|
67
|
+
# :password => "pman"
|
68
|
+
#
|
69
|
+
# c.mailer :default,
|
70
|
+
# :host => "mail.example.com",
|
71
|
+
# :address => "inky@example.com"
|
72
|
+
#
|
73
|
+
# end
|
74
|
+
#
|
75
|
+
def self.configure(&block)
|
76
|
+
block.call(Ruport::Config)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
require "ruport/attempt"
|
81
|
+
require "ruport/config"
|
82
|
+
require "ruport/data"
|
83
|
+
require "ruport/meta_tools"
|
84
|
+
require "ruport/report"
|
85
|
+
require "ruport/format"
|
86
|
+
require "ruport/query"
|
87
|
+
require "ruport/mailer"
|
data/lib/ruport/attempt.rb
CHANGED
data/lib/ruport/config.rb
CHANGED
@@ -1,166 +1,198 @@
|
|
1
|
-
# ruport/config.rb : Ruby Reports configuration system
|
2
|
-
#
|
3
|
-
# Author: Gregory T. Brown (gregory.t.brown at gmail dot com)
|
4
|
-
#
|
5
|
-
# Copyright (c) 2006, All Rights Reserved.
|
6
|
-
#
|
7
|
-
# This is free software. You may modify and redistribute this freely under
|
8
|
-
# your choice of the GNU General Public License or the Ruby License.
|
9
|
-
#
|
10
|
-
# See LICENSE and COPYING for details
|
11
|
-
#
|
12
|
-
require "ostruct"
|
13
|
-
module Ruport
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
#
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
51
|
-
#
|
52
|
-
#
|
53
|
-
#
|
54
|
-
#
|
55
|
-
#
|
56
|
-
#
|
57
|
-
#
|
58
|
-
#
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
#
|
73
|
-
#
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
#
|
81
|
-
#
|
82
|
-
#
|
83
|
-
#
|
84
|
-
#
|
85
|
-
#
|
86
|
-
#
|
87
|
-
#
|
88
|
-
#
|
89
|
-
#
|
90
|
-
#
|
91
|
-
#
|
92
|
-
#
|
93
|
-
def
|
94
|
-
return
|
95
|
-
|
96
|
-
|
97
|
-
end
|
98
|
-
|
99
|
-
|
100
|
-
#
|
101
|
-
#
|
102
|
-
#
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
#
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
#
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
#
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
#
|
123
|
-
|
124
|
-
|
125
|
-
#
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
#
|
135
|
-
def
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
end
|
153
|
-
|
154
|
-
#
|
155
|
-
def
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
1
|
+
# ruport/config.rb : Ruby Reports configuration system
|
2
|
+
#
|
3
|
+
# Author: Gregory T. Brown (gregory.t.brown at gmail dot com)
|
4
|
+
#
|
5
|
+
# Copyright (c) 2006, All Rights Reserved.
|
6
|
+
#
|
7
|
+
# This is free software. You may modify and redistribute this freely under
|
8
|
+
# your choice of the GNU General Public License or the Ruby License.
|
9
|
+
#
|
10
|
+
# See LICENSE and COPYING for details
|
11
|
+
#
|
12
|
+
require "ostruct"
|
13
|
+
module Ruport
|
14
|
+
#
|
15
|
+
# === Overview
|
16
|
+
#
|
17
|
+
# This class serves as the configuration system for Ruport.
|
18
|
+
#
|
19
|
+
# The source and mailer defined as <tt>:default</tt> will become the
|
20
|
+
# fallback values if you don't specify one in <tt>Report::Mailer</tt> or
|
21
|
+
# <tt>Query</tt>, but you may define as many sources as you like and switch
|
22
|
+
# between them later.
|
23
|
+
#
|
24
|
+
# === Example
|
25
|
+
#
|
26
|
+
# The most common way to access your application configuration is through
|
27
|
+
# the <tt>Ruport.configure</tt> method, like this:
|
28
|
+
#
|
29
|
+
# Ruport.configure do |config|
|
30
|
+
#
|
31
|
+
# config.log_file 'foo.log'
|
32
|
+
# config.enable_paranoia
|
33
|
+
#
|
34
|
+
# config.source :default,
|
35
|
+
# :dsn => "dbi:mysql:somedb:db.blixy.org",
|
36
|
+
# :user => "root",
|
37
|
+
# :password => "chunky_bacon"
|
38
|
+
#
|
39
|
+
# config.mailer :default,
|
40
|
+
# :host => "mail.chunkybacon.org",
|
41
|
+
# :address => "chunky@bacon.net",
|
42
|
+
# :user => "cartoon",
|
43
|
+
# :password => "fox",
|
44
|
+
# :port => 25,
|
45
|
+
# :auth_type => :login
|
46
|
+
#
|
47
|
+
# end
|
48
|
+
#
|
49
|
+
# You can accomplish the same thing by opening the class directly:
|
50
|
+
#
|
51
|
+
# class Ruport::Config
|
52
|
+
#
|
53
|
+
# source :default,
|
54
|
+
# :dsn => "dbi:mysql:some_db",
|
55
|
+
# :user => "root"
|
56
|
+
#
|
57
|
+
# mailer :default,
|
58
|
+
# :host => "mail.iheartwhy.com",
|
59
|
+
# :address => "sandal@ruby-harmonix.net",
|
60
|
+
# :user => "sandal",
|
61
|
+
# :password => "abc123"
|
62
|
+
#
|
63
|
+
# logfile 'foo.log'
|
64
|
+
#
|
65
|
+
# end
|
66
|
+
#
|
67
|
+
# Saving this config information into a file and then requiring it allows
|
68
|
+
# you to share configurations between Ruport applications.
|
69
|
+
#
|
70
|
+
module Config
|
71
|
+
module_function
|
72
|
+
#
|
73
|
+
# :call-seq:
|
74
|
+
# source(source_name, options)
|
75
|
+
#
|
76
|
+
# Creates or retrieves a database source configuration. Available options
|
77
|
+
# are:
|
78
|
+
# <b><tt>:user</tt></b>:: The user used to connect to the database.
|
79
|
+
# <b><tt>:password</tt></b>:: The password to use to connect to the
|
80
|
+
# database (optional).
|
81
|
+
# <b><tt>:dsn</tt></b>:: The dsn string that dbi will use to
|
82
|
+
# access the database.
|
83
|
+
#
|
84
|
+
# Example (setting a source):
|
85
|
+
# source :default, :user => "root",
|
86
|
+
# :password => "clyde",
|
87
|
+
# :dsn => "dbi:mysql:blinkybase"
|
88
|
+
#
|
89
|
+
# Example (retrieving a source):
|
90
|
+
# db = source(:default) #=> <OpenStruct ..>
|
91
|
+
# db.dsn #=> "dbi:mysql:blinkybase"
|
92
|
+
#
|
93
|
+
def source(*args)
|
94
|
+
return sources[args.first] if args.length == 1
|
95
|
+
sources[args.first] = OpenStruct.new(*args[1..-1])
|
96
|
+
check_source(sources[args.first],args.first)
|
97
|
+
end
|
98
|
+
|
99
|
+
#
|
100
|
+
# :call-seq:
|
101
|
+
# mailer(mailer_name, options)
|
102
|
+
#
|
103
|
+
# Creates or retrieves a mailer configuration. Available options:
|
104
|
+
# <b><tt>:host</tt></b>:: The SMTP host to use.
|
105
|
+
# <b><tt>:address</tt></b>:: The email address to send to.
|
106
|
+
# <b><tt>:user</tt></b>:: The username to use on the SMTP server
|
107
|
+
# <b><tt>:password</tt></b>:: The password to use on the SMTP server.
|
108
|
+
# Optional.
|
109
|
+
# <b><tt>:port</tt></b>:: The SMTP port to use. Optional, defaults
|
110
|
+
# to 25.
|
111
|
+
# <b><tt>:auth_type</tt></b>:: SMTP authorization method. Optional,
|
112
|
+
# defaults to <tt>:plain</tt>.
|
113
|
+
# <b><tt>:mail_klass</tt></b>:: If you don't want to use the default
|
114
|
+
# <tt>MailFactory</tt> object, you can
|
115
|
+
# pass another mailer to use here.
|
116
|
+
#
|
117
|
+
# Example (creating a mailer config):
|
118
|
+
# mailer :alternate, :host => "mail.test.com",
|
119
|
+
# :address => "test@test.com",
|
120
|
+
# :user => "test",
|
121
|
+
# :password => "blinky"
|
122
|
+
# :auth_type => :cram_md5
|
123
|
+
#
|
124
|
+
# Example (retreiving a mailer config):
|
125
|
+
# mail_conf = mailer(:alternate) #=> <OpenStruct ..>
|
126
|
+
# mail_conf.address #=> test@test.com
|
127
|
+
#
|
128
|
+
def mailer(*args)
|
129
|
+
return mailers[args.first] if args.length == 1
|
130
|
+
mailers[args.first] = OpenStruct.new(*args[1..-1])
|
131
|
+
check_mailer(mailers[args.first],args.first)
|
132
|
+
end
|
133
|
+
|
134
|
+
# The file that <tt>Ruport.log()</tt> will write to.
|
135
|
+
def log_file(file)
|
136
|
+
@logger = Logger.new(file)
|
137
|
+
end
|
138
|
+
|
139
|
+
# Same as <tt>Config.log_file</tt>, but accessor style.
|
140
|
+
def log_file=(file)
|
141
|
+
log_file(file)
|
142
|
+
end
|
143
|
+
|
144
|
+
# Alias for <tt>sources[:default]</tt>.
|
145
|
+
def default_source
|
146
|
+
sources[:default]
|
147
|
+
end
|
148
|
+
|
149
|
+
# Alias for <tt>mailers[:default]</tt>.
|
150
|
+
def default_mailer
|
151
|
+
mailers[:default]
|
152
|
+
end
|
153
|
+
|
154
|
+
# Returns all <tt>source</tt>s defined in this <tt>Config</tt>.
|
155
|
+
def sources; @sources ||= {}; end
|
156
|
+
|
157
|
+
# Returns all the <tt>mailer</tt>s defined in this <tt>Config</tt>.
|
158
|
+
def mailers; @mailers ||= {}; end
|
159
|
+
|
160
|
+
# Returns the currently active logger.
|
161
|
+
def logger; @logger; end
|
162
|
+
|
163
|
+
# Forces all messages marked <tt>:log_only</tt> to print anyway.
|
164
|
+
def enable_paranoia; @paranoid = true; end
|
165
|
+
|
166
|
+
# Disables the printing of <tt>:log_only</tt> messages.
|
167
|
+
def disable_paranoia; @paranoid = false; end
|
168
|
+
|
169
|
+
# Sets paranoid status.
|
170
|
+
def paranoid=(val); @paranoid = val; end
|
171
|
+
|
172
|
+
# Checks to see if paranoia is enabled.
|
173
|
+
def paranoid?; !!@paranoid; end
|
174
|
+
|
175
|
+
# Verifies that you have provided a DSN for your source.
|
176
|
+
def check_source(settings,label) # :nodoc:
|
177
|
+
unless settings.dsn
|
178
|
+
Ruport.complain(
|
179
|
+
"Missing DSN for source #{label}!",
|
180
|
+
:status => :fatal, :level => :log_only,
|
181
|
+
:exception => ArgumentError
|
182
|
+
)
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
# Verifies that you have provided a host for your mailer.
|
187
|
+
def check_mailer(settings, label) # :nodoc:
|
188
|
+
unless settings.host
|
189
|
+
Ruport.complain(
|
190
|
+
"Missing host for mailer #{label}",
|
191
|
+
:status => :fatal, :level => :log_only,
|
192
|
+
:exception => ArgumentError
|
193
|
+
)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
end
|
198
|
+
end
|