https://github.com/omgreenfield/omg-attrs
A simple Ruby object/attribute querying tool, kind of like jq.
https://github.com/omgreenfield/omg-attrs
rails ruby
Last synced: 2 months ago
JSON representation
A simple Ruby object/attribute querying tool, kind of like jq.
- Host: GitHub
- URL: https://github.com/omgreenfield/omg-attrs
- Owner: omgreenfield
- Created: 2024-05-21T20:56:23.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2026-02-04T01:27:54.000Z (5 months ago)
- Last Synced: 2026-02-04T13:34:11.633Z (5 months ago)
- Topics: rails, ruby
- Language: Ruby
- Homepage: https://rubygems.org/gems/omg-attrs
- Size: 43 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
- [Installation](#installation)
- [From RubyGems.org](#from-rubygemsorg)
- [Globally](#globally)
- [In `Gemfile`](#in-gemfile)
- [Locally](#locally)
- [Usage](#usage)
- [Development](#development)
- [Installation](#installation-1)
- [Console](#console)
- [Test](#test)
## Installation
### From RubyGems.org
#### Globally
```sh
gem i omg-attrs
```
#### In `Gemfile`
```ruby
gem 'omg-attrs'
```
### Locally
```sh
# Build gem
gem build omg-attrs.gemspec
# Install gem
gem i -l /path/to/this/folder/omg-attrs-.gem
```
Or in a `Gemfile`
```ruby
gem 'omg-attrs', path: '/path/to/this/folder'
```
## Usage
```ruby
require 'omg-attrs'
dad_hash = {
age: 36,
hair_color: 'brown',
children: [
{ age: 4, hair_color: 'blonde' },
{ age: 8, hair_color: 'brown' }
],
wife: { age: 37, hair_color: 'brown' }
}
dad_hash.attrs(:age) # => { age: 36 }
dad_hash.attrs(wife: :age, children: [:count, :age])
=> {
wife: {
age: 36
},
children: {
count: 2,
items: [
{ age: 8 },
{ age: 4 },
],
},
}
dad_hash.attrs_match?(age: 36, hair_color: 'brown') # => true
dad_hash.children.find_by(age: 4) # => { age: 4, hair_color: 'brown' }
dad_hash.children.where(hair_color: 'brown') # => [{ age: 4, hair_color: 'brown' }]
```
## Development
### Installation
```sh
bin/install
```
### Console
```sh
bin/console
```
### Test
```sh
rspec
# or
bundle exec rspec
# or
guard
```