omg-attrs 0.1.6 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ext/array.rb +2 -2
- data/lib/ext/hash.rb +3 -3
- data/lib/ext/object.rb +1 -1
- data/lib/omg-attrs.rb +2 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c90ddc4a5b434973f0022023cd4b3a2376001809b3b4f11767d3273850d3fa0
|
4
|
+
data.tar.gz: 8628c81c89ba6f5b9039ac9a06e4b1df1d5895f3eb29f13c60e42218c7673273
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9df6d5c9410005f4e2bb7b30cdcbc2f4fef6ab1c3a35f868edf93d35bbe6c7dd49997d30c36c2c2d065b3e8c9bcdd5a13de63b44d35ea3d27a9700b307f2e7cb
|
7
|
+
data.tar.gz: 75f3679a4bde73b52b41ab327808c3e0f544d0189de5a816ed1ece3c24b07d48834b3c8bcc0041d959c5ed047dbf399f7a3a90da29125e9433fb49ff83733d21
|
data/lib/ext/array.rb
CHANGED
@@ -8,13 +8,13 @@ module Ext
|
|
8
8
|
# @example
|
9
9
|
# [{ a: 1 }, { b: 2 }].find_by(a: 1) => { a: 1 }
|
10
10
|
def find_by(**attrs)
|
11
|
-
find { |item| item.
|
11
|
+
find { |item| item.matches?(**attrs) }
|
12
12
|
end
|
13
13
|
|
14
14
|
##
|
15
15
|
# @return [Array<Object>] all items that match all key/value pairs
|
16
16
|
def where(**attrs)
|
17
|
-
filter { |item| item.
|
17
|
+
filter { |item| item.matches?(**attrs) }
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
data/lib/ext/hash.rb
CHANGED
@@ -7,19 +7,19 @@ module Ext
|
|
7
7
|
self.class.define_method(method_name) do
|
8
8
|
self[method_name.to_s]
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
send(method_name)
|
12
12
|
elsif key?(method_name.to_sym)
|
13
13
|
self.class.define_method(method_name) do
|
14
14
|
self[method_name.to_sym]
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
send(method_name)
|
18
18
|
else
|
19
19
|
super
|
20
20
|
end
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def respond_to_missing?(method_name, *args, &block)
|
24
24
|
key?(method_name.to_s) || key?(method_name.to_sym) || super
|
25
25
|
end
|
data/lib/ext/object.rb
CHANGED
data/lib/omg-attrs.rb
CHANGED
@@ -12,7 +12,7 @@ module Attrs
|
|
12
12
|
module InstanceMethods
|
13
13
|
def attrs(*attrs)
|
14
14
|
return list_attrs(attrs) if is_list?
|
15
|
-
|
15
|
+
|
16
16
|
base_attrs, nested_attrs = attrs.partition { |attr| attr.is_a?(Symbol) }
|
17
17
|
nested_attrs.map! do |attr|
|
18
18
|
if attr.is_a?(Hash)
|
@@ -25,7 +25,7 @@ module Attrs
|
|
25
25
|
raise ArgumentError, "Invalid attribute: #{attr}"
|
26
26
|
end
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
base_attrs = base_attrs.to_h do |attr|
|
30
30
|
[attr, get(attr)]
|
31
31
|
end
|
metadata
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omg-attrs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Greenfield
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
- Adds `Object#attrs` method for querying nested attributes
|
15
15
|
- Adds `Array#where` to return a subset of elements matching a condition
|
16
16
|
- Adds `Array#find_by` to return the first element matching a condition
|
17
|
-
- Adds `Object#
|
17
|
+
- Adds `Object#matches?` to check if an object matches a condition
|
18
18
|
- Adds `Hash#method_missing` to allow {a: 1}.a instead of {a: 1}[:a]
|
19
19
|
email:
|
20
20
|
- mattgreenfield1@gmail.com
|
@@ -47,7 +47,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
47
47
|
- !ruby/object:Gem::Version
|
48
48
|
version: '0'
|
49
49
|
requirements: []
|
50
|
-
rubygems_version: 3.5.
|
50
|
+
rubygems_version: 3.5.23
|
51
51
|
signing_key:
|
52
52
|
specification_version: 4
|
53
53
|
summary: Gives objects methods to query nested attributes
|