ruport 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
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.0
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.0"
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 toplevel 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.0"
15
-
16
- # Ruports logging and error interface.
17
- # Can generate warnings or raise fatal errors
18
- #
19
- # Takes a message to display and a set of options.
20
- # Will log to the file defined by Config::log_file
21
- #
22
- # Options:
23
- # <tt>:status</tt>:: sets the severity level. defaults to <tt>:warn</tt>
24
- # <tt>:output</tt>:: optional 2nd output, defaults to <tt>$stderr</tt>
25
- # <tt>:level</tt>:: set to <tt>:log_only</tt> to disable secondary output
26
- # <tt>:exception</tt>:: exception to throw on fail. Defaults to RunTimeError
27
- #
28
- # The status <tt>:warn</tt> will invoke Logger#warn. A status of
29
- # <tt>:fatal</tt> will invoke Logger#fatal and raise an exception
30
- #
31
- # By default, <tt>log()</tt> will also print warnings to $stderr
32
- # You can redirect this to any I/O object via <tt>:output</tt>
33
- #
34
- # You can prevent messages from appearing on the secondary output by setting
35
- # <tt>:level</tt> to <tt>:log_only</tt>
36
- #
37
- # If you want to recover these messages to secondary output for debugging, you
38
- # can use Config::enable_paranoia
39
- def self.log(message,options={})
40
- options = {:status => :warn, :output => $stderr}.merge(options)
41
- options[:output].puts "[!!] #{message}" unless
42
- options[:level].eql?(:log_only) and not Ruport::Config.paranoid?
43
- Ruport::Config::logger.send(options[:status],message) if Config.logger
44
- if options[:status].eql? :fatal
45
- raise(options[:exception] || RuntimeError, message)
46
- end
47
- end
48
-
49
- #Alias for Ruport.log
50
- def self.complain(*args); Ruport.log(*args) end
51
-
52
- # yields a Ruport::Config object, allowing you to specify configuration
53
- # options.
54
- #
55
- # Example:
56
- #
57
- # Ruport.configure do |c|
58
- # c.source :default, :dsn => "dbi:mysql:foo",
59
- # :user => "clyde", :password => "pman"
60
- # end
61
- def self.configure(&block)
62
- block.call(Ruport::Config)
63
- end
64
- end
65
-
66
-
67
- %w[attempt config data meta_tools report format query mailer].each { |lib|
68
- require "ruport/#{lib}"
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"
@@ -1,6 +1,6 @@
1
1
  require 'timeout'
2
2
 
3
- class Attempt
3
+ class Attempt # :nodoc:
4
4
  VERSION = '0.1.0'
5
5
 
6
6
  # Number of attempts to make before failing. The default is 3.
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
- # This class serves as the configuration system for Ruport.
15
- # It's functionality is implemented through Config::method_missing
16
- #
17
- # source :default and mailer :default will become the fallback values if one
18
- # is not specified in Report::Mailer or Query, but you may define as many
19
- # sources as you like and switch between them later.
20
- #
21
- # An example config file is shown below:
22
- #
23
- # # password is optional, dsn may omit hostname for localhost
24
- # Ruport::Config.source :default,
25
- # :dsn => "dbi:mysql:somedb:db.blixy.org",
26
- # :user => "root", :password => "chunky_bacon"
27
- #
28
- # # :password, :port, and :auth_type are optional. :port defaults to 25 and
29
- # # :auth_type defaults to :plain. For more information, see the source
30
- # # of Report::Mailer#select_mailer
31
- # Ruport::Config.mailer :default,
32
- # :host => "mail.chunkybacon.org", :address => "chunky@bacon.net",
33
- # :user => "cartoon", :password => "fox", :port => 25, :auth_type => :login
34
- #
35
- # # optional, if specifed, Ruport#complain will report to it
36
- # Ruport::Config.log_file 'foo.log'
37
- #
38
- # # optional, if enabled, will force :log_only complaint calls to
39
- # # print to secondary output ($sterr by default).
40
- # # call Ruport::Config.disable_paranoia to disable
41
- # Ruport::Config.enable_paranoia
42
- #
43
- # Alternatively, this configuration could be done by opening the class:
44
- # class Ruport::Config
45
- #
46
- # source :default, :dsn => "dbi:mysql:some_db", :user => "root"
47
- #
48
- # mailer :default, :host => "mail.iheartwhy.com",
49
- # :address => "sandal@ruby-harmonix.net", :user => "sandal",
50
- # :password => "abc123"
51
- #
52
- # logfile 'foo.log'
53
- #
54
- # end
55
- #
56
- # Saving this config information into a file and then requiring it can allow
57
- # you share configurations between Ruport applications.
58
- #
59
- module Config
60
- module_function
61
-
62
-
63
- # create or retrieve a database source configuration.
64
- #
65
- # setting a source
66
- #
67
- # source :default, :user => "root", :password => "clyde",
68
- # :dsn => "dbi:mysql:blinkybase"
69
- #
70
- # retrieving a source
71
- #
72
- # db = source(:default) #=> <OpenStruct ..>
73
- # db.dsn #=> "dbi:mysql:blinkybase"
74
- def source(*args)
75
- return sources[args.first] if args.length == 1
76
- sources[args.first] = OpenStruct.new(*args[1..-1])
77
- check_source(sources[args.first],args.first)
78
- end
79
-
80
- # create or retrieve a mailer configuration
81
- #
82
- # creating a mailer config
83
- #
84
- # mailer :alternate, :host => "mail.test.com",
85
- # :address => "test@test.com",
86
- # :user => "test", :password => "blinky"
87
- # :auth_type => :cram_md5
88
- #
89
- # retreiving a mailer config
90
- #
91
- # mail_conf = mailer(:alternate) #=> <OpenStruct ..>
92
- # mail_conf.address #=> test@test.com
93
- def mailer(*args)
94
- return mailers[args.first] if args.length == 1
95
- mailers[args.first] = OpenStruct.new(*args[1..-1])
96
- check_mailer(mailers[args.first],args.first)
97
- end
98
-
99
-
100
- # Sets the logger to use the specified file.
101
- #
102
- # log_file "foo.log"
103
- def log_file(file)
104
- @logger = Logger.new(file)
105
- end
106
-
107
- # Same as Config.log_file, but accessor style
108
- def log_file=(file)
109
- log_file(file)
110
- end
111
-
112
- # Returns the source which is labeled :default
113
- def default_source
114
- sources[:default]
115
- end
116
-
117
- # Returns the mailer which is labeled :default
118
- def default_mailer
119
- mailers[:default]
120
- end
121
-
122
- # Returns an array of database source configs
123
- def sources; @sources ||= {}; end
124
-
125
- # Returns an array of mailer configs
126
- def mailers; @mailers ||= {}; end
127
-
128
- # Returns the currently active logger
129
- def logger; @logger; end
130
-
131
- # Forces all messages marked :log_only to surface
132
- def enable_paranoia; @paranoid = true; end
133
-
134
- # Disables the printing of :log_only messages to STDERR
135
- def disable_paranoia; @paranoid = false; end
136
-
137
- # Sets paranoid status
138
- def paranoid=(val); @paranoid = val; end
139
-
140
- # Checks to see if paranoia is enabled
141
- def paranoid?; !!@paranoid; end
142
-
143
- # Verifies that you have provided a DSN for your source
144
- def check_source(settings,label)
145
- unless settings.dsn
146
- Ruport.complain(
147
- "Missing DSN for source #{label}!",
148
- :status => :fatal, :level => :log_only,
149
- :exception => ArgumentError
150
- )
151
- end
152
- end
153
-
154
- # Verifies that you have provided a host for your mailer
155
- def check_mailer(settings, label)
156
- unless settings.host
157
- Ruport.complain(
158
- "Missing host for mailer #{label}",
159
- :status => :fatal, :level => :log_only,
160
- :exception => ArgumentError
161
- )
162
- end
163
- end
164
-
165
- end
166
- end
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