Project

omg-attrs

0.0
There's a lot of open issues
- Adds `Object#attrs` method for querying nested attributes - Adds `Array#where` to return a subset of elements matching a condition - Adds `Array#find_by` to return the first element matching a condition - Adds `Object#matches?` to check if an object matches a condition - Adds `Hash#method_missing` to allow {a: 1}.a instead of {a: 1}[:a]
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies
 Project Readme
  • Installation
    • From RubyGems.org
      • Globally
      • In Gemfile
    • Locally
  • Usage
  • Development
    • Installation
    • Console
    • Test

Installation

From RubyGems.org

Globally

gem i omg-attrs

In Gemfile

gem 'omg-attrs'

Locally

# Build gem
gem build omg-attrs.gemspec

# Install gem
gem i -l /path/to/this/folder/omg-attrs-<version>.gem

Usage

require 'omg-attrs'

dad_hash = {
  age: 35,
  hair_color: 'brown',
  children: [
    { age: 7, hair_color: 'blonde' },
    { age: 3, hair_color: 'brown' }
  ],
  wife: { age: 35, hair_color: 'brown' }
}

dad_hash.attrs(:age)
=> { age: 35 }

dad_hash.attrs(wife: :age, children: [:count, :age])
=> {
  wife: {
    age: 35
  },
  children: {
    count: 2,
    items: [
      { age: 7 },
      { age: 3 },
    ],
  },
}

dad_hash.matches?(age: 35) # => true

dad_hash.children.find_by(age: 7) # => { age: 7, hair_color: 'blonde' }

Development

Installation

bin/install

Console

bin/console

Test

rspec
# or
bundle exec rspec
# or
guard