not_yet_active_record 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +48 -0
- data/Rakefile +1 -0
- data/lib/generators/not_yet_active_record/not_yet_active_record_generator.rb +27 -0
- data/lib/generators/not_yet_active_record/templates/schema.rb +14 -0
- data/lib/generators/not_yet_active_record/templates/unsaved_object.rb +3 -0
- data/lib/not_yet_active_record/version.rb +3 -0
- data/lib/not_yet_active_record.rb +45 -0
- data/not_yet_active_record.gemspec +27 -0
- data/spec/lib/not_yet_active_record_spec.rb +56 -0
- data/spec/not_yet.sqlite3 +0 -0
- data/spec/spec_helper.rb +8 -0
- data/spec/support/data.rb +2 -0
- data/spec/support/models.rb +5 -0
- data/spec/support/schema.rb +15 -0
- metadata +152 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f6af89a34d5534b2850ce6e25561e78df512b965
|
4
|
+
data.tar.gz: 4a37ed76f037d9641e46d8260cc36184ee2df4b5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 61039c5655ce6699f76d67887c8f2fa420836cbb6adbb50fe2fb21152758703df766185e63f61d5e875db0ae72d303e4d868ed2f0ea20bd46b650ebabdb18afc
|
7
|
+
data.tar.gz: 1042b1a0bdedaa41134563500531161fb6f1f27861c468a5312c53455614575fdba0adfe21bf176e1be20c10d8769bfa9fc1bb7fd52e214ba1f5a974837656cd
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Adam Frey
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# Not Yet Active Record
|
2
|
+
*"We take the 'Active' out of Active Record"*
|
3
|
+
|
4
|
+
Not Yet Active Record is an extension to Active Record that allows any Active
|
5
|
+
Record object to be persisted in a serialized state in one separate table in
|
6
|
+
the database. The objects can be pulled from the database and deserialized at
|
7
|
+
any later time to save into the database.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
gem install not_yet_active_record
|
12
|
+
|
13
|
+
After installing the gem run
|
14
|
+
|
15
|
+
rails generate not_yet_active_record
|
16
|
+
rake db:migrate
|
17
|
+
|
18
|
+
to create the UnsavedObject model and table.
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
Send any Active Record object to the UnsavedObject table with the
|
23
|
+
`not_yet_save` method:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
@post.not_yet_save
|
27
|
+
```
|
28
|
+
|
29
|
+
|
30
|
+
Get an array of any unsaved objects of a particular class with:
|
31
|
+
```ruby
|
32
|
+
Post.not_yet_saved
|
33
|
+
```
|
34
|
+
|
35
|
+
A copy of the original object can be deserialized from an UnsavedObject
|
36
|
+
model with the item method:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
@unsaved_obj.item
|
40
|
+
```
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
1. Fork it
|
45
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
46
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
47
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
48
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
|
4
|
+
module NotYetActiveRecord
|
5
|
+
class NotYetActiveRecordGenerator < Rails::Generators::Base
|
6
|
+
include Rails::Generators::Migration
|
7
|
+
|
8
|
+
def self.source_root
|
9
|
+
File.expand_path("../templates",__FILE__)
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_model
|
13
|
+
generate "model UnsavedObject serialized_item:text model_name:string"
|
14
|
+
end
|
15
|
+
|
16
|
+
# def create_migration_file
|
17
|
+
# copy_file 'schema.rb',
|
18
|
+
# "db/migrate/#{Time.now.utc.strftime("%Y%m%d%H%M%S")}_unsaved_objects.rb"
|
19
|
+
# end
|
20
|
+
|
21
|
+
# def create_model
|
22
|
+
# copy_file 'unsaved_object.rb', "app/models/unsaved_object.rb"
|
23
|
+
# end
|
24
|
+
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class CreateNotYetActiveRecords < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
create_table :not_yet_active_records do |t|
|
4
|
+
t.text :serialized_item
|
5
|
+
t.string :model_name
|
6
|
+
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def down
|
12
|
+
drop_table :not_yet_active_records
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "not_yet_active_record/version"
|
2
|
+
require 'active_record'
|
3
|
+
|
4
|
+
module NotYetActiveRecord
|
5
|
+
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def not_yet_saved
|
9
|
+
unsaved_array = []
|
10
|
+
UnsavedObject.find_all_by_model_name(self.name).each do |unsaved|
|
11
|
+
unsaved_array << unsaved.item
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module InstanceMethods
|
17
|
+
def not_yet_save
|
18
|
+
att_hash = self.attributes
|
19
|
+
unsaved = UnsavedObject.new()
|
20
|
+
unsaved.serialized_item = att_hash.to_yaml
|
21
|
+
unsaved.model_name = self.class.name
|
22
|
+
unsaved.save!
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.included(base)
|
27
|
+
base.send :include, InstanceMethods
|
28
|
+
base.send :extend, ClassMethods
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
class ActiveRecord::Base
|
34
|
+
include NotYetActiveRecord
|
35
|
+
end
|
36
|
+
|
37
|
+
class UnsavedObject < ActiveRecord::Base
|
38
|
+
def item
|
39
|
+
att_hash = YAML::load(serialized_item)
|
40
|
+
att_hash.delete("id")
|
41
|
+
att_hash.delete("created_at")
|
42
|
+
att_hash.delete("updated_at")
|
43
|
+
model_name.constantize.new(att_hash)
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'not_yet_active_record/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.add_dependency "activerecord"
|
8
|
+
spec.name = "not_yet_active_record"
|
9
|
+
spec.version = NotYetActiveRecord::VERSION
|
10
|
+
spec.authors = ["Adam Frey"]
|
11
|
+
spec.email = ["adamparkerfrey@gmail.com"]
|
12
|
+
spec.description = %q{Put off saving Active Record Objects until later.}
|
13
|
+
spec.summary = %q{Defers the saving of Active Record objects by persisting in a serialized format}
|
14
|
+
spec.homepage = "http://github.com/adamfrey/not_yet_active_record"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files`.split($/)
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
spec.add_development_dependency "rspec"
|
25
|
+
spec.add_development_dependency "sqlite3"
|
26
|
+
spec.add_development_dependency "activerecord"
|
27
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "ActiveRecord instance" do
|
4
|
+
post = Post.first
|
5
|
+
it "should respond to not_yet" do
|
6
|
+
post.should respond_to(:not_yet_save)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should be saved as an unsaved object" do
|
10
|
+
before = UnsavedObject.count
|
11
|
+
post.not_yet_save
|
12
|
+
after = UnsavedObject.count
|
13
|
+
before.should == after-1
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "ActiveRecord class" do
|
18
|
+
before(:each) do
|
19
|
+
@post = Post.first
|
20
|
+
@post.not_yet_save
|
21
|
+
@unsaved = UnsavedObject.last
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should respond to not_yet_saved" do
|
25
|
+
Post.should respond_to(:not_yet_saved)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should return an array when not_yet_saved is called" do
|
29
|
+
Post.not_yet_saved.should be_an_instance_of(Array)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "UnsavedObject instance" do
|
34
|
+
before(:each) do
|
35
|
+
@post = Post.first
|
36
|
+
@post.not_yet_save
|
37
|
+
@unsaved = UnsavedObject.last
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should respond to item" do
|
41
|
+
@unsaved.should respond_to(:item)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should have the correct attribute model_name" do
|
45
|
+
@post.class.name.should == @unsaved.model_name
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should recreate a post object" do
|
49
|
+
@unsaved.item.class.name.should == @post.class.name
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should have the same attributes as the original object" do
|
53
|
+
@unsaved.item.text.should == @post.text
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
Binary file
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
require 'not_yet_active_record'
|
2
|
+
|
3
|
+
ActiveRecord::Base.establish_connection(adapter: "sqlite3",
|
4
|
+
database:
|
5
|
+
File.dirname(__FILE__) + "/not_yet.sqlite3")
|
6
|
+
load File.dirname(__FILE__) + '/support/schema.rb'
|
7
|
+
load File.dirname(__FILE__) + '/support/models.rb'
|
8
|
+
load File.dirname(__FILE__) + '/support/data.rb'
|
@@ -0,0 +1,15 @@
|
|
1
|
+
ActiveRecord::Schema.define do
|
2
|
+
self.verbose = false
|
3
|
+
|
4
|
+
create_table :posts, force: true do |t|
|
5
|
+
t.string :text
|
6
|
+
t.timestamps
|
7
|
+
end
|
8
|
+
|
9
|
+
# create_table :unsaved_objects do |t|
|
10
|
+
# t.text :serialized_item
|
11
|
+
# t.string :model_name
|
12
|
+
|
13
|
+
# t.timestamps
|
14
|
+
# end
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: not_yet_active_record
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adam Frey
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-04-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sqlite3
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: activerecord
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Put off saving Active Record Objects until later.
|
98
|
+
email:
|
99
|
+
- adamparkerfrey@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- .gitignore
|
105
|
+
- Gemfile
|
106
|
+
- LICENSE.txt
|
107
|
+
- README.md
|
108
|
+
- Rakefile
|
109
|
+
- lib/generators/not_yet_active_record/not_yet_active_record_generator.rb
|
110
|
+
- lib/generators/not_yet_active_record/templates/schema.rb
|
111
|
+
- lib/generators/not_yet_active_record/templates/unsaved_object.rb
|
112
|
+
- lib/not_yet_active_record.rb
|
113
|
+
- lib/not_yet_active_record/version.rb
|
114
|
+
- not_yet_active_record.gemspec
|
115
|
+
- spec/lib/not_yet_active_record_spec.rb
|
116
|
+
- spec/not_yet.sqlite3
|
117
|
+
- spec/spec_helper.rb
|
118
|
+
- spec/support/data.rb
|
119
|
+
- spec/support/models.rb
|
120
|
+
- spec/support/schema.rb
|
121
|
+
homepage: http://github.com/adamfrey/not_yet_active_record
|
122
|
+
licenses:
|
123
|
+
- MIT
|
124
|
+
metadata: {}
|
125
|
+
post_install_message:
|
126
|
+
rdoc_options: []
|
127
|
+
require_paths:
|
128
|
+
- lib
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
requirements: []
|
140
|
+
rubyforge_project:
|
141
|
+
rubygems_version: 2.0.0.rc.2
|
142
|
+
signing_key:
|
143
|
+
specification_version: 4
|
144
|
+
summary: Defers the saving of Active Record objects by persisting in a serialized
|
145
|
+
format
|
146
|
+
test_files:
|
147
|
+
- spec/lib/not_yet_active_record_spec.rb
|
148
|
+
- spec/not_yet.sqlite3
|
149
|
+
- spec/spec_helper.rb
|
150
|
+
- spec/support/data.rb
|
151
|
+
- spec/support/models.rb
|
152
|
+
- spec/support/schema.rb
|