Comments (9)
@ramontayag - With regard to the error @topherfangio reported. I work with him. Here is a failing spec. Just drop it into your storext_spec.rb
and run it.
it "can properly marshal" do
author = Author.new(name: "A. Clarke")
expect{Marshal.dump(author)}.to_not raise_exception(TypeError)
end
/edit Marshal.dump is used by memcache when you try to cache an object. So this use case is 'common' IMHO.
# this will fail.
Rails.cache.fetch("a_user") do
User.find(1)
end
Edit 2/ Docs on the Marshal.dump method https://ruby-doc.org/core-2.2.2/Marshal.html
from storext.
Ok that's right. Storext uses anonymous classes in which it defines Virtus attributes. The values go through an instance of that class and that instance that has Virtus does a lot of the typecasting/conversion. I'm not familiar with Marshal
and don't really understand what it means when it says it will dump descendant objects.
from storext.
The fix might be somewhere here where marshal_dump
and marshal_load
are defined.
from storext.
So, the issue lies here:
def storext_proxy_class
Storext.proxy_classes[self] ||= Class.new(*Storext.proxy_classes[self.superclass]) do
include Virtus.model
attribute :source
end
end
Marshal.dump
just doesn't know how to dump the Class.new
.
We were able to monkey patch this with the following code.
module Storext
module ClassMethods
class Dumpable
include Virtus.model
attribute :source
end
def storext_proxy_class
Storext.proxy_classes[self] ||= Dumpable
end
end
end
But I'm pretty sure this exists to cover cases of a parent class that uses Storext as well as it's child class using Storext, so this could easily break stuff for us later on down the road. Not sure if there is another workaround, but we couldn't figure out how to use the Marshal
methods to get it working.
from storext.
@gcrofils when writing, Storext just uses ActiveRecord::Store
underneath. Are you able to do what you want with ActiveRecord::Store
?
For example, if you create a stored attribute but the value is nil, what happens?
from storext.
I don't fully understand your question "Are you able to do what you want with ActiveRecord::Store
?".
In the previous example, if you remove Storext
(include
+ store_attributes
definition) from the class, without changing anything else. Marshal.dump
works.
Regarding the second part of your message:
Marshal.dump
fails if there is no value for an attribute with TypeError: can't dump anonymous class
.
It works in other cases, either if there is a default value (defined in store_attributes
) or a value set.
Hence if you try to Marshal.dump
a record with a stored attribute
that is nil
, it will fail if this attribute has no default value.
from storext.
Thanks. This'll be helpful. Mind writing a failing test case? I'll see what I can do :)
from storext.
Right now all tests are failing in Travis, but you should be able to run it locally. I'm currently trying to fix the tests in Travis.
from storext.
@seattlecyclist will #56 work for you?
from storext.
Related Issues (20)
- Default value based on another value? HOT 2
- `hash': wrong number of arguments (given 1, expected 0) (ArgumentError)
- Replace 'Virtus' with 'dry-types' for Coercion HOT 5
- Encrypt stored data HOT 4
- Any support for responding to Enums? HOT 2
- Use with Ransack HOT 2
- Update single attribute in hash column HOT 4
- Support namespace HOT 3
- Boolean type not recognized when using store_attributes inside concern HOT 4
- Empty string is converted to nil automatically HOT 3
- nested ActiveModel objects HOT 5
- 3.0.0 File permissions issue HOT 3
- define conditional attributes HOT 2
- Rails 6.0.0 Support HOT 1
- How do I manage validatations of attributes with Storext? HOT 2
- Audited gem HOT 2
- Support for Rails 6.1 HOT 3
- Using Github Actions instead of Travis?
- Rails 7 support HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from storext.