undo 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -2
  3. data/Gemfile +0 -7
  4. data/README.md +40 -38
  5. data/lib/undo.rb +5 -4
  6. data/lib/undo/config.rb +10 -8
  7. data/lib/undo/{environment.rb → gemspec.rb} +1 -0
  8. data/lib/undo/model.rb +6 -1
  9. data/lib/undo/serializer/null.rb +13 -0
  10. data/lib/undo/storage/{memory_adapter.rb → memory.rb} +2 -2
  11. data/spec/undo/model_spec.rb +25 -0
  12. data/spec/undo/serializer/null_spec.rb +19 -0
  13. data/spec/undo/storage/memory_spec.rb +13 -0
  14. data/spec/undo_spec.rb +18 -18
  15. data/undo.gemspec +10 -4
  16. metadata +18 -54
  17. data/lib/undo/serializer/simple.rb +0 -23
  18. data/lib/undo/version.rb +0 -3
  19. data/spec/acceptance/it_works_spec.rb +0 -7
  20. data/spec/acceptance/undo_deletion_spec.rb +0 -14
  21. data/spec/factories.rb +0 -6
  22. data/spec/it_works_spec.rb +0 -8
  23. data/spec/rails_app/.gitignore +0 -4
  24. data/spec/rails_app/Rakefile +0 -7
  25. data/spec/rails_app/app/models/.gitkeep +0 -0
  26. data/spec/rails_app/app/models/user.rb +0 -2
  27. data/spec/rails_app/config.ru +0 -4
  28. data/spec/rails_app/config/application.rb +0 -13
  29. data/spec/rails_app/config/boot.rb +0 -6
  30. data/spec/rails_app/config/database.yml +0 -22
  31. data/spec/rails_app/config/environment.rb +0 -5
  32. data/spec/rails_app/config/environments/development.rb +0 -23
  33. data/spec/rails_app/config/environments/production.rb +0 -50
  34. data/spec/rails_app/config/environments/test.rb +0 -34
  35. data/spec/rails_app/config/routes.rb +0 -2
  36. data/spec/rails_app/db/migrate/20140214213610_create_users.rb +0 -10
  37. data/spec/rails_app/db/schema.rb +0 -23
  38. data/spec/rails_app/db/seeds.rb +0 -7
  39. data/spec/rails_app/script/rails +0 -6
  40. data/spec/spec_helper_rails.rb +0 -22
  41. data/spec/undo/serializer/simple_spec.rb +0 -19
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: be7c69cbf8e0489d7d3ee42a63d3791ace4a85ee
4
- data.tar.gz: 8652a478948f1e5cd1ea38e1c7943d025f755b4d
3
+ metadata.gz: c5b749d7de8d45dac8367342ed0d678c5e4a6286
4
+ data.tar.gz: bc8cab3fff78e6d6edfb98e071f2e811b9a54d97
5
5
  SHA512:
6
- metadata.gz: aa050823366a0684e076aa024f2b5a90078f9c6e7df8a6e3cfaf1a08134025b193bdd95383b2bdcb705d8fc376951d73eda5b367efdc4ab35b6caaafdc3fd347
7
- data.tar.gz: 96d0ab84f7c9269d9d032b0ec55f0f6d02b0d6efaafba220696f2b3eb9730f368b974d41ef07a1f4311ef0baa0424339d383baa737fa7f0dd0aeabca73c1c03d
6
+ metadata.gz: dd5f16a578091ab7827d0876a2f8d7b01080c0f22dc35372c7d11e6d2153478ceb1d0f7f1c7a8734f73346342017406a7e7c48d3ac759787302da832284dd338
7
+ data.tar.gz: 09685a617567f1aaeeebd28073e869f6a82200217293fa7fff80690efccd09ac4a060aeeb214317e821bbbf25a4fdbd5fb90ec9742ea052826bae48bb61c47cd
data/.travis.yml CHANGED
@@ -4,14 +4,14 @@ rvm:
4
4
  - 2.0
5
5
  - 1.9.3
6
6
  - ruby-head
7
- - rbx-19mode
7
+ - rbx
8
8
  - jruby-19mode
9
9
  - jruby-head
10
10
 
11
11
  matrix:
12
12
  allow_failures:
13
13
  - rvm: ruby-head
14
- - rvm: rbx-19mode
14
+ - rvm: rbx
15
15
  - rvm: jruby-19mode
16
16
  - rvm: jruby-head
17
17
 
data/Gemfile CHANGED
@@ -2,10 +2,3 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in undo.gemspec
4
4
  gemspec
5
-
6
- group :test do
7
- gem 'rails', '4.0.2'
8
- gem 'sqlite3'
9
- gem 'factory_girl'
10
- gem 'faker'
11
- end
data/README.md CHANGED
@@ -1,12 +1,19 @@
1
1
  Undo
2
2
  ==========
3
- [![Build Status](https://travis-ci.org/AlexParamonov/undo.png?branch=master)](http://travis-ci.org/AlexParamonov/undo)
3
+ [![Build Status](https://travis-ci.org/AlexParamonov/undo.png?branch=master)](https://travis-ci.org/AlexParamonov/undo)
4
4
  [![Gemnasium Build Status](https://gemnasium.com/AlexParamonov/undo.png)](http://gemnasium.com/AlexParamonov/undo)
5
5
  [![Coverage Status](https://coveralls.io/repos/AlexParamonov/undo/badge.png?branch=master)](https://coveralls.io/r/AlexParamonov/undo?branch=master)
6
+ [![Gem Version](https://badge.fury.io/rb/undo.png)](http://badge.fury.io/rb/undo)
6
7
 
7
- Undo last operation on object.
8
- Undo gem allows to use custom adapters for storage (Redis,
9
- ActiveRecord, etc). And custom serializers when need (ActiveRecord, Virtus, etc)
8
+ Undo reverts operation made upon object.
9
+ It stores the object state before the mutator operation and allows to
10
+ restore this state later.
11
+
12
+ Undo uses adapters for storage (Redis, ActiveRecord, etc) and custom
13
+ serializers (ActiveRecord, Virtus, etc). It is very lightweight
14
+ solution that can be used as well with heavy ActiveRecord as with
15
+ simple Hash or Virtus objects. No database required: store data as it
16
+ suites you.
10
17
 
11
18
  Contents
12
19
  ---------
@@ -85,42 +92,26 @@ end
85
92
 
86
93
  ### Configuration options
87
94
  `storage` option responsible for putting and fetching object state to or from some storage.
88
- Implement `put(uuid, object)` and `fetch(uuid)` methods. See MemoryAdapter for example.
95
+ Implement `put(uuid, object)` and `fetch(uuid)` methods.
96
+ Currently available storages:
97
+ * `Undo::Storage::Memory` simple runtime storage (Hash)
98
+ * `gem "undo-storage-redis"` designed to be used with `gem "redis"` from v0.1 to current
99
+
89
100
  See also [documentation](http://github.com/AlexParamonov/undo)
90
- on project repository for currently available storage adapters.
91
- If provided storage cant handle objects (most of the storage works with own formats as json for example),
92
- pass `serializer` to it:
101
+ on project repository for full list of currently available storage adapters.
102
+ To convert objects to data that can be processed by storage adapters and backward, use `serializers`:
93
103
 
94
104
  ``` ruby
95
105
  Undo.configure do |config|
96
- config.storage = AnotherStorage.new(serializer: config.serializer)
106
+ config.serializer = CustomSerializer.new
97
107
  end
98
108
  ```
99
109
 
100
- By default here is very basic `Serializer::Simple`.
101
- There are no more serializers available now, but check
102
- [documentation](http://github.com/AlexParamonov/undo) on project
103
- repository for currently available serializers.
104
-
105
- Serializer is not used by `Undo` gem directly. It mean to be used in
106
- storage adopters to serialize and deserialize data to required format.
107
- Storage adapter may use serializer this way:
108
-
109
- ``` ruby
110
- json = serializer.to_json object # in put method
111
- return serializer.load_from_json json # in fetch method
112
-
113
- xml = serializer.to_xml object
114
- object = serializer.load_from_xml xml
115
- ```
110
+ Currently available serializers:
111
+ * `Undo::Serializer::Null` pass though serializer. It do nothing and returns whatever passed to it.
116
112
 
117
- Usage of serializer is optional, some storages does not need them.
118
- Serializer has the responsibility to write object to persistence
119
- (load_from\_\* methods) This seems a good candinate to extraction to own
120
- class (Deserializer or Loader) but due to to\_\* and load_from\_\*
121
- method are tightly coupled with data format it is in one class now.
122
- Let me know using the Github feedback (create an issue) if you have
123
- any idea on this topic.
113
+ Check [documentation](http://github.com/AlexParamonov/undo) on project
114
+ repository for currently available serializers.
124
115
 
125
116
  `uuid_generator` option allows to setup custom uuid generator.
126
117
 
@@ -144,20 +135,29 @@ end
144
135
  ```
145
136
 
146
137
  ### In place configuration
147
- Any configuration option from previous chapter can be applied in place
148
- only for given operation.
149
- To restore object from another storage use `storage` option:
138
+ Any configuration option from previous chapter can be applied in
139
+ place for given operation. To restore object from another storage use
140
+ `storage` option:
150
141
 
151
142
  ``` ruby
152
143
  Undo.restore uuid, storage: AnotherStorage.new
153
144
  ```
154
145
 
155
- To wrap an object using custom serializer use `serializer` option:
146
+ To wrap an object using custom mutator_methods use `mutator_methods` option:
156
147
 
157
148
  ``` ruby
158
- Undo.wrap object, serializer: AnotherSerializer.new
149
+ Undo.wrap object, mutator_methods: [:save]
159
150
  ```
160
151
 
152
+ To use custom serializer or deserializer use `serializer` option:
153
+
154
+ ``` ruby
155
+ Undo.wrap post, serializer: PostSerializer.new(post)
156
+ post.destroy
157
+ Undo.restore uuid, serializer: PostDeserializer.new(options)
158
+ ```
159
+
160
+
161
161
  Contacts
162
162
  -------------
163
163
  Have questions or recommendations? Contact me via `alexander.n.paramonov@gmail.com`
@@ -171,8 +171,10 @@ tested with Ruby
171
171
  * 2.1
172
172
  * 2.0
173
173
  * 1.9.3
174
- * rbx-19mode
175
174
  * ruby-head
175
+ * rbx
176
+ * jruby-19mode
177
+ * jruby-head
176
178
 
177
179
  See [build history](http://travis-ci.org/#!/AlexParamonov/undo/builds)
178
180
 
data/lib/undo.rb CHANGED
@@ -1,12 +1,11 @@
1
- require "undo/version"
1
+ require "undo/gemspec"
2
2
  require "undo/config"
3
3
 
4
4
  module Undo
5
5
  require "undo/model"
6
6
 
7
7
  def self.configure(&block)
8
- yield(config) if block_given?
9
- config
8
+ block_given? ? block.call(config) : config
10
9
  end
11
10
 
12
11
  def self.config
@@ -18,6 +17,8 @@ module Undo
18
17
  end
19
18
 
20
19
  def self.restore(uuid, options = {})
21
- config.with(options).storage.fetch uuid
20
+ config.with(options) do |config|
21
+ config.serializer.deserialize config.storage.fetch uuid
22
+ end
22
23
  end
23
24
  end
data/lib/undo/config.rb CHANGED
@@ -10,18 +10,20 @@ module Undo
10
10
  require "securerandom"
11
11
  ->(object) { SecureRandom.uuid }
12
12
  }
13
- attribute :storage, Object, default: ->(config, _) {
14
- require "undo/storage/memory_adapter"
15
- Undo::Storage::MemoryAdapter.new
16
- }
17
13
  attribute :serializer, Object, default: ->(config, _) {
18
- require "undo/serializer/simple"
19
- Undo::Serializer::Simple.new
14
+ require "undo/serializer/null"
15
+ Undo::Serializer::Null.new
20
16
  }
17
+ attribute :storage, Object, default: ->(config, _) {
18
+ require "undo/storage/memory"
19
+ Undo::Storage::Memory.new serializer: config.serializer
20
+ }, lazy: true
21
21
 
22
22
  def with(attribute_updates = {}, &block)
23
- return self if attribute_updates.empty?
24
- self.class.new attribute_set.get(self).merge(attribute_updates)
23
+ config = attribute_updates.empty? ? self
24
+ : self.class.new(attribute_set.get(self).merge attribute_updates)
25
+
26
+ block_given? ? block.call(config) : config
25
27
  end
26
28
  end
27
29
  end
@@ -1,3 +1,4 @@
1
1
  module Undo
2
+ VERSION = "0.0.2"
2
3
  RUNNING_ON_CI = !!ENV['CI']
3
4
  end
data/lib/undo/model.rb CHANGED
@@ -1,5 +1,10 @@
1
+ require "forwardable"
2
+
1
3
  module Undo
2
4
  class Model < SimpleDelegator
5
+ extend Forwardable
6
+ def_delegators :object, :class, :kind_of?
7
+
3
8
  def initialize(object, options = {})
4
9
  @object = object
5
10
  @config = config.with options
@@ -23,7 +28,7 @@ module Undo
23
28
  end
24
29
 
25
30
  def store
26
- config.storage.put uuid, object
31
+ config.storage.put uuid, config.serializer.serialize(object)
27
32
  end
28
33
 
29
34
  def config
@@ -0,0 +1,13 @@
1
+ module Undo
2
+ module Serializer
3
+ class Null
4
+ def serialize(object)
5
+ object
6
+ end
7
+
8
+ def deserialize(object)
9
+ object
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,6 +1,6 @@
1
1
  module Undo
2
2
  module Storage
3
- class MemoryAdapter
3
+ class Memory
4
4
  def initialize(options = {})
5
5
  end
6
6
 
@@ -9,7 +9,7 @@ module Undo
9
9
  end
10
10
 
11
11
  def fetch(uuid)
12
- storage.fetch uuid
12
+ storage.fetch(uuid)
13
13
  end
14
14
 
15
15
  private
@@ -32,5 +32,30 @@ describe Undo::Model do
32
32
 
33
33
  end
34
34
 
35
+ describe "stores object data" do
36
+ let(:object) { double :object, change: true }
37
+ let(:storage) { double :storage }
38
+ let(:serializer) { double :serializer }
39
+
40
+ specify "when called mutator method" do
41
+ expect(storage).to receive(:put)
42
+
43
+ model = subject.new object,
44
+ storage: storage,
45
+ mutator_methods: [:change]
46
+ model.change
47
+ end
48
+
49
+ it "serializes data before storing" do
50
+ expect(serializer).to receive(:serialize).with(object).ordered
51
+ expect(storage).to receive(:put).ordered
52
+
53
+ model = subject.new object,
54
+ storage: storage,
55
+ serializer: serializer,
56
+ mutator_methods: [:change]
57
+ model.change
58
+ end
59
+ end
35
60
  end
36
61
  end
@@ -0,0 +1,19 @@
1
+ require "spec_helper_lite"
2
+ require "undo/serializer/null"
3
+
4
+ describe Undo::Serializer::Null do
5
+ subject { described_class }
6
+ let(:serializer) { described_class.new }
7
+
8
+ describe "returns passed argument" do
9
+ let(:object) { double :object }
10
+
11
+ specify "#serialize" do
12
+ expect(serializer.serialize object).to eq object
13
+ end
14
+
15
+ specify "#deserialize" do
16
+ expect(serializer.deserialize object).to eq object
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ require "spec_helper_lite"
2
+ require 'undo/storage/memory'
3
+
4
+ describe Undo::Storage::Memory do
5
+ subject { described_class }
6
+ let(:adapter) { subject.new }
7
+ let(:object) { double :object }
8
+
9
+ it "stores any object" do
10
+ adapter.put 123, object
11
+ expect(adapter.fetch 123).to eq object
12
+ end
13
+ end
data/spec/undo_spec.rb CHANGED
@@ -1,11 +1,10 @@
1
1
  require "spec_helper_lite"
2
2
 
3
3
  describe Undo do
4
+ let(:object) { double :object, change: true }
4
5
  subject { described_class }
5
6
 
6
7
  describe "#wrap" do
7
- let(:object) { double :object, change: true }
8
-
9
8
  before do
10
9
  subject.configure do |config|
11
10
  config.mutator_methods = [:change]
@@ -13,34 +12,35 @@ describe Undo do
13
12
  end
14
13
 
15
14
  it "is a decorator" do
16
- object = [:a, :b]
15
+ object = %w[hello world]
16
+
17
17
  decorator = subject.wrap object
18
18
  expect(object).to receive(:some_method)
19
-
20
19
  decorator.some_method
21
- expect(object.class).to eq Array
20
+
21
+ expect(decorator.class).to eq Array
22
+ expect(decorator).to be_a Array
22
23
  end
24
+ end
23
25
 
26
+ describe "restores object by uuid" do
24
27
  it "restores object" do
25
- undoable_model = subject.wrap object
26
- undoable_model.change
27
- restored_object = subject.restore undoable_model.uuid
28
+ model = subject.wrap object
29
+ model.change
30
+ restored_object = subject.restore model.uuid
28
31
 
29
32
  expect(restored_object).to eq object
30
33
  end
31
34
 
32
- describe "with options" do
33
- it "restores using provided options" do
34
- storage = double
35
- expect(storage).to receive(:put)
36
- expect(storage).to receive(:fetch) { object }
35
+ it "restores using provided options" do
36
+ serializer = double :serializer
37
+ expect(serializer).to receive(:deserialize) { object }
37
38
 
38
- undoable_model = subject.wrap object, storage: storage
39
- undoable_model.change
40
- restored_object = subject.restore undoable_model.uuid, storage: storage
39
+ model = subject.wrap object
40
+ model.change
41
+ restored_object = subject.restore model.uuid, serializer: serializer
41
42
 
42
- expect(restored_object).to eq object
43
- end
43
+ expect(restored_object).to eq object
44
44
  end
45
45
  end
46
46
  end
data/undo.gemspec CHANGED
@@ -1,16 +1,22 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'undo/version'
5
- require 'undo/environment'
4
+ require 'undo/gemspec'
6
5
 
7
6
  Gem::Specification.new do |spec|
8
7
  spec.name = "undo"
9
8
  spec.version = Undo::VERSION
10
9
  spec.authors = ["Alexander Paramonov"]
11
10
  spec.email = ["alexander.n.paramonov@gmail.com"]
12
- spec.summary = %q{Undo operations on object}
13
- spec.description = %q{Undo allows to reverl last operation on object}
11
+ spec.summary = %q{Reverts operation made upon object}
12
+ spec.description = %q{
13
+ Undo reverts operation made upon object.
14
+ It stores the object state before the mutator operation and allows to restore this state later.
15
+
16
+ Undo uses adapters for storage (Redis, ActiveRecord, etc) and custom serializers (ActiveRecord, Virtus, etc).
17
+ It is very lightweight solution that can be used as well with heavy ActiveRecord as with simple Hash or Virtus objects.
18
+ No database required: store data as it suites you.
19
+ }
14
20
  spec.homepage = "http://github.com/AlexParamonov/undo"
15
21
  spec.license = "MIT"
16
22
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: undo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Paramonov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-15 00:00:00.000000000 Z
11
+ date: 2014-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: virtus
@@ -94,7 +94,14 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
- description: Undo allows to reverl last operation on object
97
+ description: |2
98
+
99
+ Undo reverts operation made upon object.
100
+ It stores the object state before the mutator operation and allows to restore this state later.
101
+
102
+ Undo uses adapters for storage (Redis, ActiveRecord, etc) and custom serializers (ActiveRecord, Virtus, etc).
103
+ It is very lightweight solution that can be used as well with heavy ActiveRecord as with simple Hash or Virtus objects.
104
+ No database required: store data as it suites you.
98
105
  email:
99
106
  - alexander.n.paramonov@gmail.com
100
107
  executables: []
@@ -113,36 +120,14 @@ files:
113
120
  - Rakefile
114
121
  - lib/undo.rb
115
122
  - lib/undo/config.rb
116
- - lib/undo/environment.rb
123
+ - lib/undo/gemspec.rb
117
124
  - lib/undo/model.rb
118
- - lib/undo/serializer/simple.rb
119
- - lib/undo/storage/memory_adapter.rb
120
- - lib/undo/version.rb
121
- - spec/acceptance/it_works_spec.rb
122
- - spec/acceptance/undo_deletion_spec.rb
123
- - spec/factories.rb
124
- - spec/it_works_spec.rb
125
- - spec/rails_app/.gitignore
126
- - spec/rails_app/Rakefile
127
- - spec/rails_app/app/models/.gitkeep
128
- - spec/rails_app/app/models/user.rb
129
- - spec/rails_app/config.ru
130
- - spec/rails_app/config/application.rb
131
- - spec/rails_app/config/boot.rb
132
- - spec/rails_app/config/database.yml
133
- - spec/rails_app/config/environment.rb
134
- - spec/rails_app/config/environments/development.rb
135
- - spec/rails_app/config/environments/production.rb
136
- - spec/rails_app/config/environments/test.rb
137
- - spec/rails_app/config/routes.rb
138
- - spec/rails_app/db/migrate/20140214213610_create_users.rb
139
- - spec/rails_app/db/schema.rb
140
- - spec/rails_app/db/seeds.rb
141
- - spec/rails_app/script/rails
125
+ - lib/undo/serializer/null.rb
126
+ - lib/undo/storage/memory.rb
142
127
  - spec/spec_helper_lite.rb
143
- - spec/spec_helper_rails.rb
144
128
  - spec/undo/model_spec.rb
145
- - spec/undo/serializer/simple_spec.rb
129
+ - spec/undo/serializer/null_spec.rb
130
+ - spec/undo/storage/memory_spec.rb
146
131
  - spec/undo_spec.rb
147
132
  - undo.gemspec
148
133
  homepage: http://github.com/AlexParamonov/undo
@@ -168,32 +153,11 @@ rubyforge_project:
168
153
  rubygems_version: 2.2.2
169
154
  signing_key:
170
155
  specification_version: 4
171
- summary: Undo operations on object
156
+ summary: Reverts operation made upon object
172
157
  test_files:
173
- - spec/acceptance/it_works_spec.rb
174
- - spec/acceptance/undo_deletion_spec.rb
175
- - spec/factories.rb
176
- - spec/it_works_spec.rb
177
- - spec/rails_app/.gitignore
178
- - spec/rails_app/Rakefile
179
- - spec/rails_app/app/models/.gitkeep
180
- - spec/rails_app/app/models/user.rb
181
- - spec/rails_app/config.ru
182
- - spec/rails_app/config/application.rb
183
- - spec/rails_app/config/boot.rb
184
- - spec/rails_app/config/database.yml
185
- - spec/rails_app/config/environment.rb
186
- - spec/rails_app/config/environments/development.rb
187
- - spec/rails_app/config/environments/production.rb
188
- - spec/rails_app/config/environments/test.rb
189
- - spec/rails_app/config/routes.rb
190
- - spec/rails_app/db/migrate/20140214213610_create_users.rb
191
- - spec/rails_app/db/schema.rb
192
- - spec/rails_app/db/seeds.rb
193
- - spec/rails_app/script/rails
194
158
  - spec/spec_helper_lite.rb
195
- - spec/spec_helper_rails.rb
196
159
  - spec/undo/model_spec.rb
197
- - spec/undo/serializer/simple_spec.rb
160
+ - spec/undo/serializer/null_spec.rb
161
+ - spec/undo/storage/memory_spec.rb
198
162
  - spec/undo_spec.rb
199
163
  has_rdoc:
@@ -1,23 +0,0 @@
1
- require "json"
2
-
3
- module Undo
4
- module Serializer
5
- class Simple
6
- def to_json(object)
7
- object.to_json
8
- end
9
-
10
- def load_from_json(json)
11
- JSON.parse json
12
- end
13
-
14
- def to_xml(object)
15
- raise NotImplementedError
16
- end
17
-
18
- def load_from_xml(xml)
19
- raise NotImplementedError
20
- end
21
- end
22
- end
23
- end
data/lib/undo/version.rb DELETED
@@ -1,3 +0,0 @@
1
- module Undo
2
- VERSION = "0.0.1"
3
- end
@@ -1,7 +0,0 @@
1
- require "spec_helper_rails"
2
-
3
- describe "Initial rails setup" do
4
- it "works" do
5
- expect(true).to eq true
6
- end
7
- end
@@ -1,14 +0,0 @@
1
- require "spec_helper_rails"
2
-
3
- describe "Undo deletion" do
4
- subject { Undo }
5
-
6
- it "reverts user deletion" do
7
- user = create :user
8
- undoable_model = subject.wrap user
9
- undoable_model.destroy
10
- restored_user = subject.restore undoable_model.uuid
11
-
12
- expect(restored_user).to eq user
13
- end
14
- end
data/spec/factories.rb DELETED
@@ -1,6 +0,0 @@
1
- FactoryGirl.define do
2
- factory :user do
3
- name { Faker::Name.name }
4
- email { Faker::Internet.email }
5
- end
6
- end
@@ -1,8 +0,0 @@
1
- require "spec_helper_lite"
2
-
3
- describe "Initial setup" do
4
- it "works" do
5
- expect(true).to eq true
6
- end
7
-
8
- end
@@ -1,4 +0,0 @@
1
- .bundle
2
- db/*.sqlite3
3
- log/*.log
4
- tmp/
@@ -1,7 +0,0 @@
1
- # Add your own tasks in files placed in lib/tasks ending in .rake,
2
- # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
-
4
- require File.expand_path('../config/application', __FILE__)
5
- require 'rake'
6
-
7
- RailsApp::Application.load_tasks
File without changes
@@ -1,2 +0,0 @@
1
- class User < ActiveRecord::Base
2
- end
@@ -1,4 +0,0 @@
1
- # This file is used by Rack-based servers to start the application.
2
-
3
- require ::File.expand_path('../config/environment', __FILE__)
4
- run RailsApp::Application
@@ -1,13 +0,0 @@
1
- require File.expand_path('../boot', __FILE__)
2
-
3
- require "rails/all"
4
-
5
- # If you have a Gemfile, require the gems listed there, including any gems
6
- # you've limited to :test, :development, or :production.
7
- Bundler.require(:default, Rails.env) if defined?(Bundler)
8
-
9
- module RailsApp
10
- class Application < Rails::Application
11
- I18n.enforce_available_locales = false
12
- end
13
- end
@@ -1,6 +0,0 @@
1
- require 'rubygems'
2
-
3
- # Set up gems listed in the Gemfile.
4
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
5
-
6
- require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
@@ -1,22 +0,0 @@
1
- # SQLite version 3.x
2
- # gem install sqlite3
3
- development:
4
- adapter: sqlite3
5
- database: db/development.sqlite3
6
- pool: 5
7
- timeout: 5000
8
-
9
- # Warning: The database defined as "test" will be erased and
10
- # re-generated from your development database when you run "rake".
11
- # Do not set this db to the same as development or production.
12
- test:
13
- adapter: sqlite3
14
- database: db/test.sqlite3
15
- pool: 5
16
- timeout: 5000
17
-
18
- production:
19
- adapter: sqlite3
20
- database: db/production.sqlite3
21
- pool: 5
22
- timeout: 5000
@@ -1,5 +0,0 @@
1
- # Load the rails application
2
- require File.expand_path('../application', __FILE__)
3
-
4
- # Initialize the rails application
5
- RailsApp::Application.initialize!
@@ -1,23 +0,0 @@
1
- RailsApp::Application.configure do
2
- # Settings specified here will take precedence over those in config/application.rb
3
-
4
- # In the development environment your application's code is reloaded on
5
- # every request. This slows down response time but is perfect for development
6
- # since you don't have to restart the webserver when you make code changes.
7
- config.cache_classes = false
8
- config.eager_load = false
9
-
10
- # Show full error reports and disable caching
11
- config.consider_all_requests_local = true
12
- config.action_controller.perform_caching = false
13
-
14
- # Don't care if the mailer can't send
15
- config.action_mailer.raise_delivery_errors = false
16
-
17
- # Print deprecation notices to the Rails logger
18
- config.active_support.deprecation = :log
19
-
20
- # Only use best-standards-support built into browsers
21
- config.action_dispatch.best_standards_support = :builtin
22
- end
23
-
@@ -1,50 +0,0 @@
1
- RailsApp::Application.configure do
2
- # Settings specified here will take precedence over those in config/application.rb
3
-
4
- # The production environment is meant for finished, "live" apps.
5
- # Code is not reloaded between requests
6
- config.cache_classes = true
7
- config.eager_load = true
8
-
9
- # Full error reports are disabled and caching is turned on
10
- config.consider_all_requests_local = false
11
- config.action_controller.perform_caching = true
12
-
13
- # Specifies the header that your server uses for sending files
14
- config.action_dispatch.x_sendfile_header = "X-Sendfile"
15
-
16
- # For nginx:
17
- # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
18
-
19
- # If you have no front-end server that supports something like X-Sendfile,
20
- # just comment this out and Rails will serve the files
21
-
22
- # See everything in the log (default is :info)
23
- # config.log_level = :debug
24
-
25
- # Use a different logger for distributed setups
26
- # config.logger = SyslogLogger.new
27
-
28
- # Use a different cache store in production
29
- # config.cache_store = :mem_cache_store
30
-
31
- # Disable Rails's static asset server
32
- # In production, Apache or nginx will already do this
33
- config.serve_static_assets = false
34
-
35
- # Enable serving of images, stylesheets, and javascripts from an asset server
36
- # config.action_controller.asset_host = "http://assets.example.com"
37
-
38
- # Disable delivery errors, bad email addresses will be ignored
39
- # config.action_mailer.raise_delivery_errors = false
40
-
41
- # Enable threaded mode
42
- # config.threadsafe!
43
-
44
- # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
45
- # the I18n.default_locale when a translation can not be found)
46
- config.i18n.fallbacks = true
47
-
48
- # Send deprecation notices to registered listeners
49
- config.active_support.deprecation = :notify
50
- end
@@ -1,34 +0,0 @@
1
- RailsApp::Application.configure do
2
- # Settings specified here will take precedence over those in config/application.rb
3
-
4
- # The test environment is used exclusively to run your application's
5
- # test suite. You never need to work with it otherwise. Remember that
6
- # your test database is "scratch space" for the test suite and is wiped
7
- # and recreated between test runs. Don't rely on the data there!
8
- config.cache_classes = true
9
- config.eager_load = false
10
-
11
- # Show full error reports and disable caching
12
- config.consider_all_requests_local = true
13
- config.action_controller.perform_caching = false
14
-
15
- # Raise exceptions instead of rendering exception templates
16
- config.action_dispatch.show_exceptions = false
17
-
18
- # Disable request forgery protection in test environment
19
- config.action_controller.allow_forgery_protection = false
20
-
21
- # Tell Action Mailer not to deliver emails to the real world.
22
- # The :test delivery method accumulates sent emails in the
23
- # ActionMailer::Base.deliveries array.
24
- config.action_mailer.delivery_method = :test
25
- config.action_mailer.default_url_options = { :host => 'www.example.com' }
26
-
27
- # Use SQL instead of Active Record's schema dumper when creating the test database.
28
- # This is necessary if your schema can't be completely dumped by the schema dumper,
29
- # like if you have constraints or database-specific column types
30
- # config.active_record.schema_format = :sql
31
-
32
- # Print deprecation notices to the stderr
33
- config.active_support.deprecation = :stderr
34
- end
@@ -1,2 +0,0 @@
1
- RailsApp::Application.routes.draw do
2
- end
@@ -1,10 +0,0 @@
1
- class CreateUsers < ActiveRecord::Migration
2
- def change
3
- create_table :users do |t|
4
- t.string :name
5
- t.string :email
6
-
7
- t.timestamps
8
- end
9
- end
10
- end
@@ -1,23 +0,0 @@
1
- # encoding: UTF-8
2
- # This file is auto-generated from the current state of the database. Instead
3
- # of editing this file, please use the migrations feature of Active Record to
4
- # incrementally modify your database, and then regenerate this schema definition.
5
- #
6
- # Note that this schema.rb definition is the authoritative source for your
7
- # database schema. If you need to create the application database on another
8
- # system, you should be using db:schema:load, not running all the migrations
9
- # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
- # you'll amass, the slower it'll run and the greater likelihood for issues).
11
- #
12
- # It's strongly recommended that you check this file into your version control system.
13
-
14
- ActiveRecord::Schema.define(version: 20140214213610) do
15
-
16
- create_table "users", force: true do |t|
17
- t.string "name"
18
- t.string "email"
19
- t.datetime "created_at"
20
- t.datetime "updated_at"
21
- end
22
-
23
- end
@@ -1,7 +0,0 @@
1
- # This file should contain all the record creation needed to seed the database with its default values.
2
- # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
3
- #
4
- # Examples:
5
- #
6
- # cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
7
- # Mayor.create(:name => 'Daley', :city => cities.first)
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
-
4
- APP_PATH = File.expand_path('../../config/application', __FILE__)
5
- require File.expand_path('../../config/boot', __FILE__)
6
- require 'rails/commands'
@@ -1,22 +0,0 @@
1
- if Undo::RUNNING_ON_CI
2
- require 'coveralls'
3
- Coveralls.wear!
4
- else
5
- require 'pry'
6
- end
7
-
8
- ENV['RAILS_ENV'] ||= 'test'
9
-
10
- require File.expand_path('../rails_app/config/environment', __FILE__)
11
- require 'rspec'
12
- require_relative 'factories'
13
-
14
- ActiveRecord::Migration.verbose = false
15
- ActiveRecord::Migrator.migrate(Rails.root.join('db', 'migrate').to_s)
16
-
17
- RSpec.configure do |config|
18
- config.mock_with :rspec do |config|
19
- config.syntax = [:expect, :should]
20
- end
21
- config.include FactoryGirl::Syntax::Methods
22
- end
@@ -1,19 +0,0 @@
1
- require "spec_helper_lite"
2
- require "undo/serializer/simple"
3
-
4
- describe Undo::Serializer::Simple do
5
- subject { described_class }
6
- let(:serializer) { described_class.new }
7
-
8
- it "serializes to json" do
9
- object = { "hello" => "world" }
10
- result = serializer.to_json object
11
- expect(result).to eq '{"hello":"world"}'
12
- end
13
-
14
- it "deserializes from json" do
15
- serialized_object = '{"hello":"world"}'
16
- result = serializer.load_from_json serialized_object
17
- expect(result).to eq "hello" => "world"
18
- end
19
- end