scriber 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  test.rb
2
2
  pkg
3
3
  scribe.log
4
+ dump.db
data/Rakefile CHANGED
@@ -8,7 +8,7 @@ begin
8
8
  gemspec.description = "Record class changes to disk, then replay them."
9
9
  gemspec.authors = ["Alex MacCaw"]
10
10
  gemspec.add_dependency("activesupport", ">=2.3.5")
11
- gemspec.add_dependency("activemodel")
11
+ gemspec.add_dependency("supermodel", ">=0.0.1")
12
12
  end
13
13
  rescue LoadError
14
14
  puts "Jeweler not available. Install it with: sudo gem install jeweler"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
@@ -1,39 +1,30 @@
1
1
  module Scriber
2
- class Scribe
3
- include ActiveModel::Observing
2
+ class Scribe < SuperModel::Base
3
+ include SuperModel::RandomID
4
+ include SuperModel::Persist::Model
4
5
 
5
6
  class << self
6
- def create(*args)
7
- self.new(*args).save
7
+ def since(id)
8
+ record = find(id)
9
+ index = records.index(record)
10
+ records.slice(index, -1).dup
11
+ rescue UnknownRecord
8
12
  end
9
13
  end
10
-
11
- attr_reader :klass, :type, :data
12
-
13
- def initialize(klass, type, data)
14
- @klass = klass
15
- @type = type
16
- @data = data
17
- end
18
-
14
+
15
+ validates_presence_of :klass, :type, :data
16
+
19
17
  def play
20
18
  klass.scribe_play(type, data)
21
19
  end
22
20
 
23
- def save
24
- notify_observers(:before_save)
25
- Scriber.backend.save(self)
26
- notify_observers(:after_save)
27
- true
28
- end
29
-
30
- def marshal_dump
31
- [klass.name, type, data]
32
- end
33
-
34
- def marshal_load(array)
35
- klass_name, @type, @data = array
36
- @klass = klass_name.constantize
21
+ def klass=(klass)
22
+ if klass.is_a?(String)
23
+ klass = klass.constantize
24
+ end
25
+ write_attribute(:klass, klass)
26
+ rescue NameError
27
+ write_attribute(:klass, nil)
37
28
  end
38
29
  end
39
30
  end
data/lib/scriber.rb CHANGED
@@ -1,36 +1,40 @@
1
1
  gem "activesupport"
2
- gem "activemodel"
2
+ gem "supermodel"
3
3
 
4
4
  require "active_support/inflector"
5
5
  require "active_support/core_ext/string/inflections"
6
- require "active_model"
6
+ require "supermodel"
7
7
 
8
8
  module Scriber
9
9
  class ScriberError < StandardError; end
10
10
 
11
- def backend
12
- @backend || raise("Set a backend")
11
+ def disabled?
12
+ @disabled
13
13
  end
14
14
 
15
- def backend=(b)
16
- @backend = b
15
+ def disable(&block)
16
+ @disabled = true
17
+ yield
18
+ @disabled = false
17
19
  end
18
-
20
+
19
21
  def record(klass, type, data)
20
- Scribe.create(klass, type, data)
22
+ return if disabled?
23
+ Scribe.create({
24
+ :klass => klass,
25
+ :type => type,
26
+ :data => data
27
+ })
21
28
  end
22
29
 
23
30
  def play
24
- backend.each {|scribe|
31
+ Scribe.all.each {|scribe|
25
32
  scribe.play
26
33
  }
27
34
  end
28
-
29
35
  extend self
30
36
  end
31
37
 
32
38
  $: << File.dirname(__FILE__)
33
39
 
34
- require "scriber/scribe"
35
- require "scriber/backends"
36
- require "scriber/backends/log"
40
+ require "scriber/scribe"
data/scriber.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{scriber}
8
- s.version = "0.0.2"
8
+ s.version = "0.0.3"
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-04}
12
+ s.date = %q{2010-02-06}
13
13
  s.description = %q{Record class changes to disk, then replay them.}
14
14
  s.email = %q{info@eribium.org}
15
15
  s.extra_rdoc_files = [
@@ -21,8 +21,6 @@ Gem::Specification.new do |s|
21
21
  "Rakefile",
22
22
  "VERSION",
23
23
  "lib/scriber.rb",
24
- "lib/scriber/backends.rb",
25
- "lib/scriber/backends/log.rb",
26
24
  "lib/scriber/scribe.rb",
27
25
  "scriber.gemspec"
28
26
  ]
@@ -38,14 +36,14 @@ Gem::Specification.new do |s|
38
36
 
39
37
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
40
38
  s.add_runtime_dependency(%q<activesupport>, [">= 2.3.5"])
41
- s.add_runtime_dependency(%q<activemodel>, [">= 0"])
39
+ s.add_runtime_dependency(%q<supermodel>, [">= 0.0.1"])
42
40
  else
43
41
  s.add_dependency(%q<activesupport>, [">= 2.3.5"])
44
- s.add_dependency(%q<activemodel>, [">= 0"])
42
+ s.add_dependency(%q<supermodel>, [">= 0.0.1"])
45
43
  end
46
44
  else
47
45
  s.add_dependency(%q<activesupport>, [">= 2.3.5"])
48
- s.add_dependency(%q<activemodel>, [">= 0"])
46
+ s.add_dependency(%q<supermodel>, [">= 0.0.1"])
49
47
  end
50
48
  end
51
49
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scriber
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
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-04 00:00:00 +00:00
12
+ date: 2010-02-06 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -23,14 +23,14 @@ dependencies:
23
23
  version: 2.3.5
24
24
  version:
25
25
  - !ruby/object:Gem::Dependency
26
- name: activemodel
26
+ name: supermodel
27
27
  type: :runtime
28
28
  version_requirement:
29
29
  version_requirements: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: "0"
33
+ version: 0.0.1
34
34
  version:
35
35
  description: Record class changes to disk, then replay them.
36
36
  email: info@eribium.org
@@ -46,8 +46,6 @@ files:
46
46
  - Rakefile
47
47
  - VERSION
48
48
  - lib/scriber.rb
49
- - lib/scriber/backends.rb
50
- - lib/scriber/backends/log.rb
51
49
  - lib/scriber/scribe.rb
52
50
  - scriber.gemspec
53
51
  has_rdoc: true
@@ -1,25 +0,0 @@
1
- module Scriber
2
- module Backends
3
- class Log < Base
4
- attr_reader :path
5
-
6
- def initialize(path)
7
- @path = path
8
- end
9
-
10
- def save(scribe)
11
- File.open(path, "ab") {|file|
12
- file.write(Marshal.dump(scribe) + $/)
13
- }
14
- end
15
-
16
- def each
17
- file = File.new(path, "rb")
18
- file.each {|line|
19
- yield(Marshal.load(line))
20
- }
21
- file.close
22
- end
23
- end
24
- end
25
- end
@@ -1,15 +0,0 @@
1
- module Scriber
2
- module Backends
3
- class Base
4
- class UnimplementedError < ScriberError; end
5
-
6
- def save(scribe)
7
- raise UnimplementedError
8
- end
9
-
10
- def each
11
- raise UnimplementedError
12
- end
13
- end
14
- end
15
- end