scriber 0.0.2 → 0.0.3
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/.gitignore +1 -0
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/scriber/scribe.rb +18 -27
- data/lib/scriber.rb +17 -13
- data/scriber.gemspec +5 -7
- metadata +4 -6
- data/lib/scriber/backends/log.rb +0 -25
- data/lib/scriber/backends.rb +0 -15
data/.gitignore
CHANGED
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("
|
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.
|
1
|
+
0.0.3
|
data/lib/scriber/scribe.rb
CHANGED
@@ -1,39 +1,30 @@
|
|
1
1
|
module Scriber
|
2
|
-
class Scribe
|
3
|
-
include
|
2
|
+
class Scribe < SuperModel::Base
|
3
|
+
include SuperModel::RandomID
|
4
|
+
include SuperModel::Persist::Model
|
4
5
|
|
5
6
|
class << self
|
6
|
-
def
|
7
|
-
|
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
|
-
|
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
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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 "
|
2
|
+
gem "supermodel"
|
3
3
|
|
4
4
|
require "active_support/inflector"
|
5
5
|
require "active_support/core_ext/string/inflections"
|
6
|
-
require "
|
6
|
+
require "supermodel"
|
7
7
|
|
8
8
|
module Scriber
|
9
9
|
class ScriberError < StandardError; end
|
10
10
|
|
11
|
-
def
|
12
|
-
@
|
11
|
+
def disabled?
|
12
|
+
@disabled
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
16
|
-
@
|
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
|
-
|
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
|
-
|
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.
|
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-
|
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<
|
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<
|
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<
|
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.
|
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-
|
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:
|
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:
|
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
|
data/lib/scriber/backends/log.rb
DELETED
@@ -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
|
data/lib/scriber/backends.rb
DELETED