active_record-serializable 1.0.0
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/.coveralls.yml +1 -0
- data/.github/workflows/ci.yml +37 -0
- data/.gitignore +9 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +85 -0
- data/Rakefile +26 -0
- data/active_record-serializable.gemspec +34 -0
- data/lib/active_record/serializable/version.rb +5 -0
- data/lib/active_record/serializable.rb +108 -0
- data/lib/active_record-serializable.rb +1 -0
- data/spec/coverage_helper.rb +5 -0
- data/spec/minitest_helper.rb +82 -0
- data/spec/serializable_spec.rb +135 -0
- metadata +238 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2f2d3ceb6cb1564b74ee7de4b8ad2b1e7e4f255c875137f39ddb51db1b57b18c
|
4
|
+
data.tar.gz: 4fc099d7f01321420a571caba177b266b05cc51c8f4fc311ed3a2d2df0a54943
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b3e38484b5dcc5f4bed5c90b446a8f10c5e2628004529e6b08240445c798d26fc4fda058f48c1e936ebe658c695bd66f5aae38e830154e73c5fe9ccf6a860000
|
7
|
+
data.tar.gz: dd3ef9c833f52e23ea94fa4dce0e7dad0e4663587c1b38c9fb8fff7478effd5fe889244cde40ce871025179aa87ac3ddef3d8e97f3595d5eb02d82ff3e75a513
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
repo_token: Mitw1kAsG7lecWa9euqRGcCi2A97cmqIV
|
@@ -0,0 +1,37 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ '**' ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ '**' ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
|
12
|
+
name: Tests
|
13
|
+
runs-on: ubuntu-latest
|
14
|
+
|
15
|
+
services:
|
16
|
+
postgres:
|
17
|
+
image: postgres:11.13-alpine
|
18
|
+
env:
|
19
|
+
POSTGRES_PASSWORD: password
|
20
|
+
POSTGRES_USER: postgres
|
21
|
+
ports:
|
22
|
+
- 5432:5432
|
23
|
+
|
24
|
+
strategy:
|
25
|
+
fail-fast: false
|
26
|
+
matrix:
|
27
|
+
ruby-version: ['2.4', '2.5', '2.6', '2.7']
|
28
|
+
|
29
|
+
steps:
|
30
|
+
- uses: actions/checkout@v3
|
31
|
+
- name: Set up Ruby
|
32
|
+
uses: ruby/setup-ruby@v1
|
33
|
+
with:
|
34
|
+
ruby-version: ${{ matrix.ruby-version }}
|
35
|
+
bundler-cache: true
|
36
|
+
- name: Run tests
|
37
|
+
run: bundle exec rake
|
data/.gitignore
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
active_record-serializable
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.3.0
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 Gabriel Naiman
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
# ActiveRecord::Serializable
|
2
|
+
|
3
|
+
[](https://rubygems.org/gems/active_record-serializable)
|
4
|
+
[](https://github.com/gabynaiman/active_record-serializable/actions/workflows/ci.yml)
|
5
|
+
[](https://coveralls.io/github/gabynaiman/active_record-serializable?branch=master)
|
6
|
+
[](https://codeclimate.com/github/gabynaiman/active_record-serializable)
|
7
|
+
|
8
|
+
Extension for ActiveRecord to get serializable and marshalizable models using Rasti::Model
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'active_record-serializable'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install active_record-serializable
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
class User < ActiveRecord::Base
|
30
|
+
has_one :avatar
|
31
|
+
has_many :posts
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
### Basic
|
36
|
+
```ruby
|
37
|
+
user = User.find 1
|
38
|
+
user.to_serializable # ActiveRecord::Serializable::USER[id: 1, ...]
|
39
|
+
```
|
40
|
+
|
41
|
+
### Include relations
|
42
|
+
```ruby
|
43
|
+
user = User.find 1
|
44
|
+
user.to_serializable include: [:avatar, :posts] # ActiveRecord::Serializable::USER[id: 1, avatar: ActiveRecord::Serializable::AVATAR[...], posts: [ActiveRecord::Serializable::POST[...]]]
|
45
|
+
```
|
46
|
+
|
47
|
+
### Extended with methods
|
48
|
+
```ruby
|
49
|
+
class User < ActiveRecord::Base
|
50
|
+
serializable_define_method :sorted_post_titles do
|
51
|
+
posts.map(&:title).sort
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
user = User.find 1
|
56
|
+
serializable = user.to_serializable(include: [:posts])
|
57
|
+
serializable.sorted_post_titles # ['Title 1', ...]
|
58
|
+
```
|
59
|
+
|
60
|
+
### Extended with modules
|
61
|
+
```ruby
|
62
|
+
module Helper
|
63
|
+
def sorted_post_titles
|
64
|
+
posts.map(&:title).sort
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
class User < ActiveRecord::Base
|
69
|
+
serializable_include Helper
|
70
|
+
end
|
71
|
+
|
72
|
+
user = User.find 1
|
73
|
+
serializable = user.to_serializable(include: [:posts])
|
74
|
+
serializable.sorted_post_titles # ['Title 1', ...]
|
75
|
+
```
|
76
|
+
|
77
|
+
## Contributing
|
78
|
+
|
79
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/gabynaiman/active_record-serializable.
|
80
|
+
|
81
|
+
|
82
|
+
## License
|
83
|
+
|
84
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
85
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rake/testtask'
|
3
|
+
|
4
|
+
Rake::TestTask.new(:spec) do |t|
|
5
|
+
t.libs << 'spec'
|
6
|
+
t.libs << 'lib'
|
7
|
+
t.pattern = ENV['DIR'] ? File.join(ENV['DIR'], '**', '*_spec.rb') : 'spec/**/*_spec.rb'
|
8
|
+
t.verbose = false
|
9
|
+
t.warning = false
|
10
|
+
t.loader = nil if ENV['TEST']
|
11
|
+
ENV['TEST'], ENV['LINE'] = ENV['TEST'].split(':') if ENV['TEST'] && !ENV['LINE']
|
12
|
+
t.options = ''
|
13
|
+
t.options << "--name=/#{ENV['NAME']}/ " if ENV['NAME']
|
14
|
+
t.options << "-l #{ENV['LINE']} " if ENV['LINE'] && ENV['TEST']
|
15
|
+
t.ruby_opts << '-W0'
|
16
|
+
end
|
17
|
+
|
18
|
+
task default: :spec
|
19
|
+
|
20
|
+
desc 'Pry console'
|
21
|
+
task :console do
|
22
|
+
require 'active_record-serializable'
|
23
|
+
require 'pry'
|
24
|
+
ARGV.clear
|
25
|
+
Pry.start
|
26
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'active_record/serializable/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'active_record-serializable'
|
8
|
+
spec.version = ActiveRecord::Serializable::VERSION
|
9
|
+
spec.authors = ['Gabriel Naiman']
|
10
|
+
spec.email = ['gabynaiman@gmail.com']
|
11
|
+
spec.summary = 'Extension for ActiveRecord to get serializable and marshalizable models using Rasti::Model'
|
12
|
+
spec.description = 'Extension for ActiveRecord to get serializable and marshalizable models using Rasti::Model'
|
13
|
+
spec.homepage = 'https://github.com/gabynaiman/active_record-serializable'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'activerecord', '~> 4.0'
|
22
|
+
spec.add_development_dependency 'activesupport', '~> 4.0'
|
23
|
+
spec.add_development_dependency 'rasti-model', '~> 2.0'
|
24
|
+
spec.add_development_dependency 'bigdecimal', '~> 1.0'
|
25
|
+
|
26
|
+
spec.add_development_dependency 'sqlite3', '~> 1.3.6'
|
27
|
+
spec.add_development_dependency 'rake', '~> 12.3'
|
28
|
+
spec.add_development_dependency 'minitest', '~> 5.0', '< 5.11'
|
29
|
+
spec.add_development_dependency 'minitest-colorin', '~> 0.1'
|
30
|
+
spec.add_development_dependency 'minitest-line', '~> 0.6'
|
31
|
+
spec.add_development_dependency 'simplecov', '~> 0.12'
|
32
|
+
spec.add_development_dependency 'coveralls', '~> 0.8'
|
33
|
+
spec.add_development_dependency 'pry-nav', '~> 0.2'
|
34
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
require 'active_support/core_ext/marshal'
|
3
|
+
require 'rasti-model'
|
4
|
+
|
5
|
+
require_relative 'serializable/version'
|
6
|
+
|
7
|
+
module ActiveRecord
|
8
|
+
module Serializable
|
9
|
+
|
10
|
+
class << self
|
11
|
+
|
12
|
+
def create_for(active_record_class)
|
13
|
+
const_name = const_name_for active_record_class
|
14
|
+
|
15
|
+
return const_get const_name if const_defined? const_name
|
16
|
+
|
17
|
+
attribute_names = active_record_class.attribute_names.map(&:to_sym)
|
18
|
+
|
19
|
+
Rasti::Model[*attribute_names].tap do |serializable_class|
|
20
|
+
serializable_class.instance_eval do
|
21
|
+
active_record_class.reflections.each do |name, relation|
|
22
|
+
cast_method_name = "cast_#{name}".to_sym
|
23
|
+
attribute name.to_sym, cast_method_name
|
24
|
+
|
25
|
+
define_method cast_method_name do |value|
|
26
|
+
base_type = Rasti::Types::Model[relation.klass.serializable_class]
|
27
|
+
type = relation.collection? ? Rasti::Types::Array[base_type] : base_type
|
28
|
+
type.cast value
|
29
|
+
end
|
30
|
+
|
31
|
+
private cast_method_name
|
32
|
+
end
|
33
|
+
|
34
|
+
active_record_class.serializable_included_modules.each do |mod|
|
35
|
+
include mod
|
36
|
+
end
|
37
|
+
|
38
|
+
active_record_class.serializable_defined_methods.each do |name, block|
|
39
|
+
define_method(name, &block)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
const_set const_name, serializable_class
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def const_missing(const_name)
|
48
|
+
active_record_class_name = active_record_class_name_for const_name
|
49
|
+
if Object.const_defined? active_record_class_name
|
50
|
+
Object.const_get(active_record_class_name).serializable_class
|
51
|
+
else
|
52
|
+
super const_name
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def const_name_for(active_record_class)
|
59
|
+
Inflecto.underscore(active_record_class.name).gsub('/', '__').upcase
|
60
|
+
end
|
61
|
+
|
62
|
+
def active_record_class_name_for(const_name)
|
63
|
+
Inflecto.camelize(const_name.to_s.downcase.gsub('__', '/'))
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
module ClassMethods
|
69
|
+
|
70
|
+
def serializable_class
|
71
|
+
@serializable_class ||= Serializable.create_for self
|
72
|
+
end
|
73
|
+
|
74
|
+
def serializable_included_modules
|
75
|
+
@serializable_included_modules ||= Set.new
|
76
|
+
end
|
77
|
+
|
78
|
+
def serializable_include(*modules)
|
79
|
+
modules.each { |m| serializable_included_modules << m }
|
80
|
+
end
|
81
|
+
|
82
|
+
def serializable_defined_methods
|
83
|
+
@serializable_defined_methods ||= {}
|
84
|
+
end
|
85
|
+
|
86
|
+
def serializable_define_method(name, &block)
|
87
|
+
serializable_defined_methods[name] = block
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
module InstanceMethods
|
93
|
+
|
94
|
+
def to_serializable(*args)
|
95
|
+
hash = as_json(*args)
|
96
|
+
self.class.serializable_class.new hash
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
Base.instance_eval do
|
104
|
+
extend Serializable::ClassMethods
|
105
|
+
include Serializable::InstanceMethods
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require_relative 'active_record/serializable'
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'coverage_helper'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'minitest/colorin'
|
4
|
+
require 'minitest/line/describe_track'
|
5
|
+
require 'pry-nav'
|
6
|
+
require 'active_record'
|
7
|
+
require 'active_record-serializable'
|
8
|
+
|
9
|
+
module AuthorHelper
|
10
|
+
def author
|
11
|
+
user.name
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class User < ActiveRecord::Base
|
16
|
+
has_one :avatar
|
17
|
+
has_many :posts
|
18
|
+
has_and_belongs_to_many :groups
|
19
|
+
|
20
|
+
serializable_define_method :hi do
|
21
|
+
"Hi, my name is #{name}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class Avatar < ActiveRecord::Base
|
26
|
+
belongs_to :user
|
27
|
+
end
|
28
|
+
|
29
|
+
class Post < ActiveRecord::Base
|
30
|
+
belongs_to :user
|
31
|
+
has_many :comments
|
32
|
+
serializable_include AuthorHelper
|
33
|
+
end
|
34
|
+
|
35
|
+
class Comment < ActiveRecord::Base
|
36
|
+
belongs_to :post
|
37
|
+
end
|
38
|
+
|
39
|
+
class Group < ActiveRecord::Base
|
40
|
+
has_and_belongs_to_many :users
|
41
|
+
end
|
42
|
+
|
43
|
+
class Minitest::Spec
|
44
|
+
|
45
|
+
def setup
|
46
|
+
ActiveRecord::Base.establish_connection adapter: :sqlite3, database: ':memory:'
|
47
|
+
|
48
|
+
ActiveRecord::Schema.define do
|
49
|
+
self.verbose = false
|
50
|
+
|
51
|
+
create_table :users do |t|
|
52
|
+
t.string :name
|
53
|
+
end
|
54
|
+
|
55
|
+
create_table :avatars do |t|
|
56
|
+
t.belongs_to :user
|
57
|
+
t.string :image_url
|
58
|
+
end
|
59
|
+
|
60
|
+
create_table :posts do |t|
|
61
|
+
t.belongs_to :user
|
62
|
+
t.string :title
|
63
|
+
t.string :body
|
64
|
+
end
|
65
|
+
|
66
|
+
create_table :comments do |t|
|
67
|
+
t.belongs_to :post
|
68
|
+
t.string :text
|
69
|
+
end
|
70
|
+
|
71
|
+
create_table :groups do |t|
|
72
|
+
t.string :name
|
73
|
+
end
|
74
|
+
|
75
|
+
create_table :groups_users do |t|
|
76
|
+
t.belongs_to :group
|
77
|
+
t.belongs_to :user
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
require 'minitest_helper'
|
2
|
+
|
3
|
+
describe ActiveRecord::Serializable do
|
4
|
+
|
5
|
+
before do
|
6
|
+
1.upto(4) do |i|
|
7
|
+
Group.create! name: "Group #{i}"
|
8
|
+
end
|
9
|
+
|
10
|
+
1.upto(3) do |i|
|
11
|
+
user = User.create! name: "User #{i}",
|
12
|
+
groups: Group.all.shuffle.take(2)
|
13
|
+
|
14
|
+
Avatar.create! user_id: user.id,
|
15
|
+
image_url: "http://www.avatar.com/#{i}"
|
16
|
+
|
17
|
+
1.upto(2) do |j|
|
18
|
+
Post.create! user_id: user.id,
|
19
|
+
title: "Post ##{j}",
|
20
|
+
body: 'This is an example'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'Serialize' do
|
26
|
+
|
27
|
+
it 'Without relations' do
|
28
|
+
user = User.first
|
29
|
+
|
30
|
+
expected_user = User.serializable_class.new id: user.id,
|
31
|
+
name: user.name
|
32
|
+
|
33
|
+
assert_equal expected_user, user.to_serializable
|
34
|
+
end
|
35
|
+
|
36
|
+
describe 'With relations' do
|
37
|
+
|
38
|
+
it 'Belongs to' do
|
39
|
+
avatar = Avatar.first
|
40
|
+
|
41
|
+
expected_avatar = Avatar.serializable_class.new id: avatar.id,
|
42
|
+
image_url: avatar.image_url,
|
43
|
+
user_id: avatar.user_id,
|
44
|
+
user: avatar.user.to_serializable
|
45
|
+
|
46
|
+
assert_equal expected_avatar, avatar.to_serializable(include: [:user])
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'Has one' do
|
50
|
+
user = User.first
|
51
|
+
|
52
|
+
expected_user = User.serializable_class.new id: user.id,
|
53
|
+
name: user.name,
|
54
|
+
avatar: user.avatar.to_serializable
|
55
|
+
|
56
|
+
assert_equal expected_user, user.to_serializable(include: [:avatar])
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'Has many' do
|
60
|
+
user = User.first
|
61
|
+
|
62
|
+
expected_user = User.serializable_class.new id: user.id,
|
63
|
+
name: user.name,
|
64
|
+
posts: user.posts.map(&:to_serializable)
|
65
|
+
|
66
|
+
assert_equal expected_user, user.to_serializable(include: [:posts])
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'Has and belongs to many' do
|
70
|
+
user = User.first
|
71
|
+
|
72
|
+
expected_user = User.serializable_class.new id: user.id,
|
73
|
+
name: user.name,
|
74
|
+
groups: user.groups.map(&:to_serializable)
|
75
|
+
|
76
|
+
assert_equal expected_user, user.to_serializable(include: [:groups])
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
describe 'Extensible' do
|
84
|
+
|
85
|
+
it 'Include module' do
|
86
|
+
post = Post.first
|
87
|
+
|
88
|
+
serializable = post.to_serializable(include: [:user])
|
89
|
+
|
90
|
+
assert_equal post.user.name, serializable.author
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'Define method' do
|
94
|
+
user = User.first
|
95
|
+
|
96
|
+
serializable = user.to_serializable
|
97
|
+
|
98
|
+
assert_equal "Hi, my name is #{user.name}", serializable.hi
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
describe 'Marshalizable' do
|
104
|
+
|
105
|
+
it 'Dump' do
|
106
|
+
user = User.first
|
107
|
+
|
108
|
+
expected_dump = "\x04\bo:%ActiveRecord::Serializable::USER\x06:\x14@__attributes__{\aI\"\aid\x06:\x06ETi\x06I\"\tname\x06;\aTI\"\vUser 1\x06;\aT"
|
109
|
+
|
110
|
+
assert_equal expected_dump, Marshal.dump(user.to_serializable)
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'Load' do
|
114
|
+
dump = "\x04\bo:(ActiveRecord::Serializable::COMMENT\x06:\x14@__attributes__{\b:\aidi\x06:\fpost_idi\x06:\ttextI\"\x15I like this post\x06:\x06ET"
|
115
|
+
|
116
|
+
comment = Marshal.load dump
|
117
|
+
|
118
|
+
expected_comment = Comment.serializable_class.new id: 1,
|
119
|
+
post_id: 1,
|
120
|
+
text: 'I like this post'
|
121
|
+
|
122
|
+
assert_equal expected_comment, comment
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'Load error' do
|
126
|
+
dump = "\x04\bo:'ActiveRecord::Serializable::PERSON\x06:\x14@__attributes__{\a:\aidi\x06:\tnameI\"\rPerson 1\x06:\x06ET"
|
127
|
+
|
128
|
+
assert_raises(NameError, 'uninitialized constant ActiveRecord::Serializable::PERSON') do
|
129
|
+
Marshal.load dump
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
metadata
ADDED
@@ -0,0 +1,238 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: active_record-serializable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gabriel Naiman
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-03-21 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: '4.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rasti-model
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bigdecimal
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.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: 1.3.6
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.3.6
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '12.3'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '12.3'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: minitest
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '5.0'
|
104
|
+
- - "<"
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '5.11'
|
107
|
+
type: :development
|
108
|
+
prerelease: false
|
109
|
+
version_requirements: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - "~>"
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '5.0'
|
114
|
+
- - "<"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '5.11'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: minitest-colorin
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - "~>"
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0.1'
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - "~>"
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0.1'
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: minitest-line
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - "~>"
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0.6'
|
138
|
+
type: :development
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - "~>"
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0.6'
|
145
|
+
- !ruby/object:Gem::Dependency
|
146
|
+
name: simplecov
|
147
|
+
requirement: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - "~>"
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0.12'
|
152
|
+
type: :development
|
153
|
+
prerelease: false
|
154
|
+
version_requirements: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - "~>"
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0.12'
|
159
|
+
- !ruby/object:Gem::Dependency
|
160
|
+
name: coveralls
|
161
|
+
requirement: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - "~>"
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0.8'
|
166
|
+
type: :development
|
167
|
+
prerelease: false
|
168
|
+
version_requirements: !ruby/object:Gem::Requirement
|
169
|
+
requirements:
|
170
|
+
- - "~>"
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: '0.8'
|
173
|
+
- !ruby/object:Gem::Dependency
|
174
|
+
name: pry-nav
|
175
|
+
requirement: !ruby/object:Gem::Requirement
|
176
|
+
requirements:
|
177
|
+
- - "~>"
|
178
|
+
- !ruby/object:Gem::Version
|
179
|
+
version: '0.2'
|
180
|
+
type: :development
|
181
|
+
prerelease: false
|
182
|
+
version_requirements: !ruby/object:Gem::Requirement
|
183
|
+
requirements:
|
184
|
+
- - "~>"
|
185
|
+
- !ruby/object:Gem::Version
|
186
|
+
version: '0.2'
|
187
|
+
description: Extension for ActiveRecord to get serializable and marshalizable models
|
188
|
+
using Rasti::Model
|
189
|
+
email:
|
190
|
+
- gabynaiman@gmail.com
|
191
|
+
executables: []
|
192
|
+
extensions: []
|
193
|
+
extra_rdoc_files: []
|
194
|
+
files:
|
195
|
+
- ".coveralls.yml"
|
196
|
+
- ".github/workflows/ci.yml"
|
197
|
+
- ".gitignore"
|
198
|
+
- ".ruby-gemset"
|
199
|
+
- ".ruby-version"
|
200
|
+
- Gemfile
|
201
|
+
- LICENSE.txt
|
202
|
+
- README.md
|
203
|
+
- Rakefile
|
204
|
+
- active_record-serializable.gemspec
|
205
|
+
- lib/active_record-serializable.rb
|
206
|
+
- lib/active_record/serializable.rb
|
207
|
+
- lib/active_record/serializable/version.rb
|
208
|
+
- spec/coverage_helper.rb
|
209
|
+
- spec/minitest_helper.rb
|
210
|
+
- spec/serializable_spec.rb
|
211
|
+
homepage: https://github.com/gabynaiman/active_record-serializable
|
212
|
+
licenses:
|
213
|
+
- MIT
|
214
|
+
metadata: {}
|
215
|
+
post_install_message:
|
216
|
+
rdoc_options: []
|
217
|
+
require_paths:
|
218
|
+
- lib
|
219
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
220
|
+
requirements:
|
221
|
+
- - ">="
|
222
|
+
- !ruby/object:Gem::Version
|
223
|
+
version: '0'
|
224
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
225
|
+
requirements:
|
226
|
+
- - ">="
|
227
|
+
- !ruby/object:Gem::Version
|
228
|
+
version: '0'
|
229
|
+
requirements: []
|
230
|
+
rubygems_version: 3.3.14
|
231
|
+
signing_key:
|
232
|
+
specification_version: 4
|
233
|
+
summary: Extension for ActiveRecord to get serializable and marshalizable models using
|
234
|
+
Rasti::Model
|
235
|
+
test_files:
|
236
|
+
- spec/coverage_helper.rb
|
237
|
+
- spec/minitest_helper.rb
|
238
|
+
- spec/serializable_spec.rb
|