Git Product home page Git Product logo

metahash's Introduction

MetaHash

Provides a subclass of Hash and a wrapper around Rails' serialize attribute for object-like access to hashes without validating existence of nested hashes

Examples

Access nested hashes using method / object syntax

h = Metadata.new
h # => {}
h.outer.inner # => {}

Access to values stored in nested hashes via method call syntax

h = Metadata.new( { outer: { inner: { hash_key: "value" } } } )
h.outer.inner.hash_key # => "value"

Set values for nested hash structures without the nested hashes having to be initially defined

h = Metadata.new( {} )

Using with ActiveRecord

In your Gemfile

gem "metahash", github: "TinderBox/MetaHash"

in your ActiveRecord model

metadata_field_for :field_name

Support

This gem has been tested with Ruby 2.0, and rails 3.2

Contributing

  1. Fork the project
  2. Create a new, descriptively named branch
  3. Add Test(s)!
  4. Commit your proposed changes
  5. Submit a pull request

metahash's People

Contributors

nullvoxpopuli avatar

Stargazers

 avatar

Watchers

Clayton Parker avatar Dustin Sapp avatar Josh Kramer avatar James Cloos avatar

metahash's Issues

Don't set the field to have nested empty hashes unless explicitly told to do so.

Desired behavior:

metadata = Metadata.new
metadata.data.should be_nil
metadata.data.nested_data.should be_nil
metadata.should == {}
metadata.data = {}
metadata.should == {data: {}}

Current Behavior:

metadata = Metadata.new
metadata.data == {}
metadata.data.nested_data == {}
metadata == {data: {nested_data: {}}

this is a problem if one of the nested keys we call is eventually supposed to be a non Hash

example:

metadata = Metadata.new
id = metadata.property.id
klass.find(id)

=> errors cause id is a hash, rather than an id or nil

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.