palsy 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,6 +1,9 @@
1
- * 0.0.2 - February 23, 2003
1
+ * 0.0.3 - April 2, 2013
2
+ * Ensure exclusive transactions are being used for all operations. This
3
+ should make it a little more viable for non-MRI things.
4
+ * 0.0.2 - February 23, 2013
2
5
  * if Palsy::List is put into a situation where it will try to replace itself
3
6
  with an empty array, it would generate a SQL syntax error.
4
7
  * Fixes for unit testing / build environment
5
- * 0.0.1 - February 10, 2003
8
+ * 0.0.1 - February 10, 2013
6
9
  * Initial Release
data/Gemfile CHANGED
@@ -2,5 +2,3 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in palsy.gemspec
4
4
  gemspec
5
-
6
- gem 'guard-rake', :git => "https://github.com/erikh/guard-rake", :branch => "failure_ok"
data/Guardfile CHANGED
@@ -5,6 +5,6 @@ guard 'minitest' do
5
5
  watch(%r|^test/helper\.rb|) { "test" }
6
6
  end
7
7
 
8
- guard 'rake', :failure_ok => true, :run_on_all => false, :task => 'rdoc_cov' do
8
+ guard 'rake', :run_on_all => false, :task => 'rdoc_cov' do
9
9
  watch(%r|^lib/(.*)([^/]+)\.rb|)
10
10
  end
data/Rakefile CHANGED
@@ -10,7 +10,8 @@ end
10
10
 
11
11
  RDoc::Task.new do |rdoc|
12
12
  rdoc.title = "Palsy: a simple sqlite layer for persisting data structures"
13
- rdoc.rdoc_files.include("lib/**/*.rb")
13
+ rdoc.main = "README.md"
14
+ rdoc.rdoc_files.include("README.md", "lib/**/*.rb")
14
15
  rdoc.rdoc_files -= ["lib/palsy/version.rb"]
15
16
  if ENV["RDOC_COVER"]
16
17
  rdoc.options << "-C"
data/lib/palsy.rb CHANGED
@@ -87,6 +87,19 @@ class Palsy < DelegateClass(SQLite3::Database)
87
87
  SQLite3::Database.new(self.class.database)
88
88
  end
89
89
  end
90
+
91
+ #
92
+ # Execute this query in an exclusive transaction.
93
+ #
94
+ def execute_t(query, args=[], &block)
95
+ result = nil
96
+
97
+ transaction(:exclusive) do
98
+ result = execute(query, args, &block)
99
+ end
100
+
101
+ return result
102
+ end
90
103
  end
91
104
 
92
105
  require 'palsy/basic'
@@ -12,7 +12,7 @@ class Palsy
12
12
  #
13
13
  # class Palsy::Object < Palsy::Generic
14
14
  # def create_table
15
- # @db.execute %Q[
15
+ # @db.execute_t %Q[
16
16
  # create table if not exists #{@table_name} (
17
17
  # id integer not null primary key autoincrement,
18
18
  # key varchar(255) not null,
@@ -37,7 +37,7 @@ class Palsy
37
37
  # Add a value to the tail of the list.
38
38
  #
39
39
  def push(val)
40
- @db.execute(
40
+ @db.execute_t(
41
41
  "insert into #{@table_name} (name, value) values (?, ?)",
42
42
  [@object_name, Marshal.dump(val)]
43
43
  )
@@ -86,7 +86,7 @@ class Palsy
86
86
 
87
87
  value_string = ("(?, ?)," * ary.count).chop
88
88
 
89
- @db.execute(
89
+ @db.execute_t(
90
90
  "insert into #{@table_name} (name, value) values #{value_string}",
91
91
  ary.map { |x| [@object_name, Marshal.dump(x)] }.flatten
92
92
  )
@@ -96,7 +96,7 @@ class Palsy
96
96
  # Empty the list.
97
97
  #
98
98
  def clear
99
- @db.execute("delete from #{@table_name} where name=?", [@object_name])
99
+ @db.execute_t("delete from #{@table_name} where name=?", [@object_name])
100
100
  end
101
101
 
102
102
  #
@@ -111,7 +111,7 @@ class Palsy
111
111
  # Convert the list to a Ruby Array.
112
112
  #
113
113
  def to_a
114
- @db.execute(
114
+ @db.execute_t(
115
115
  "select value from #{@table_name} where name=? order by id",
116
116
  [@object_name]
117
117
  ).map { |x| Marshal.load(x.first) }
@@ -121,7 +121,7 @@ class Palsy
121
121
  # Define the schema for this type.
122
122
  #
123
123
  def create_table
124
- @db.execute <<-EOF
124
+ @db.execute_t <<-EOF
125
125
  create table if not exists #{@table_name} (
126
126
  id integer not null primary key autoincrement,
127
127
  name varchar(255) not null,
@@ -129,7 +129,7 @@ class Palsy
129
129
  )
130
130
  EOF
131
131
 
132
- @db.execute "create index if not exists #{@table_name}_name_index on #{@table_name} (name)"
132
+ @db.execute_t "create index if not exists #{@table_name}_name_index on #{@table_name} (name)"
133
133
  end
134
134
  end
135
135
  end
@@ -40,7 +40,7 @@ class Palsy
40
40
  # entry.
41
41
  #
42
42
  def [](key)
43
- value = @db.execute("select value from #{@table_name} where name=? and key=?", [@object_name, Marshal.dump(key)]).first.first rescue nil
43
+ value = @db.execute_t("select value from #{@table_name} where name=? and key=?", [@object_name, Marshal.dump(key)]).first.first rescue nil
44
44
  return value && Marshal.load(value)
45
45
  end
46
46
 
@@ -50,7 +50,7 @@ class Palsy
50
50
  #
51
51
  def []=(key, value)
52
52
  delete(key)
53
- @db.execute("insert into #{@table_name} (name, key, value) values (?, ?, ?)", [@object_name, Marshal.dump(key), Marshal.dump(value)])
53
+ @db.execute_t("insert into #{@table_name} (name, key, value) values (?, ?, ?)", [@object_name, Marshal.dump(key), Marshal.dump(value)])
54
54
  value
55
55
  end
56
56
 
@@ -68,7 +68,7 @@ class Palsy
68
68
  # Convert this map to a Ruby Hash object.
69
69
  #
70
70
  def to_hash
71
- rows = @db.execute("select key, value from #{@table_name} where name=?", [@object_name])
71
+ rows = @db.execute_t("select key, value from #{@table_name} where name=?", [@object_name])
72
72
  Hash[rows.map { |x| x.map { |y| Marshal.load(y) } }]
73
73
  end
74
74
 
@@ -76,7 +76,7 @@ class Palsy
76
76
  # Defines the schema for Maps.
77
77
  #
78
78
  def create_table
79
- @db.execute <<-EOF
79
+ @db.execute_t <<-EOF
80
80
  create table if not exists #{@table_name} (
81
81
  id integer not null primary key autoincrement,
82
82
  name varchar(255) not null,
@@ -86,7 +86,7 @@ class Palsy
86
86
  )
87
87
  EOF
88
88
 
89
- @db.execute "create index if not exists #{@table_name}_name_idx on #{@table_name} (name)"
89
+ @db.execute_t "create index if not exists #{@table_name}_name_idx on #{@table_name} (name)"
90
90
  end
91
91
  end
92
92
  end
@@ -27,7 +27,7 @@ class Palsy
27
27
  # Get an object by referencing its key. Returns nil unless it exists.
28
28
  #
29
29
  def [](key)
30
- value = @db.execute("select value from #{@table_name} where key=?", [key]).first.first rescue nil
30
+ value = @db.execute_t("select value from #{@table_name} where key=?", [key]).first.first rescue nil
31
31
  return value && Marshal.load(value)
32
32
  end
33
33
 
@@ -36,7 +36,7 @@ class Palsy
36
36
  #
37
37
  def []=(key, value)
38
38
  delete(key)
39
- @db.execute("insert into #{@table_name} (key, value) values (?, ?)", [key, Marshal.dump(value)])
39
+ @db.execute_t("insert into #{@table_name} (key, value) values (?, ?)", [key, Marshal.dump(value)])
40
40
  value
41
41
  end
42
42
 
@@ -44,14 +44,14 @@ class Palsy
44
44
  # Deletes an object.
45
45
  #
46
46
  def delete(key)
47
- @db.execute("delete from #{@table_name} where key=?", [key])
47
+ @db.execute_t("delete from #{@table_name} where key=?", [key])
48
48
  end
49
49
 
50
50
  #
51
51
  # Defines the schema for this data type.
52
52
  #
53
53
  def create_table
54
- @db.execute <<-EOF
54
+ @db.execute_t <<-EOF
55
55
  create table if not exists #{@table_name} (
56
56
  id integer not null primary key autoincrement,
57
57
  key varchar(255) not null,
@@ -42,21 +42,21 @@ class Palsy
42
42
  #
43
43
  def add(key)
44
44
  delete(key)
45
- @db.execute("insert into #{@table_name} (name, key) values (?, ?)", [@object_name, Marshal.dump(key)])
45
+ @db.execute_t("insert into #{@table_name} (name, key) values (?, ?)", [@object_name, Marshal.dump(key)])
46
46
  end
47
47
 
48
48
  #
49
49
  # Remove a value from the Set.
50
50
  #
51
51
  def delete(key)
52
- @db.execute("delete from #{@table_name} where name=? and key=?", [@object_name, Marshal.dump(key)])
52
+ @db.execute_t("delete from #{@table_name} where name=? and key=?", [@object_name, Marshal.dump(key)])
53
53
  end
54
54
 
55
55
  #
56
56
  # Predicate to determine if a value is in this set.
57
57
  #
58
58
  def has_key?(key)
59
- @db.execute("select count(*) from #{@table_name} where name=? and key=?", [@object_name, Marshal.dump(key)]).first.first.to_i > 0
59
+ @db.execute_t("select count(*) from #{@table_name} where name=? and key=?", [@object_name, Marshal.dump(key)]).first.first.to_i > 0
60
60
  end
61
61
 
62
62
  alias include? has_key?
@@ -65,7 +65,7 @@ class Palsy
65
65
  # Remove all values from the set.
66
66
  #
67
67
  def clear
68
- @db.execute("delete from #{@table_name} where name=?", [@object_name])
68
+ @db.execute_t("delete from #{@table_name} where name=?", [@object_name])
69
69
  end
70
70
 
71
71
  #
@@ -79,14 +79,14 @@ class Palsy
79
79
 
80
80
  value_string = ("(?, ?)," * set.count).chop
81
81
 
82
- @db.execute("insert into #{@table_name} (name, key) values #{value_string}", set.map { |x| [@object_name, Marshal.dump(x)] }.flatten)
82
+ @db.execute_t("insert into #{@table_name} (name, key) values #{value_string}", set.map { |x| [@object_name, Marshal.dump(x)] }.flatten)
83
83
  end
84
84
 
85
85
  #
86
86
  # Return a ruby Array of the set. Used for #to_a and #to_set by various Ruby libraries.
87
87
  #
88
88
  def keys
89
- @db.execute("select distinct key from #{@table_name} where name=?", [@object_name]).map { |x| Marshal.load(x.first) }
89
+ @db.execute_t("select distinct key from #{@table_name} where name=?", [@object_name]).map { |x| Marshal.load(x.first) }
90
90
  end
91
91
 
92
92
  #
@@ -100,7 +100,7 @@ class Palsy
100
100
  # Defines the schema for a set.
101
101
  #
102
102
  def create_table
103
- @db.execute <<-EOF
103
+ @db.execute_t <<-EOF
104
104
  create table if not exists #{@table_name} (
105
105
  id integer not null primary key autoincrement,
106
106
  name varchar(255) not null,
@@ -109,7 +109,7 @@ class Palsy
109
109
  )
110
110
  EOF
111
111
 
112
- @db.execute "create index if not exists #{@table_name}_name_idx on #{@table_name} (name)"
112
+ @db.execute_t "create index if not exists #{@table_name}_name_idx on #{@table_name} (name)"
113
113
  end
114
114
  end
115
115
  end
data/lib/palsy/version.rb CHANGED
@@ -1 +1 @@
1
- PalsyVersion = "0.0.2"
1
+ PalsyVersion = "0.0.3"
data/palsy.gemspec CHANGED
@@ -21,9 +21,9 @@ Gem::Specification.new do |gem|
21
21
 
22
22
  gem.add_development_dependency 'minitest', '~> 4.5.0'
23
23
  gem.add_development_dependency 'rake'
24
- gem.add_development_dependency 'rdoc', "~> 3.12"
24
+ gem.add_development_dependency 'rdoc', "~> 4"
25
25
  gem.add_development_dependency 'simplecov'
26
26
  gem.add_development_dependency 'guard-minitest'
27
- gem.add_development_dependency 'guard-rake'
27
+ gem.add_development_dependency 'guard-rake', '~> 0.0.8'
28
28
  gem.add_development_dependency 'rb-fsevent'
29
29
  end
data/test/test_list.rb CHANGED
@@ -6,6 +6,17 @@ class TestList < PalsyTypeTest
6
6
  @list = Palsy::List.new('test_list', 'a_list')
7
7
  end
8
8
 
9
+ def test_threaded_operation
10
+ syms = [:foo, :bar, :baz]
11
+ t = syms.map do |x|
12
+ Thread.new { @list.push(x) }
13
+ end
14
+
15
+ t.each(&:join)
16
+
17
+ assert_equal(syms.sort, @list.to_a.sort)
18
+ end
19
+
9
20
  def test_semantics
10
21
  assert_empty(@list.to_a, 'an uninitialized list with no data is empty')
11
22
  end
data/test/test_map.rb CHANGED
@@ -7,6 +7,17 @@ class TestMap < PalsyTypeTest
7
7
  @map2 = Palsy::Map.new('test_map', 'a_map')
8
8
  end
9
9
 
10
+ def test_threaded_operation
11
+ args = { :foo => 2, :bar => 3, :baz => 4 }
12
+ t = args.map do |k, v|
13
+ Thread.new { @map[k] = v }
14
+ end
15
+
16
+ t.each(&:join)
17
+
18
+ assert_equal(@map.to_hash, args)
19
+ end
20
+
10
21
  def test_inherits
11
22
  assert_includes(Palsy::Map.ancestors, Palsy::Set, 'maps are also sets')
12
23
  end
data/test/test_object.rb CHANGED
@@ -1,6 +1,21 @@
1
1
  require 'helper'
2
2
 
3
3
  class TestObject < PalsyTypeTest
4
+ def test_threaded_operation
5
+ obj = Palsy::Object.new('test_object')
6
+
7
+ args = { 'foo' => 2, 'bar' => 3, 'baz' => 4 }
8
+ t = args.map do |k, v|
9
+ Thread.new { obj[k] = v }
10
+ end
11
+
12
+ t.each(&:join)
13
+
14
+ args.each do |k,v|
15
+ assert_equal(obj[k], args[k])
16
+ end
17
+ end
18
+
4
19
  def test_index
5
20
  obj = Palsy::Object.new('test_object')
6
21
  obj2 = Palsy::Object.new('test_object')
data/test/test_set.rb CHANGED
@@ -6,6 +6,17 @@ class TestSet < PalsyTypeTest
6
6
  @set = Palsy::Set.new('test_set', 'a_set')
7
7
  end
8
8
 
9
+ def test_threaded_operation
10
+ syms = [:foo, :bar, :baz]
11
+ t = syms.map do |x|
12
+ Thread.new { @set.add(x) }
13
+ end
14
+
15
+ t.each(&:join)
16
+
17
+ assert_equal(syms.sort, @set.to_a.sort)
18
+ end
19
+
9
20
  def test_semantics
10
21
  assert_empty(@set.to_set, 'an uninitialized set is empty')
11
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: palsy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-23 00:00:00.000000000 Z
12
+ date: 2013-04-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sqlite3
@@ -66,7 +66,7 @@ dependencies:
66
66
  requirements:
67
67
  - - ~>
68
68
  - !ruby/object:Gem::Version
69
- version: '3.12'
69
+ version: '4'
70
70
  type: :development
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
@@ -74,7 +74,7 @@ dependencies:
74
74
  requirements:
75
75
  - - ~>
76
76
  - !ruby/object:Gem::Version
77
- version: '3.12'
77
+ version: '4'
78
78
  - !ruby/object:Gem::Dependency
79
79
  name: simplecov
80
80
  requirement: !ruby/object:Gem::Requirement
@@ -112,17 +112,17 @@ dependencies:
112
112
  requirement: !ruby/object:Gem::Requirement
113
113
  none: false
114
114
  requirements:
115
- - - ! '>='
115
+ - - ~>
116
116
  - !ruby/object:Gem::Version
117
- version: '0'
117
+ version: 0.0.8
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  none: false
122
122
  requirements:
123
- - - ! '>='
123
+ - - ~>
124
124
  - !ruby/object:Gem::Version
125
- version: '0'
125
+ version: 0.0.8
126
126
  - !ruby/object:Gem::Dependency
127
127
  name: rb-fsevent
128
128
  requirement: !ruby/object:Gem::Requirement
@@ -186,7 +186,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
186
186
  version: '0'
187
187
  segments:
188
188
  - 0
189
- hash: -599058759357210586
189
+ hash: 3156010217290385344
190
190
  required_rubygems_version: !ruby/object:Gem::Requirement
191
191
  none: false
192
192
  requirements:
@@ -195,7 +195,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
195
195
  version: '0'
196
196
  segments:
197
197
  - 0
198
- hash: -599058759357210586
198
+ hash: 3156010217290385344
199
199
  requirements: []
200
200
  rubyforge_project:
201
201
  rubygems_version: 1.8.25