active_nomad 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ == 0.2.2 2010-10-07
2
+
3
+ * Support custom destruction strategies.
4
+ * #save noops if no persistence strategy defined.
5
+
1
6
  == 0.2.1 2010-10-06
2
7
 
3
8
  * from_json noops on invalid JSON strings.
@@ -1,5 +1,5 @@
1
1
  module ActiveNomad
2
- VERSION = [0, 2, 1]
2
+ VERSION = [0, 2, 2]
3
3
 
4
4
  class << VERSION
5
5
  include Comparable
data/lib/active_nomad.rb CHANGED
@@ -2,8 +2,6 @@ require 'active_record'
2
2
  require 'cgi'
3
3
 
4
4
  module ActiveNomad
5
- NoPersistenceStrategy = Class.new(RuntimeError)
6
-
7
5
  class Base < ActiveRecord::Base
8
6
  #
9
7
  # Tell this record how to save itself.
@@ -97,30 +95,33 @@ module ActiveNomad
97
95
  from_serialized_attributes(serialized_attributes)
98
96
  end
99
97
 
100
- protected
101
-
102
98
  #
103
- # Persist the object.
99
+ # Destroy the object.
104
100
  #
105
101
  # The default is to call the block registered with
106
- # #to_save. Override if you don't want to use #to_save.
102
+ # #to_destroy. Override if you don't want to use #to_destroy.
107
103
  #
108
- def persist
109
- @save_proc or
110
- raise NoPersistenceStrategy, "no persistence strategy - use #to_save to define one"
111
- @save_proc.call(self)
104
+ def destroy
105
+ if @destroy_proc
106
+ @destroy_proc.call(self)
107
+ end
108
+ self
112
109
  end
113
110
 
111
+ protected
112
+
114
113
  #
115
- # Destroy the object.
114
+ # Persist the object.
116
115
  #
117
116
  # The default is to call the block registered with
118
- # #to_destroy. Override if you don't want to use #to_destroy.
117
+ # #to_save. Override if you don't want to use #to_save.
119
118
  #
120
- def destroy
121
- @destroy_proc or
122
- raise NoDestructionStrategy, "no destruction strategy - use #to_destroy to define one"
123
- @destroy_proc.call(self)
119
+ def persist
120
+ if @save_proc
121
+ @save_proc.call(self)
122
+ else
123
+ true
124
+ end
124
125
  end
125
126
 
126
127
  private
@@ -84,9 +84,9 @@ describe ActiveNomad::Base do
84
84
 
85
85
  describe "#save" do
86
86
  describe "when no save strategy has been defined" do
87
- it "should raise a NoPersistenceStrategy error" do
87
+ it "should return true" do
88
88
  instance = ActiveNomad::Base.new
89
- lambda{instance.save}.should raise_error(ActiveNomad::NoPersistenceStrategy)
89
+ instance.save.should be_true
90
90
  end
91
91
  end
92
92
 
@@ -123,6 +123,30 @@ describe ActiveNomad::Base do
123
123
  end
124
124
  end
125
125
 
126
+ describe "#destroy" do
127
+ describe "no destruction strategy has been defined" do
128
+ it "should return the object" do
129
+ instance = ActiveNomad::Base.new
130
+ instance.destroy.should equal(instance)
131
+ end
132
+
133
+ describe "when a destruction strategy has been defined" do
134
+ before do
135
+ destroys = @destroys = []
136
+ @instance = ActiveNomad::Base.new
137
+ @instance.to_destroy do |*args|
138
+ destroys << args
139
+ end
140
+ end
141
+
142
+ it "should call the destroy_proc with the record as an argument" do
143
+ @instance.destroy
144
+ @destroys.should == [[@instance]]
145
+ end
146
+ end
147
+ end
148
+ end
149
+
126
150
  describe "#to_serialized_attributes" do
127
151
  it "should return a list of attribute names with serialized attributes, sorted by name" do
128
152
  klass = Class.new(ActiveNomad::Base) do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_nomad
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 1
10
- version: 0.2.1
9
+ - 2
10
+ version: 0.2.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - George Ogata
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-06 00:00:00 -04:00
18
+ date: 2010-10-07 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency