soveran / nest Goto Github PK
View Code? Open in Web Editor NEWGenerate nested namespaced keys for key-value databases.
License: MIT License
Generate nested namespaced keys for key-value databases.
License: MIT License
Activesupport overrides Object#to_json
so that it calls Object#as_json
. The latter however looks for to_hash
method and if not found just grabs all the instance variables. This leads to Nest.initialize('foo').to_json
returning a ton of garbage instead of a key, because it also appends @rc
The issue can be solved by adding Nest#to_json
explicitly so that it does to_s.to_json
for example
UPD: this won't work. The solutions are to add Nest#to_hash
or Nest#as_json
to return @ns
, both of which being kinda meh since it's not really a hash...
This is ok for a monkeypatch workaround though =)
I think Redic seem to be the better option. Per my experience, Redic doesn't yield issue when being wrapped inside an EventMachine block.
When creating a new nest, if a symbol is used instead of a string, it fails to coerce into string.
irb(main):001:0> Nest.new(:Foo)
TypeError: can't convert Symbol into String
from C:/Users/Luis/.bundle/ruby/1.8/gems/nest-0.0.4/lib/nest.rb:5:in `initialize'
Changing line 16 to key.to_s
workaround the issue.
I'm not sure where did I copy these extensions from, perhaps redis-ruby. These extensions let nest use hash directly. I find them very useful. Do you think we can add them to the gem?
Nest.class_eval do
def mapped_hmget(*fields)
Hash[**hmget(*fields)]
end
def mapped_hgetall
Hash[*hgetall]
end
def mapped_hmset(values)
hmset(*values.to_a.flatten)
end
end
I think the old interface is what make nest great. Instead of sterilze this to only "call" I think we'd better use method missing instead. The syntax error still propagate through RuntimeError exception What do you say?
A test app with ohm 3.1.1 and nest 3.1.0 (ruby 2.3.1p112) fails on Ohm::Model#find:
TypeError: can't convert Nest to Array (Nest#to_ary gives RuntimeError)
ohm-3.1.1/lib/ohm.rb:1480:in `flatten'
This may be related to an interaction between method_missing
and flatten
discussed here. I did not write tests, but cargo-culting the solution applied to bundler there also appeared to solve the problem for nest:
private
def to_ary
nil
end
Thanks!
I've just run into the issue on Ruby 1.8.6 where define_method doesn't recognize block arguments. You can read more here
I've tried every combo I can think of to patch this up and nothing really seems to work well. class_eval results in stack level too deep and I'm not sure how far down the rabbit hole I want to go on this one.
If you guys have any idea, I'd love to hear it. Obviously "use 1.8.7 or higher" is a valid answer ;)
nest.get is returning result of different redis query (like a redis set, or of different key) when running in thin.
When I switch from nest to the regular redis-rb, the issue go away.
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.