scriber 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ test.rb
2
+ pkg
3
+ scribe.log
data/README ADDED
@@ -0,0 +1,35 @@
1
+
2
+ Record class changes and replay them.
3
+ I plan to use this for Ruby class synchronisation on different clients.
4
+
5
+ Example:
6
+
7
+ require "scriber"
8
+
9
+ class Test
10
+ class << self
11
+ def var
12
+ @var
13
+ end
14
+
15
+ def var=(v)
16
+ @var = v
17
+ end
18
+
19
+ def scribe_play(type, data)
20
+ case type
21
+ when :var=
22
+ self.var = data
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ Scriber.backend = Scriber::Backends::Log.new("scribe.log")
29
+
30
+ Scriber.record(Test, :var=, 1)
31
+ Scriber.record(Test, :var=, 2)
32
+ Scriber.record(Test, :var=, 3)
33
+
34
+ Scriber.play
35
+ Test.var #=> 3
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ begin
2
+ require 'jeweler'
3
+ Jeweler::Tasks.new do |gemspec|
4
+ gemspec.name = "scriber"
5
+ gemspec.summary = "Record class changes to disk, then replay them."
6
+ gemspec.email = "info@eribium.org"
7
+ gemspec.homepage = "http://github.com/maccman/scriber"
8
+ gemspec.description = "Record class changes to disk, then replay them."
9
+ gemspec.authors = ["Alex MacCaw"]
10
+ gemspec.add_dependency("activesupport", ">=2.3.5")
11
+ end
12
+ rescue LoadError
13
+ puts "Jeweler not available. Install it with: sudo gem install jeweler"
14
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,25 @@
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 record(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
@@ -0,0 +1,15 @@
1
+ module Scriber
2
+ module Backends
3
+ class Base
4
+ class UnimplementedError < ScriberError; end
5
+
6
+ def record(scribe)
7
+ raise UnimplementedError
8
+ end
9
+
10
+ def each
11
+ raise UnimplementedError
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,24 @@
1
+ module Scriber
2
+ class Scribe
3
+ attr_reader :klass, :type, :data
4
+
5
+ def initialize(klass, type, data)
6
+ @klass = klass
7
+ @type = type
8
+ @data = data
9
+ end
10
+
11
+ def play
12
+ klass.scribe_play(type, data)
13
+ end
14
+
15
+ def marshal_dump
16
+ [klass.name, type, data]
17
+ end
18
+
19
+ def marshal_load(array)
20
+ klass_name, @type, @data = array
21
+ @klass = klass_name.constantize
22
+ end
23
+ end
24
+ end
data/lib/scriber.rb ADDED
@@ -0,0 +1,35 @@
1
+ gem "activesupport"
2
+
3
+ require "active_support/inflector"
4
+ require "active_support/core_ext/string/inflections"
5
+
6
+ module Scriber
7
+ class ScriberError < StandardError; end
8
+
9
+ def backend
10
+ @backend || raise("Set a backend")
11
+ end
12
+
13
+ def backend=(b)
14
+ @backend = b
15
+ end
16
+
17
+ def record(klass, type, data)
18
+ scribe = Scribe.new(klass, type, data)
19
+ backend.record(scribe)
20
+ end
21
+
22
+ def play
23
+ backend.each {|scribe|
24
+ scribe.play
25
+ }
26
+ end
27
+
28
+ extend self
29
+ end
30
+
31
+ $: << File.dirname(__FILE__)
32
+
33
+ require "scriber/scribe"
34
+ require "scriber/backends"
35
+ require "scriber/backends/log"
data/scriber.gemspec ADDED
@@ -0,0 +1,48 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{scriber}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Alex MacCaw"]
12
+ s.date = %q{2010-02-04}
13
+ s.description = %q{Record class changes to disk, then replay them.}
14
+ s.email = %q{info@eribium.org}
15
+ s.extra_rdoc_files = [
16
+ "README"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "README",
21
+ "Rakefile",
22
+ "VERSION",
23
+ "lib/scriber.rb",
24
+ "lib/scriber/backends.rb",
25
+ "lib/scriber/backends/log.rb",
26
+ "lib/scriber/scribe.rb",
27
+ "scriber.gemspec"
28
+ ]
29
+ s.homepage = %q{http://github.com/maccman/scriber}
30
+ s.rdoc_options = ["--charset=UTF-8"]
31
+ s.require_paths = ["lib"]
32
+ s.rubygems_version = %q{1.3.5}
33
+ s.summary = %q{Record class changes to disk, then replay them.}
34
+
35
+ if s.respond_to? :specification_version then
36
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
37
+ s.specification_version = 3
38
+
39
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
40
+ s.add_runtime_dependency(%q<activesupport>, [">= 2.3.5"])
41
+ else
42
+ s.add_dependency(%q<activesupport>, [">= 2.3.5"])
43
+ end
44
+ else
45
+ s.add_dependency(%q<activesupport>, [">= 2.3.5"])
46
+ end
47
+ end
48
+
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scriber
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Alex MacCaw
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-04 00:00:00 +00:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activesupport
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.3.5
24
+ version:
25
+ description: Record class changes to disk, then replay them.
26
+ email: info@eribium.org
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README
33
+ files:
34
+ - .gitignore
35
+ - README
36
+ - Rakefile
37
+ - VERSION
38
+ - lib/scriber.rb
39
+ - lib/scriber/backends.rb
40
+ - lib/scriber/backends/log.rb
41
+ - lib/scriber/scribe.rb
42
+ - scriber.gemspec
43
+ has_rdoc: true
44
+ homepage: http://github.com/maccman/scriber
45
+ licenses: []
46
+
47
+ post_install_message:
48
+ rdoc_options:
49
+ - --charset=UTF-8
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ requirements: []
65
+
66
+ rubyforge_project:
67
+ rubygems_version: 1.3.5
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: Record class changes to disk, then replay them.
71
+ test_files: []
72
+