u-attributes 1.1.1 → 1.2.0
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/Gemfile.lock +1 -1
- data/README.md +16 -0
- data/lib/micro/attributes.rb +6 -2
- data/lib/micro/attributes/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97dfa238f3a4bbeea816dd6965e9261de6cff2af2c14a5934c9d2ffdee03b2a4
|
4
|
+
data.tar.gz: a21fb9c6247d7d8b6969c0f60539dfe9e5bec6fb502c945dea64ec8534a86265
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a99ea97d70785cfa6f90a3a638ca4fe68bffc2ee05d4b3d9f5a3b9b31de2c3076607f1c64753c1c3850df6150d105985a5336b2d66e0560dab77ceea35a12b28
|
7
|
+
data.tar.gz: daaee31a1f10ec4c74ffc59131196f040ce33eee787ea0381643737ade568615d1b52c78964a392f8e41a476de940d5b0a215102537514783273dd79da0329f1
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -11,6 +11,7 @@ This gem allows defining read-only attributes, that is, your objects will have o
|
|
11
11
|
## Table of contents
|
12
12
|
- [μ-attributes (Micro::Attributes)](#%ce%bc-attributes-microattributes)
|
13
13
|
- [Table of contents](#table-of-contents)
|
14
|
+
- [Required Ruby version](#required-ruby-version)
|
14
15
|
- [Installation](#installation)
|
15
16
|
- [Usage](#usage)
|
16
17
|
- [How to require?](#how-to-require)
|
@@ -29,6 +30,10 @@ This gem allows defining read-only attributes, that is, your objects will have o
|
|
29
30
|
- [License](#license)
|
30
31
|
- [Code of Conduct](#code-of-conduct)
|
31
32
|
|
33
|
+
## Required Ruby version
|
34
|
+
|
35
|
+
> \>= 2.2.0
|
36
|
+
|
32
37
|
## Installation
|
33
38
|
|
34
39
|
Add this line to your application's Gemfile:
|
@@ -320,6 +325,17 @@ puts person.attribute?(:foo) # false
|
|
320
325
|
|
321
326
|
p person.attributes # {"age"=>20, "name"=>"John Doe"}
|
322
327
|
p Person.new(name: 'John').attributes # {"age"=>nil, "name"=>"John"}
|
328
|
+
|
329
|
+
#---------------------#
|
330
|
+
# #attributes(*names) #
|
331
|
+
#---------------------#
|
332
|
+
|
333
|
+
# Slices the attributes to include only the given keys.
|
334
|
+
# Returns a hash containing the given keys (in their types).
|
335
|
+
|
336
|
+
p person.attributes(:age) # {age: 20}
|
337
|
+
p person.attributes(:age, :name) # {age: 20, name: "John Doe"}
|
338
|
+
p person.attributes('age', 'name') # {"age"=>20, "name"=>"John Doe"}
|
323
339
|
```
|
324
340
|
|
325
341
|
## Built-in extensions
|
data/lib/micro/attributes.rb
CHANGED
@@ -62,8 +62,12 @@ module Micro
|
|
62
62
|
__attributes[name] = instance_variable_set("@#{name}", value) if attribute?(name)
|
63
63
|
end
|
64
64
|
|
65
|
-
def attributes
|
66
|
-
__attributes
|
65
|
+
def attributes(*names)
|
66
|
+
return __attributes if names.empty?
|
67
|
+
|
68
|
+
names.each_with_object({}) do |name, memo|
|
69
|
+
memo[name] = attribute(name) if attribute?(name)
|
70
|
+
end
|
67
71
|
end
|
68
72
|
|
69
73
|
def attribute?(name)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: u-attributes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rodrigo Serradura
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-08-
|
11
|
+
date: 2019-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -75,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
75
|
- !ruby/object:Gem::Version
|
76
76
|
version: '0'
|
77
77
|
requirements: []
|
78
|
-
rubygems_version: 3.0.
|
78
|
+
rubygems_version: 3.0.3
|
79
79
|
signing_key:
|
80
80
|
specification_version: 4
|
81
81
|
summary: Define read-only attributes
|