shadydb 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
@@ -11,7 +11,7 @@ module ShadyDB
11
11
 
12
12
  field :id
13
13
 
14
- attr_accessor :attributes
14
+ attr_accessor :attributes, :raw
15
15
  end
16
16
  end
17
17
 
@@ -13,9 +13,7 @@ module ShadyDB
13
13
  return false unless self.exists?(id)
14
14
 
15
15
  document = self.new :id => id
16
- storage = File.read(document.path)
17
-
18
- document.send(:restore!, storage)
16
+ document.send(:restore!)
19
17
  document.instance_variable_set('@new_record', false)
20
18
  document
21
19
  end
@@ -7,9 +7,11 @@ module ShadyDB
7
7
 
8
8
  def self.included(base)
9
9
  base.class_eval do
10
- define_model_callbacks :save, :create, :update, :destroy
10
+ define_model_callbacks :save, :create, :update, :destroy, :persist, :restore
11
11
 
12
- before_create :ensure_data_directory_exists
12
+ before_persist :_set_raw
13
+ before_restore :_get_raw
14
+ before_create :_ensure_data_directory_exists
13
15
 
14
16
  extend ClassMethods
15
17
  end
@@ -65,7 +67,7 @@ module ShadyDB
65
67
 
66
68
  protected
67
69
 
68
- def ensure_data_directory_exists
70
+ def _ensure_data_directory_exists
69
71
  self.class.data_directory.split('/').inject do |base, dir_name|
70
72
  dir = File.join(base, dir_name)
71
73
  Dir.mkdir(dir) unless File.exist?(dir)
@@ -89,22 +91,31 @@ module ShadyDB
89
91
 
90
92
  def update
91
93
  _run_update_callbacks do
92
- File.open(path,'w') do |storage|
93
- storage << self.to_xml
94
- end
95
-
94
+ persist!
96
95
  true
97
96
  end
98
97
  end
99
98
 
100
99
  def persist!
101
- File.open(path,'w') do |storage|
102
- storage << self.send(:"to_#{ShadyDB.configuration.format}")
100
+ _run_persist_callbacks do
101
+ File.open(path,'w') do |storage|
102
+ storage << @raw
103
+ end
103
104
  end
104
105
  end
105
106
 
106
- def restore!(xml_or_json)
107
- send(:"from_#{ShadyDB.configuration.format}" ,xml_or_json)
107
+ def restore!
108
+ _run_restore_callbacks do
109
+ send(:"from_#{ShadyDB.configuration.format}" ,@raw)
110
+ end
111
+ end
112
+
113
+ def _set_raw
114
+ @raw = self.send(:"to_#{ShadyDB.configuration.format}")
115
+ end
116
+
117
+ def _get_raw
118
+ @raw = File.read(path)
108
119
  end
109
120
 
110
121
  def generate_id
data/shadydb.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{shadydb}
8
- s.version = "0.2.0"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["jdpace"]
12
- s.date = %q{2010-05-19}
12
+ s.date = %q{2010-05-20}
13
13
  s.description = %q{ORM that persists to file system using either XML or JSON with optional encryption layer.}
14
14
  s.email = %q{jared@codewordstudios.com}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 2
7
+ - 3
8
8
  - 0
9
- version: 0.2.0
9
+ version: 0.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - jdpace
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-19 00:00:00 -04:00
17
+ date: 2010-05-20 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency