ruport-util 0.2.0 → 0.3.0

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/Rakefile CHANGED
@@ -18,7 +18,7 @@ end
18
18
 
19
19
  spec = Gem::Specification.new do |spec|
20
20
  spec.name = "ruport-util"
21
- spec.version = "0.2.0"
21
+ spec.version = "0.3.0"
22
22
  spec.platform = Gem::Platform::RUBY
23
23
  spec.summary = "A set of tools and helper libs for Ruby Reports"
24
24
  spec.files = Dir.glob("{example,lib,test,bin}/**/**/*") +
data/example/mailer.rb CHANGED
@@ -3,7 +3,7 @@ require "ruport/util/mailer"
3
3
  require "fileutils"
4
4
  class MyReport < Ruport::Report
5
5
  def prepare
6
- mailer :default,
6
+ add_mailer :default,
7
7
  :host => "mail.adelphia.net",
8
8
  :address => "gregory.t.brown@gmail.com"
9
9
  end
@@ -0,0 +1,31 @@
1
+ module Ruport::Bench
2
+
3
+ require "benchmark"
4
+
5
+ def bench_case(name,n,&block)
6
+ 2.times {
7
+ @run = 0
8
+ n.times do
9
+ @bench_prepare.call if @bench_prepare
10
+ @run += Benchmark.realtime { block.call }
11
+ end
12
+ }
13
+ @bench_results << { "name" => name, "iterations" => n,
14
+ "realtime" => (time = sprintf("%.5f",@run)) }
15
+ STDERR.puts "> #{name}... ok[#{time}] "
16
+ @bench_prepare = nil
17
+ end
18
+
19
+ def bench_prepare(&block)
20
+ @bench_prepare = block
21
+ end
22
+
23
+ def bench_suite(&block)
24
+ STDERR.puts "Running Bench Suite..."
25
+ @bench_results = Table(%w[name iterations realtime])
26
+ block.call
27
+ puts @bench_results
28
+ puts "Suite run time: " << sprintf("%.5f",@bench_results.sigma("realtime"))
29
+ end
30
+
31
+ end
@@ -5,7 +5,6 @@
5
5
  #
6
6
  # This is free software. See LICENSE and COPYING for details.
7
7
  #
8
-
9
8
  begin
10
9
  require "rubygems"
11
10
  gem "ruport", ">= 0.9.3"
@@ -85,15 +85,8 @@ module Ruport
85
85
  end
86
86
 
87
87
  def build_invoice_body
88
-
89
- pdf_writer.y = 600
90
-
91
- Ruport::Renderer::Table.render_pdf { |r|
92
- r.data = data
93
- r.options.formatter = pdf_writer
94
- r.options.table_width = options.body_width || 450
95
- }
96
-
88
+ move_cursor_to 600
89
+ draw_table data, :width => options.body_width || 450
97
90
  end
98
91
 
99
92
  def build_invoice_footer
@@ -9,7 +9,6 @@ require "forwardable"
9
9
 
10
10
  module Ruport
11
11
 
12
- #
13
12
  # === Overview
14
13
  #
15
14
  # This class uses SMTP to provide a simple mail sending mechanism.
@@ -37,9 +36,10 @@ module Ruport
37
36
  # :text => "This is what you asked for"
38
37
  #
39
38
  class Mailer
39
+
40
+ class InvalidMailerConfigurationError < RuntimeError; end
40
41
  extend Forwardable
41
42
 
42
- #
43
43
  # Creates a new Mailer object. Optionally, you can select a mailer
44
44
  # specified by Ruport::Config.
45
45
  #
@@ -58,8 +58,58 @@ module Ruport
58
58
  def_delegators( :@mail, :to, :to=, :from, :from=,
59
59
  :subject, :subject=, :attach,
60
60
  :text, :text=, :html, :html= )
61
-
62
- #
61
+
62
+ class << self
63
+ # :call-seq:
64
+ # mailer(mailer_name, options)
65
+ #
66
+ # Creates or retrieves a mailer configuration. Available options:
67
+ # <b><tt>:host</tt></b>:: The SMTP host to use.
68
+ # <b><tt>:address</tt></b>:: Address the email is being sent from.
69
+ # <b><tt>:user</tt></b>:: The username to use on the SMTP server
70
+ # <b><tt>:password</tt></b>:: The password to use on the SMTP server.
71
+ # Optional.
72
+ # <b><tt>:port</tt></b>:: The SMTP port to use. Optional, defaults
73
+ # to 25.
74
+ # <b><tt>:auth_type</tt></b>:: SMTP authorization method. Optional,
75
+ # defaults to <tt>:plain</tt>.
76
+ # <b><tt>:mail_klass</tt></b>:: If you don't want to use the default
77
+ # <tt>MailFactory</tt> object, you can
78
+ # pass another mailer to use here.
79
+ #
80
+ # Example (creating a mailer config):
81
+ # mailer :alternate, :host => "mail.test.com",
82
+ # :address => "test@test.com",
83
+ # :user => "test",
84
+ # :password => "blinky"
85
+ # :auth_type => :cram_md5
86
+ #
87
+ # Example (retreiving a mailer config):
88
+ # mail_conf = mailer(:alternate) #=> <OpenStruct ..>
89
+ # mail_conf.address #=> test@test.com
90
+ #
91
+ def add_mailer(name,options)
92
+ mailers[name] = OpenStruct.new(options)
93
+ check_mailer(mailers[name],name)
94
+ end
95
+
96
+ # Alias for <tt>mailers[:default]</tt>.
97
+ def default_mailer
98
+ mailers[:default]
99
+ end
100
+
101
+ # Returns all the <tt>mailer</tt>s defined
102
+ def mailers; @mailers ||= {}; end
103
+
104
+ private
105
+
106
+ # Verifies that you have provided a host for your mailer.
107
+ def check_mailer(settings, label) # :nodoc:
108
+ raise InvalidMailerConfigurationError unless settings.host
109
+ end
110
+
111
+ end
112
+
63
113
  # Sends the message.
64
114
  #
65
115
  # Example:
@@ -78,7 +128,7 @@ module Ruport
78
128
  private
79
129
 
80
130
  def select_mailer(label)
81
- @mailer = Ruport::Config.mailers[label]
131
+ @mailer = self.class.mailers[label]
82
132
  @host = @mailer.host
83
133
  @user = @mailer.user
84
134
  @password = @mailer.password
@@ -110,70 +160,16 @@ module Ruport
110
160
  m.deliver :from => m.from, :to => m.to
111
161
  end
112
162
 
113
- # Sets the active mailer to the Ruport::Config source requested by <tt>label</tt>.
163
+ # Sets the active mailer to the Ruport::Mailer source requested by <tt>label</tt>.
114
164
  def use_mailer(label)
115
165
  @mailer = label
116
166
  end
117
167
 
118
- def_delegator Ruport::Config, :mailer
168
+ def_delegator Ruport::Mailer, :add_mailer
119
169
 
120
170
  end
121
171
 
122
- module Config
123
- module_function
124
- # Verifies that you have provided a host for your mailer.
125
- def check_mailer(settings, label) # :nodoc:
126
- unless settings.host
127
- Ruport.log(
128
- "Missing host for mailer #{label}",
129
- :status => :fatal, :level => :log_only,
130
- :raises => ArgumentError
131
- )
132
- end
133
- end
134
-
135
- # :call-seq:
136
- # mailer(mailer_name, options)
137
- #
138
- # Creates or retrieves a mailer configuration. Available options:
139
- # <b><tt>:host</tt></b>:: The SMTP host to use.
140
- # <b><tt>:address</tt></b>:: Address the email is being sent from.
141
- # <b><tt>:user</tt></b>:: The username to use on the SMTP server
142
- # <b><tt>:password</tt></b>:: The password to use on the SMTP server.
143
- # Optional.
144
- # <b><tt>:port</tt></b>:: The SMTP port to use. Optional, defaults
145
- # to 25.
146
- # <b><tt>:auth_type</tt></b>:: SMTP authorization method. Optional,
147
- # defaults to <tt>:plain</tt>.
148
- # <b><tt>:mail_klass</tt></b>:: If you don't want to use the default
149
- # <tt>MailFactory</tt> object, you can
150
- # pass another mailer to use here.
151
- #
152
- # Example (creating a mailer config):
153
- # mailer :alternate, :host => "mail.test.com",
154
- # :address => "test@test.com",
155
- # :user => "test",
156
- # :password => "blinky"
157
- # :auth_type => :cram_md5
158
- #
159
- # Example (retreiving a mailer config):
160
- # mail_conf = mailer(:alternate) #=> <OpenStruct ..>
161
- # mail_conf.address #=> test@test.com
162
- #
163
- def mailer(*args)
164
- return mailers[args.first] if args.length == 1
165
- mailers[args.first] = OpenStruct.new(*args[1..-1])
166
- check_mailer(mailers[args.first],args.first)
167
- end
168
-
169
- # Alias for <tt>mailers[:default]</tt>.
170
- def default_mailer
171
- mailers[:default]
172
- end
173
172
 
174
- # Returns all the <tt>mailer</tt>s defined in this <tt>Config</tt>.
175
- def mailers; @mailers ||= {}; end
176
- end
177
173
 
178
174
 
179
175
  end
data/lib/ruport/util.rb CHANGED
@@ -1,3 +1,5 @@
1
1
  require "ruport/util/graph"
2
2
  require "ruport/util/invoice"
3
3
  require "ruport/util/report_manager"
4
+ require "ruport/util/mailer"
5
+ require "ruport/util/bench"
data/test/test_invoice.rb CHANGED
@@ -4,7 +4,9 @@ require "ruport/util/invoice"
4
4
  class TestInvoice < Test::Unit::TestCase
5
5
 
6
6
  def test_required_options
7
- assert_raises(RuntimeError) { Ruport::Renderer::Invoice.render_pdf }
7
+ assert_raises(Ruport::Renderer::RequiredOptionNotSet) {
8
+ Ruport::Renderer::Invoice.render_pdf
9
+ }
8
10
 
9
11
  #hash form
10
12
  assert_nothing_raised {
@@ -26,4 +28,4 @@ class TestInvoice < Test::Unit::TestCase
26
28
  end
27
29
 
28
30
 
29
- end
31
+ end
data/test/test_mailer.rb CHANGED
@@ -27,8 +27,8 @@ class TestMailer < Test::Unit::TestCase
27
27
  :password => "bacon"
28
28
  }
29
29
 
30
- Ruport::Config.mailer :default, @default_opts
31
- Ruport::Config.mailer :other, @other_opts
30
+ Ruport::Mailer.add_mailer :default, @default_opts
31
+ Ruport::Mailer.add_mailer :other, @other_opts
32
32
 
33
33
  @default_mailer = Ruport::Mailer.new
34
34
  @other_mailer = Ruport::Mailer.new :other
@@ -52,8 +52,8 @@ class TestMailer < Test::Unit::TestCase
52
52
  end
53
53
 
54
54
  def test_mail_defaults
55
- assert_equal( Ruport::Config.mailers[:default],
56
- Ruport::Config.default_mailer)
55
+ assert_equal( Ruport::Mailer.mailers[:default],
56
+ Ruport::Mailer.default_mailer)
57
57
  end
58
58
 
59
59
 
@@ -67,7 +67,7 @@ class TestMailer < Test::Unit::TestCase
67
67
  end
68
68
 
69
69
  def test_constructor_without_mailer
70
- Ruport::Config.mailers[:default] = nil
70
+ Ruport::Mailer.mailers[:default] = nil
71
71
  assert_raise(RuntimeError) { Ruport::Mailer.new }
72
72
  end
73
73
 
@@ -80,10 +80,11 @@ class TestMailer < Test::Unit::TestCase
80
80
  end
81
81
 
82
82
  def test_mailer_config_errors
83
- assert_raise(ArgumentError) {
84
- Ruport::Config.mailer :bar, :user => :foo, :address => "foo@bar.com"
83
+
84
+ assert_raise(Ruport::Mailer::InvalidMailerConfigurationError) {
85
+ Ruport::Mailer.add_mailer :bar, :user => :foo, :address => "foo@bar.com"
85
86
  }
86
- assert_nothing_raised { Ruport::Config.mailer :bar, :host => "localhost" }
87
+ assert_nothing_raised { Ruport::Mailer.add_mailer :bar, :host => "localhost" }
87
88
  end
88
89
 
89
90
 
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: ruport-util
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.2.0
7
- date: 2007-04-10 00:00:00 -04:00
6
+ version: 0.3.0
7
+ date: 2007-04-22 00:00:00 -04:00
8
8
  summary: A set of tools and helper libs for Ruby Reports
9
9
  require_paths:
10
10
  - lib
@@ -29,7 +29,6 @@ post_install_message:
29
29
  authors:
30
30
  - Gregory Brown
31
31
  files:
32
- - example/mailed_report.rb
33
32
  - example/invoice_report.rb
34
33
  - example/managed_report.rb
35
34
  - example/mailer.rb
@@ -37,9 +36,10 @@ files:
37
36
  - lib/ruport
38
37
  - lib/ruport/util
39
38
  - lib/ruport/util.rb
39
+ - lib/ruport/util/mailer.rb
40
+ - lib/ruport/util/bench.rb
40
41
  - lib/ruport/util/graph.rb
41
42
  - lib/ruport/util/report_manager.rb
42
- - lib/ruport/util/mailer.rb
43
43
  - lib/ruport/util/invoice.rb
44
44
  - test/samples
45
45
  - test/init.rb
File without changes