rhubarb 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,4 +1,12 @@
1
- version 0.2.1
1
+ version 0.2.2
2
+
3
+ * explicit support for :blob-typed columns (blob values will be
4
+ appropriately stored in create statements and attribute assignments).
5
+ Note that it is still not possible to search for rows based on the
6
+ value in a blob-valued column.
7
+ * equality and hash methods (both based on class and row identity).
8
+
9
+ version 0.2.1 (97339238fbca0116b686f64343d479d15af8a03f)
2
10
 
3
11
  * Code cleanups
4
12
 
data/Rakefile CHANGED
@@ -41,13 +41,12 @@ def pkg_version
41
41
  return version.chomp
42
42
  end
43
43
 
44
- def pkg_version
45
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
- return version.chomp
44
+ def name
45
+ return 'rhubarb'
47
46
  end
48
47
 
49
48
  def pkg_name
50
- return 'ruby-rhubarb'
49
+ return "ruby-" + name()
51
50
  end
52
51
 
53
52
  def pkg_spec
@@ -71,15 +70,18 @@ def rpm_dirs
71
70
  end
72
71
 
73
72
  desc "create RPMs"
74
- task :rpms => [:build, :tarball] do
75
- require 'fileutils'
73
+ task :rpms => [:build, :tarball, :gen_spec] do
76
74
  FileUtils.cp pkg_spec(), 'SPECS'
77
75
  sh "rpmbuild --define=\"_topdir \${PWD}\" -ba SPECS/#{pkg_spec}"
78
76
  end
79
77
 
78
+ desc "Generate the specfile"
79
+ task :gen_spec do
80
+ sh "cat #{pkg_spec}" + ".in" + "| sed 's/RHUBARB_VERSION/#{pkg_version}/' > #{pkg_spec}"
81
+ end
82
+
80
83
  desc "Create a tarball"
81
- task :tarball => :make_rpmdirs do
82
- require 'fileutils'
84
+ task :tarball => [:make_rpmdirs, :gen_spec] do
83
85
  FileUtils.cp_r 'lib', pkg_dir()
84
86
  FileUtils.cp ['LICENSE', 'README.rdoc', 'CHANGES', 'TODO', 'VERSION'], pkg_dir()
85
87
  sh "tar -cf #{pkg_source} #{pkg_dir}"
@@ -87,17 +89,15 @@ task :tarball => :make_rpmdirs do
87
89
  end
88
90
 
89
91
  desc "Make dirs for building RPM"
90
- task :make_rpmdirs => :rpm_clean do
91
- require 'fileutils'
92
+ task :make_rpmdirs => :clean do
92
93
  FileUtils.mkdir pkg_dir()
93
94
  FileUtils.mkdir rpm_dirs()
94
95
  end
95
96
 
96
97
  desc "Cleanup after an RPM build"
97
- task :rpm_clean do
98
+ task :clean do
98
99
  require 'fileutils'
99
- FileUtils.rm_r pkg_dir(), :force => true
100
- FileUtils.rm_r rpm_dirs(), :force => true
100
+ FileUtils.rm_r [pkg_dir(), rpm_dirs(), pkg_spec(), 'pkg', name() + ".gemspec"], :force => true
101
101
  end
102
102
 
103
103
  require 'spec/rake/spectask'
data/TODO CHANGED
@@ -5,6 +5,10 @@
5
5
  * Documentation
6
6
  * Standalone examples (i.e. not just "please see the test suite")
7
7
  * Resolve issues related to using prepared statements
8
+ * Find rows by value of blob-valued field
9
+ * Automatic zlib compression of blobs (:zblob type)
10
+ * Automatic yaml serialization of arbitrary Ruby objects (:rubyobj type)
11
+ * Refactor column value transformations (e.g. for foreign-key rows, blobs, [future] zblob/rubyobj, etc.) to be more regular and uniform
8
12
 
9
13
  Legend:
10
14
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.2.2
@@ -128,6 +128,7 @@ module Rhubarb
128
128
  end
129
129
 
130
130
  self.colnames.merge([cname])
131
+ self.colkinds[cname] = kind
131
132
  self.columns << Column.new(cname, kind, quals)
132
133
 
133
134
  # add accessors
@@ -138,8 +139,14 @@ module Rhubarb
138
139
  end
139
140
 
140
141
  if not rf
142
+ xform = nil
143
+
144
+ if kind == :blob
145
+ xform = Util::blobify_proc
146
+ end
147
+
141
148
  define_method set_method_name do |arg|
142
- @tuple["#{cname}"] = arg
149
+ @tuple["#{cname}"] = xform ? xform.call(arg) : arg
143
150
  update cname, arg
144
151
  end
145
152
  else
@@ -202,7 +209,7 @@ module Rhubarb
202
209
 
203
210
  # resolve any references in the args
204
211
  new_row.each do |column,value|
205
- new_row[column] = Util::rhubarb_fk_identity(value)
212
+ new_row[column] = colkinds[column] == :blob ? Util::blobify(value) : Util::rhubarb_fk_identity(value)
206
213
  end
207
214
 
208
215
  stmt = "insert into #{table_name} (#{colspec}) values (#{valspec})"
@@ -246,7 +253,7 @@ module Rhubarb
246
253
  # The API purposefully does not expose the ability to create a
247
254
  # row with a given id, and created and updated values are
248
255
  # maintained automatically by the API.
249
- attr_accessor :columns, :colnames, :constraints, :dirtied, :refs, :creation_callbacks
256
+ attr_accessor :columns, :colnames, :colkinds, :constraints, :dirtied, :refs, :creation_callbacks
250
257
  end
251
258
  end
252
259
 
@@ -254,6 +261,7 @@ module Rhubarb
254
261
  self.columns ||= [Column.new(:row_id, :integer, [:primary_key]), Column.new(:created, :integer, []), Column.new(:updated, :integer, [])]
255
262
  self.colnames ||= Set.new [:created, :updated]
256
263
  self.constraints ||= []
264
+ self.colkinds ||= {}
257
265
  self.dirtied ||= {}
258
266
  self.refs ||= {}
259
267
  self.creation_callbacks ||= []
@@ -34,7 +34,17 @@ module Rhubarb
34
34
  freshen
35
35
  not @tuple
36
36
  end
37
-
37
+
38
+ def hash
39
+ freshen
40
+ @row_id ^ self.table_name.hash
41
+ end
42
+
43
+ def ==(other)
44
+ freshen
45
+ self.class == other.class && other.row_id == self.row_id
46
+ end
47
+
38
48
  # Initializes a new instance backed by a tuple of values. Do not call this directly.
39
49
  # Create new instances with the create or find methods.
40
50
  def initialize(tup)
data/lib/rhubarb/util.rb CHANGED
@@ -24,5 +24,13 @@ module Rhubarb
24
24
  def self.rhubarb_fk_identity(object)
25
25
  (object.row_id if object.class.ancestors.include? Persisting) || object
26
26
  end
27
+
28
+ def self.blobify(obj)
29
+ blobify_proc.call(obj)
30
+ end
31
+
32
+ def self.blobify_proc
33
+ @blobify_proc ||= Proc.new {|x| x.is_a?(SQLite3::Blob) ? x : SQLite3::Blob.new(x)}
34
+ end
27
35
  end
28
36
  end
@@ -1,9 +1,9 @@
1
1
  %{!?ruby_sitelib: %global ruby_sitelib %(ruby -rrbconfig -e 'puts Config::CONFIG["sitelibdir"] ')}
2
- %define rel 0.3
2
+ %define rel 0.1
3
3
 
4
4
  Summary: Simple versioned object-graph persistence layer
5
5
  Name: ruby-rhubarb
6
- Version: 0.2.0
6
+ Version: RHUBARB_VERSION
7
7
  Release: %{rel}%{?dist}
8
8
  Group: Applications/System
9
9
  License: ASL 2.0
data/test/helper.rb CHANGED
@@ -2,6 +2,8 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
3
 
4
4
  require 'rhubarb/rhubarb'
5
+ require 'test/unit'
6
+ require 'zlib'
5
7
 
6
8
  class Test::Unit::TestCase
7
9
  end
data/test/test_rhubarb.rb CHANGED
@@ -11,8 +11,7 @@
11
11
  #
12
12
  # http://www.apache.org/licenses/LICENSE-2.0
13
13
 
14
- require 'rhubarb/rhubarb'
15
- require 'test/unit'
14
+ require 'helper'
16
15
 
17
16
  class TestClass
18
17
  include Rhubarb::Persisting
@@ -88,6 +87,11 @@ class FreshTestTable
88
87
  declare_column :fum, :integer
89
88
  end
90
89
 
90
+ class BlobTestTable
91
+ include Rhubarb::Persisting
92
+ declare_column :info, :blob
93
+ end
94
+
91
95
  class BackendBasicTests < Test::Unit::TestCase
92
96
  def setup
93
97
  Rhubarb::Persistence::open(":memory:")
@@ -101,6 +105,7 @@ class BackendBasicTests < Test::Unit::TestCase
101
105
  klasses << ToRef
102
106
  klasses << FromRef
103
107
  klasses << FreshTestTable
108
+ klasses << BlobTestTable
104
109
  klasses << RhubarbNamespace::NMTC
105
110
  klasses << RhubarbNamespace::NMTC2
106
111
 
@@ -554,6 +559,26 @@ class BackendBasicTests < Test::Unit::TestCase
554
559
  end
555
560
 
556
561
  end
562
+
563
+ def test_equality
564
+ tc1 = TestClass.create(:foo=>1, :bar=>"hello")
565
+ tc2 = TestClass.create(:foo=>1, :bar=>"hello")
566
+ tc3 = TestClass.create(:foo=>2, :bar=>"goodbye")
567
+
568
+ tc1p = TestClass.find(tc1.row_id)
569
+
570
+ assert_equal(tc1, tc1) # equality is reflexive
571
+ assert_equal(tc1p, tc1) # even after find operations
572
+ assert_equal(tc1, tc1p) # ... and it should be symmetric
573
+ assert_not_equal(tc1, tc2) # these are not identical
574
+ assert_not_equal(tc1p, tc2) # even after find operations
575
+ assert_not_equal(tc2, tc1p) # ... and it should be symmetric
576
+ assert_not_same(tc1, tc2) # but these are not identical
577
+ assert_not_equal(tc1, tc3) # these aren't even equal!
578
+ assert_not_equal(tc2, tc3) # neither are these
579
+ assert_not_equal(tc3, tc1) # and inequality should hold
580
+ assert_not_equal(tc3, tc2) # under symmetry
581
+ end
557
582
 
558
583
  def freshness_query_fixture
559
584
  @flist = []
@@ -629,4 +654,25 @@ class BackendBasicTests < Test::Unit::TestCase
629
654
  end
630
655
  end
631
656
  end
657
+
658
+ def test_blob_data
659
+ words = %w{the quick brown fox jumps over a lazy dog now is time for all good men to come aid party jackdaws love my big sphinx of quartz}
660
+ text = ""
661
+ (0..300).each do
662
+ text << words[rand(words.length)] << " "
663
+ end
664
+
665
+ compressed_text = Zlib::Deflate.deflate(text)
666
+
667
+ row = BlobTestTable.create(:info => text)
668
+
669
+ crow = BlobTestTable.create(:info => compressed_text)
670
+
671
+ btrow = BlobTestTable.find(row.row_id)
672
+ cbtrow = BlobTestTable.find(crow.row_id)
673
+
674
+ assert_equal(text, btrow.info)
675
+ assert_equal(text, Zlib::Inflate.inflate(cbtrow.info))
676
+ end
677
+
632
678
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rhubarb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Benton
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-15 00:00:00 -06:00
12
+ date: 2010-02-22 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -59,7 +59,7 @@ files:
59
59
  - lib/rhubarb/reference.rb
60
60
  - lib/rhubarb/rhubarb.rb
61
61
  - lib/rhubarb/util.rb
62
- - ruby-rhubarb.spec
62
+ - ruby-rhubarb.spec.in
63
63
  - test/helper.rb
64
64
  - test/test_rhubarb.rb
65
65
  has_rdoc: true