spira 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.md CHANGED
@@ -1,4 +1,11 @@
1
1
  # Changelog for Spira <http://github.com/datagraph/spira>
2
+
3
+ ## 0.0.11
4
+ * Bumped the version dependency on rdf-isomorphic to 0.3.0
5
+ * Added support for before_create, after_create, before_save, after_save,
6
+ after_update, before_destroy and after_destroy hooks.
7
+ * Switch RDF.rb dependency to >= instead of ~>
8
+
2
9
  ## 0.0.10
3
10
  * Use RDF::URI.intern on URIs generated via base URIs
4
11
  * Added a Spira::Types::Native, which will return the RDF::Value for a given
data/README CHANGED
@@ -359,6 +359,36 @@ built in `assert` and assert helpers such as `assert_set` and
359
359
  dancing_queen.artist = abba
360
360
  dancing_queen.save! #=> true
361
361
 
362
+ ## Hooks
363
+
364
+ Spira supports `before_create`, `after_create`, `after_update`, `before_save`,
365
+ `after_save`, and `before_destroy` hooks:
366
+
367
+ class CD
368
+ def before_save
369
+ self.publisher = 'No publisher set' if self.publisher.nil?
370
+ end
371
+ end
372
+
373
+ The `after_update` hook only fires on the `update` method, not simple property
374
+ accessors (to allow you to easily set properties in these without going into a
375
+ recursive loop):
376
+
377
+ class CD
378
+ def after_update
379
+ self.artist = 'Queen' # every artist should be Queen!
380
+ end
381
+ end
382
+
383
+ # ...snip ...
384
+ dancing_queen.artist
385
+ #=> "ABBA"
386
+ dancing_queen.name = "Dancing Queen"
387
+ dancing_queen.artist
388
+ #=> "ABBA"
389
+ dancing_queen.update(:name => "Dancing Queen")
390
+ dancing_queen.artist
391
+ #=> "Queen"
362
392
 
363
393
  ## Inheritance
364
394
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.10
1
+ 0.0.11
@@ -1,5 +1,3 @@
1
- require 'promise'
2
-
3
1
  module Spira
4
2
  module Resource
5
3
 
@@ -139,7 +139,8 @@ module Spira
139
139
  # @object.destroy!(:completely)
140
140
  # @return [true, false] Whether or not the destroy was successful
141
141
  def destroy!(what = nil)
142
- case what
142
+ before_destroy if self.respond_to?(:before_destroy)
143
+ result = case what
143
144
  when nil
144
145
  _destroy_attributes(attributes, :destroy_type => true) != nil
145
146
  when :subject
@@ -149,6 +150,8 @@ module Spira
149
150
  when :completely
150
151
  destroy!(:subject) && destroy!(:object)
151
152
  end
153
+ after_destroy if self.respond_to?(:after_destroy) if result
154
+ result
152
155
  end
153
156
 
154
157
  ##
@@ -156,6 +159,9 @@ module Spira
156
159
  #
157
160
  # @return [self] self
158
161
  def save!
162
+ existed = (self.respond_to?(:before_create) || self.respond_to?(:after_create)) && !self.type.nil? && exists?
163
+ before_create if self.respond_to?(:before_create) && !self.type.nil? && !existed
164
+ before_save if self.respond_to?(:before_save)
159
165
  unless self.class.validators.empty?
160
166
  errors.clear
161
167
  self.class.validators.each do | validator | self.send(validator) end
@@ -167,6 +173,8 @@ module Spira
167
173
  else
168
174
  _update!
169
175
  end
176
+ after_create if self.respond_to?(:after_create) && !self.type.nil? && !existed
177
+ after_save if self.respond_to?(:after_save)
170
178
  self
171
179
  end
172
180
 
@@ -188,6 +196,7 @@ module Spira
188
196
  properties.each do |property, value|
189
197
  attribute_set(property, value)
190
198
  end
199
+ after_update if self.respond_to?(:after_update)
191
200
  self
192
201
  end
193
202
 
data/lib/spira/version.rb CHANGED
@@ -2,7 +2,7 @@ module Spira
2
2
  module VERSION
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- TINY = 10
5
+ TINY = 11
6
6
  EXTRA = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY].join('.')
data/lib/spira.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'rdf'
2
+ require 'promise'
2
3
  require 'spira/exceptions'
3
4
 
4
5
  ##
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 10
9
- version: 0.0.10
8
+ - 11
9
+ version: 0.0.11
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ben Lavender
@@ -15,7 +15,7 @@ bindir:
15
15
  - bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-26 00:00:00 -05:00
18
+ date: 2010-11-03 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -23,7 +23,7 @@ dependencies:
23
23
  prerelease: false
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
25
  requirements:
26
- - - ~>
26
+ - - ">="
27
27
  - !ruby/object:Gem::Version
28
28
  segments:
29
29
  - 0
@@ -65,7 +65,7 @@ dependencies:
65
65
  prerelease: false
66
66
  requirement: &id004 !ruby/object:Gem::Requirement
67
67
  requirements:
68
- - - ~>
68
+ - - ">="
69
69
  - !ruby/object:Gem::Version
70
70
  segments:
71
71
  - 0
@@ -83,9 +83,9 @@ dependencies:
83
83
  - !ruby/object:Gem::Version
84
84
  segments:
85
85
  - 0
86
- - 2
86
+ - 3
87
87
  - 0
88
- version: 0.2.0
88
+ version: 0.3.0
89
89
  type: :runtime
90
90
  version_requirements: *id005
91
91
  - !ruby/object:Gem::Dependency