supermodel 0.0.8 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.8
1
+ 0.1.0
@@ -1,6 +1,5 @@
1
1
  module SuperModel
2
2
  class Base
3
- include ActiveModel::Dirty
4
3
  class_inheritable_array :known_attributes
5
4
  self.known_attributes = []
6
5
 
@@ -224,7 +223,6 @@ module SuperModel
224
223
  self.id ||= generate_id
225
224
  self.new_record = false
226
225
  raw_create
227
- save_previous_changes
228
226
  self.id
229
227
  end
230
228
 
@@ -235,14 +233,8 @@ module SuperModel
235
233
 
236
234
  def update
237
235
  raw_update
238
- save_previous_changes
239
236
  true
240
237
  end
241
-
242
- def save_previous_changes
243
- @previously_changed = changes
244
- changed_attributes.clear
245
- end
246
238
 
247
239
  private
248
240
 
@@ -270,6 +262,6 @@ module SuperModel
270
262
  include ActiveModel::Conversion
271
263
  include ActiveModel::Serializers::JSON
272
264
  include ActiveModel::Serializers::Xml
273
- include Observing, Validations, Callbacks
265
+ include Dirty, Observing, Validations, Callbacks
274
266
  end
275
267
  end
@@ -0,0 +1,24 @@
1
+ module SuperModel
2
+ module Dirty
3
+ extend ActiveSupport::Concern
4
+ include ActiveModel::Dirty
5
+
6
+ included do
7
+ %w( create update ).each do |method|
8
+ class_eval(<<-EOS, __FILE__, __LINE__ + 1)
9
+ def #{method}_with_dirty(*args, &block)
10
+ result = #{method}_without_dirty(*args, &block)
11
+ save_previous_changes
12
+ result
13
+ end
14
+ EOS
15
+ alias_method_chain(method, :dirty)
16
+ end
17
+ end
18
+
19
+ def save_previous_changes
20
+ @previously_changed = changes
21
+ changed_attributes.clear
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ module SuperModel
2
+ module Timestamp
3
+ module Model
4
+ def self.included(base)
5
+ base.class_eval do
6
+ attributes :created_at, :updated_at
7
+
8
+ before_create :set_created_at
9
+ before_save :set_updated_at
10
+ end
11
+
12
+ private
13
+
14
+ def set_created_at
15
+ self.created_at = Time.now
16
+ end
17
+
18
+ def set_updated_at
19
+ self.updated_at = Time.now
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
data/lib/supermodel.rb CHANGED
@@ -28,6 +28,8 @@ require "supermodel/callbacks"
28
28
  require "supermodel/observing"
29
29
  require "supermodel/marshal"
30
30
  require "supermodel/random_id"
31
+ require "supermodel/timestamp"
31
32
  require "supermodel/validations"
33
+ require "supermodel/dirty"
32
34
  require "supermodel/base"
33
35
  require "supermodel/redis"
data/supermodel.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{supermodel}
8
- s.version = "0.0.8"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Alex MacCaw"]
12
- s.date = %q{2010-02-10}
12
+ s.date = %q{2010-02-16}
13
13
  s.description = %q{In memory DB using ActiveModel}
14
14
  s.email = %q{info@eribium.org}
15
15
  s.extra_rdoc_files = [
@@ -24,10 +24,12 @@ Gem::Specification.new do |s|
24
24
  "lib/supermodel.rb",
25
25
  "lib/supermodel/base.rb",
26
26
  "lib/supermodel/callbacks.rb",
27
+ "lib/supermodel/dirty.rb",
27
28
  "lib/supermodel/marshal.rb",
28
29
  "lib/supermodel/observing.rb",
29
30
  "lib/supermodel/random_id.rb",
30
31
  "lib/supermodel/redis.rb",
32
+ "lib/supermodel/timestamp.rb",
31
33
  "lib/supermodel/validations.rb",
32
34
  "supermodel.gemspec"
33
35
  ]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: supermodel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex MacCaw
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-10 00:00:00 +00:00
12
+ date: 2010-02-16 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -39,10 +39,12 @@ files:
39
39
  - lib/supermodel.rb
40
40
  - lib/supermodel/base.rb
41
41
  - lib/supermodel/callbacks.rb
42
+ - lib/supermodel/dirty.rb
42
43
  - lib/supermodel/marshal.rb
43
44
  - lib/supermodel/observing.rb
44
45
  - lib/supermodel/random_id.rb
45
46
  - lib/supermodel/redis.rb
47
+ - lib/supermodel/timestamp.rb
46
48
  - lib/supermodel/validations.rb
47
49
  - supermodel.gemspec
48
50
  has_rdoc: true