omg-attrs 0.1.8 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/ext/array.rb +2 -2
- data/lib/ext/object.rb +1 -1
- data/lib/omg-attrs.rb +14 -1
- metadata +6 -7
- data/lib/ext/hash.rb +0 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e5822f78ef8d7ac5c1bba6b6ee912617f898ec5c11bd210616be22651f8fcc5
|
4
|
+
data.tar.gz: 804ee836c7c8466d75c012b336619e3e06600e3ea74ba056f0d5b759e1220b71
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 378b45c0446ba129bad73bb72e5746f3c2e03ce7d0067f82959feab9cabd8b328388439946d01476644446e0fcc288af039549afca77adc0b63affaeeee14af1
|
7
|
+
data.tar.gz: 8e12597d30f4173570134902111821ad8738d0bc7d984060549a5684c26ed953ae3d63b27381684fadb171222b638dca1ffd06f16f129939b844b2df6fdba175
|
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.attrs_match?(**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.attrs_match?(**attrs) }
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
data/lib/ext/object.rb
CHANGED
data/lib/omg-attrs.rb
CHANGED
@@ -2,13 +2,26 @@
|
|
2
2
|
|
3
3
|
require_relative 'ext/object'
|
4
4
|
require_relative 'ext/array'
|
5
|
-
require_relative 'ext/hash'
|
6
5
|
|
7
6
|
module Attrs
|
8
7
|
def self.included(base)
|
9
8
|
base.include(InstanceMethods)
|
10
9
|
end
|
11
10
|
|
11
|
+
class << self
|
12
|
+
def included(base)
|
13
|
+
base.include(InstanceMethods)
|
14
|
+
end
|
15
|
+
|
16
|
+
def version
|
17
|
+
config[:version]
|
18
|
+
end
|
19
|
+
|
20
|
+
def config
|
21
|
+
YAML.load_file(File.join(__dir__, '..', 'config.yml'))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
12
25
|
module InstanceMethods
|
13
26
|
def attrs(*attrs)
|
14
27
|
return list_attrs(attrs) if is_list?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Greenfield
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
- Adds `Object#attrs` method for querying nested attributes
|
@@ -23,7 +23,6 @@ extensions: []
|
|
23
23
|
extra_rdoc_files: []
|
24
24
|
files:
|
25
25
|
- lib/ext/array.rb
|
26
|
-
- lib/ext/hash.rb
|
27
26
|
- lib/ext/object.rb
|
28
27
|
- lib/omg-attrs.rb
|
29
28
|
homepage: https://github.com/omgreenfield/attrs
|
@@ -32,7 +31,7 @@ licenses:
|
|
32
31
|
metadata:
|
33
32
|
homepage_uri: https://github.com/omgreenfield/attrs
|
34
33
|
rubygems_mfa_required: 'true'
|
35
|
-
post_install_message:
|
34
|
+
post_install_message:
|
36
35
|
rdoc_options: []
|
37
36
|
require_paths:
|
38
37
|
- lib
|
@@ -47,8 +46,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
47
46
|
- !ruby/object:Gem::Version
|
48
47
|
version: '0'
|
49
48
|
requirements: []
|
50
|
-
rubygems_version: 3.
|
51
|
-
signing_key:
|
49
|
+
rubygems_version: 3.4.10
|
50
|
+
signing_key:
|
52
51
|
specification_version: 4
|
53
52
|
summary: Gives objects methods to query nested attributes
|
54
53
|
test_files: []
|
data/lib/ext/hash.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
require_relative 'object'
|
2
|
-
|
3
|
-
module Ext
|
4
|
-
module Hash
|
5
|
-
def method_missing(method_name, *args, &block)
|
6
|
-
if key?(method_name.to_s)
|
7
|
-
self.class.define_method(method_name) do
|
8
|
-
self[method_name.to_s]
|
9
|
-
end
|
10
|
-
|
11
|
-
send(method_name)
|
12
|
-
elsif key?(method_name.to_sym)
|
13
|
-
self.class.define_method(method_name) do
|
14
|
-
self[method_name.to_sym]
|
15
|
-
end
|
16
|
-
|
17
|
-
send(method_name)
|
18
|
-
else
|
19
|
-
super
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def respond_to_missing?(method_name, *args, &block)
|
24
|
-
key?(method_name.to_s) || key?(method_name.to_sym) || super
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
Hash.include Ext::Hash
|
30
|
-
Hash.include Ext::Object
|