lassebunk / dish Goto Github PK
View Code? Open in Web Editor NEWSuper simple conversion of hashes into plain Ruby objects. Also works in RubyMotion.
License: MIT License
Super simple conversion of hashes into plain Ruby objects. Also works in RubyMotion.
License: MIT License
It seems a little silly that you can't set a key on a dish plate object.
On a Product
model, calling description
returns:
"#<Product:0xd8bbfd0>"
Using in RubyMotion
How would I do this? Is it possible to do that or do I have to use the Dish(Hash) syntax?
What everyone's opinion on this? User configurable, default option, etc.?
#key_name=
methods. (This modified the original has ATM)#methods
(underscored like about, but could be changed).#to_json
which is useful when marshaling and unmarshaling to/from HTTP responses.#to_h
instead of #as_hash
(provide an alias for compat.)See the original file used in an API client here.
Right now we don't have any tests for the project in RubyMotion.
Anybody have ideas on how to automatically test the project with RubyMotion?
Thanks.
Hey there, I'm using Dish in RubyMotion and I really love it! Thanks so much for creating this library and making it compatible with RM!
Question about getting a reference to an object's parent...
I have:
{
id: 12,
items: [{
name: "test1"
},{
name: "test2"
}]
}
Defined by:
class Order < Dish::Plate
coerce :items, Item
end
class Item < Dish::Plate
end
Is there a way to get an item's parent (Order
) id?
# my_item is an Item
my_item.parent # Order object
my_item.parent.id # 12
Or if not, is there perhaps a way to set a weakref to the parent when initializing the objects?
class Order < Dish::Plate
# Something like this?
coerce :items, ->(value) { Item.new(value, self) }
end
class Item < Dish::Plate
def initialize(hash, parent)
super
@parent = WeafRef.new(parent)
end
end
Any ideas? Thanks again for the great library!
Why has the Dish::Plate#to_json
method been merged into 99ac61a?
It is quite complex and even contains platform specific dependencies (NSJSONSerialization
). So let the user decide how he/she wants to use to_json
. Any thoughts?
Furthermore it's not covered by any tests.
Dish causes behavioral difference on Object#try
require 'dish'
dish = Dish({a:1,b:2})
=> #<Dish::Plate:0x007fcfc2c99070 @_original_hash={"a"=>1, "b"=>2}>
dish.a
=> 1
dish.try(:a)
=> nil
I haven't read the source, but is this expected? Workarounds?
When attempting to use Dish with ActiveModel::Model includes it fails because initialize requires the first parameter as a hash, I feel it should be defaulted to hash = {}
.
Code: https://github.com/lassebunk/dish/blob/master/lib/dish/plate.rb#L13
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.