TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: Created my first Ruby Gem. How'd I do?

2 点作者 eatenbyagrue超过 15 年前
Last weekend I was working on a Rails project and realized that I was creating the same utility function for the third time in a row. In the spirit of DRY, I figured it was time to package it up into a gem that I could drop into any project.<p>The basic problem was creating a place to quickly and easily shove config values and application wide state. CONSTANTS in the environment work ok, but can't be modified by the run time. What I ultimately wanted was memcache, with persistence.<p>So I created the entity_store gem, which allows you to drop a persistent key/value store into any rails app in about 5 minutes. After initialization, you can use commands like:<p># Get key value.<p>e = EntityStore["testkey"]<p>e = EntityStore.testkey<p>e = EntityStore[:testkey]<p># sets key named 'happened' to a Time object of now<p>EntityStore[:happened] = Time.now<p>EntityStore["happened"] = Time.now<p>EntityStore.happened = Time.now<p>Everything syncs instantly with the database, so state is preserved even if the server goes down. Additionally, it allows you to initialize with some defaults for keys - which works great for getting initial state going on your app.<p>Overall, packaging up and publishing the gem in a decent state online took longer than actually writing the functionality. Talk about yak shaving! But it was fun... hope someone else finds it useful.<p>http://eatenbyagrue.github.com/entity_storage/<p>Any ideas for the next version would be greatly appreciated.

暂无评论

暂无评论