ruport 0.8.13 → 0.8.14
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/ruport/data/record.rb +2 -0
- data/lib/ruport/data/table.rb +14 -8
- data/lib/ruport.rb +3 -3
- data/test/test_record.rb +24 -0
- data/test/test_table.rb +10 -0
- metadata +2 -2
data/Rakefile
CHANGED
data/lib/ruport/data/record.rb
CHANGED
@@ -87,6 +87,7 @@ module Ruport::Data
|
|
87
87
|
@data[@attributes[index]] = value
|
88
88
|
else
|
89
89
|
@data[index] = value
|
90
|
+
@attributes << index unless @attributes.include? index
|
90
91
|
end
|
91
92
|
end
|
92
93
|
|
@@ -251,6 +252,7 @@ module Ruport::Data
|
|
251
252
|
|
252
253
|
def delete(key)
|
253
254
|
@data.delete(key)
|
255
|
+
@attributes.delete(key)
|
254
256
|
end
|
255
257
|
|
256
258
|
|
data/lib/ruport/data/table.rb
CHANGED
@@ -193,7 +193,9 @@ module Ruport::Data
|
|
193
193
|
#
|
194
194
|
def +(other)
|
195
195
|
raise ArgumentError unless other.column_names == @column_names
|
196
|
-
|
196
|
+
self.class.new( :column_names => @column_names,
|
197
|
+
:data => @data + other.data,
|
198
|
+
:record_class => record_class )
|
197
199
|
end
|
198
200
|
|
199
201
|
|
@@ -390,7 +392,8 @@ module Ruport::Data
|
|
390
392
|
#
|
391
393
|
# FIXME: loses tags
|
392
394
|
def sub_table(columns=column_names,range=nil)
|
393
|
-
t =
|
395
|
+
t = self.class.new(:column_names => columns,
|
396
|
+
:record_class => record_class)
|
394
397
|
if range
|
395
398
|
data[range].each { |r| t << r }
|
396
399
|
elsif block_given?
|
@@ -480,7 +483,9 @@ module Ruport::Data
|
|
480
483
|
sort_by(&block)
|
481
484
|
end
|
482
485
|
|
483
|
-
table =
|
486
|
+
table = self.class.new( :data => data_array,
|
487
|
+
:column_names => @column_names,
|
488
|
+
:record_class => record_class )
|
484
489
|
|
485
490
|
table.tags = self.tags
|
486
491
|
return table
|
@@ -505,10 +510,15 @@ module Ruport::Data
|
|
505
510
|
# two = one.dup
|
506
511
|
#
|
507
512
|
def dup
|
508
|
-
a = self.class.new(:data => @data,
|
513
|
+
a = self.class.new( :data => @data,
|
514
|
+
:column_names => @column_names,
|
515
|
+
:record_class => record_class )
|
509
516
|
a.tags = tags.dup
|
510
517
|
return a
|
511
518
|
end
|
519
|
+
|
520
|
+
# NOTE: does not respect tainted status
|
521
|
+
alias_method :clone, :dup
|
512
522
|
|
513
523
|
#
|
514
524
|
# Uses Ruport's built-in text plugin to render this Table into a String
|
@@ -522,10 +532,6 @@ module Ruport::Data
|
|
522
532
|
def to_s
|
523
533
|
as(:text)
|
524
534
|
end
|
525
|
-
|
526
|
-
# NOTE: does not respect tainted status
|
527
|
-
alias_method :clone, :dup
|
528
|
-
|
529
535
|
|
530
536
|
# Provides a shortcut for the <tt>as()</tt> method by converting a call to
|
531
537
|
# <tt>as(:format_name)</tt> into a call to <tt>to_format_name</tt>
|
data/lib/ruport.rb
CHANGED
@@ -12,7 +12,7 @@
|
|
12
12
|
|
13
13
|
module Ruport
|
14
14
|
|
15
|
-
VERSION = "0.8.
|
15
|
+
VERSION = "0.8.14"
|
16
16
|
|
17
17
|
# This method is Ruport's logging and error interface. It can generate
|
18
18
|
# warnings or raise fatal errors, logging +message+ to the file defined by
|
@@ -37,8 +37,8 @@ module Ruport
|
|
37
37
|
# <tt>log()</tt> (which can be useful for
|
38
38
|
# debugging), you can set
|
39
39
|
# <tt>Config.debug_mode</tt>.
|
40
|
-
# <b><tt>:
|
41
|
-
# defaults to +
|
40
|
+
# <b><tt>:raises</tt></b>:: The +Exception+ to throw on failure. This
|
41
|
+
# defaults to +RuntimeError+.
|
42
42
|
#
|
43
43
|
def self.log(message, options={})
|
44
44
|
options = {:status => :warn, :output => $stderr}.merge(options)
|
data/test/test_record.rb
CHANGED
@@ -257,5 +257,29 @@ class TestRecord < Test::Unit::TestCase
|
|
257
257
|
assert_equal 2, a.get(1)
|
258
258
|
assert_equal 1, a.get(0)
|
259
259
|
end
|
260
|
+
|
261
|
+
def test_ensure_delete_removes_attribute
|
262
|
+
a = Record.new({"a" => 1, "b" => 2})
|
263
|
+
assert_equal({"a" => 1, "b" => 2}, a.data)
|
264
|
+
assert_equal(["a","b"], a.attributes)
|
265
|
+
|
266
|
+
a.send(:delete, "a")
|
267
|
+
assert_equal({"b" => 2}, a.data)
|
268
|
+
assert_equal(["b"], a.attributes)
|
269
|
+
end
|
270
|
+
|
271
|
+
def test_ensure_bracket_equals_updates_attributes
|
272
|
+
a = Record.new({"a" => 1, "b" => 2})
|
273
|
+
assert_equal({"a" => 1, "b" => 2}, a.data)
|
274
|
+
assert_equal(["a","b"], a.attributes)
|
275
|
+
|
276
|
+
a["b"] = 3
|
277
|
+
assert_equal({"a" => 1, "b" => 3}, a.data)
|
278
|
+
assert_equal(["a","b"], a.attributes)
|
279
|
+
|
280
|
+
a["c"] = 4
|
281
|
+
assert_equal({"a" => 1, "b" => 3, "c" => 4}, a.data)
|
282
|
+
assert_equal(["a","b","c"], a.attributes)
|
283
|
+
end
|
260
284
|
|
261
285
|
end
|
data/test/test_table.rb
CHANGED
@@ -496,8 +496,18 @@ class TestTable < Test::Unit::TestCase
|
|
496
496
|
assert_equal [[1,3,3],[4,6,6]].to_table(%w[a foo c]), a
|
497
497
|
end
|
498
498
|
|
499
|
+
def test_ensure_propagate_record_class
|
500
|
+
a = Ruport::Data::Table.new(:record_class => DuckRecord)
|
501
|
+
assert_equal DuckRecord, a.record_class
|
502
|
+
|
503
|
+
b = a.dup
|
504
|
+
assert_equal DuckRecord, b.record_class
|
505
|
+
end
|
506
|
+
|
499
507
|
end
|
500
508
|
|
509
|
+
class DuckRecord < Ruport::Data::Record; end
|
510
|
+
|
501
511
|
class TestTableKernelHack < Test::Unit::TestCase
|
502
512
|
|
503
513
|
def test_simple
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
|
|
3
3
|
specification_version: 1
|
4
4
|
name: ruport
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.8.
|
7
|
-
date: 2007-04-
|
6
|
+
version: 0.8.14
|
7
|
+
date: 2007-04-16 00:00:00 -04:00
|
8
8
|
summary: A generalized Ruby report generation and templating engine.
|
9
9
|
require_paths:
|
10
10
|
- lib
|