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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 854cdfcbae1f568640947a0bbfdf5fa26493a1e47ebf29ce91d7d287f6388050
4
- data.tar.gz: df775cef424add3e18672d03b6522d5e625b6e211b6891078b7bfb31e2ba996a
3
+ metadata.gz: 97dfa238f3a4bbeea816dd6965e9261de6cff2af2c14a5934c9d2ffdee03b2a4
4
+ data.tar.gz: a21fb9c6247d7d8b6969c0f60539dfe9e5bec6fb502c945dea64ec8534a86265
5
5
  SHA512:
6
- metadata.gz: 6541f9295ae0cc88fec1fcc05d8307feb05769de3aadfb597710517aa76e80dacaef7fd2d165491319ef2b0e701c20ebd025459befa2e5c92f07da43f5df6f3b
7
- data.tar.gz: 04e200e16d8c6258e819baa9b3f0ef00c86fc1715d6a866c6dc05fcefde54ceb7fd4746fa050e4e7b50ae7360dcd4639a2397ffe837593107368e19bfcef0dad
6
+ metadata.gz: a99ea97d70785cfa6f90a3a638ca4fe68bffc2ee05d4b3d9f5a3b9b31de2c3076607f1c64753c1c3850df6150d105985a5336b2d66e0560dab77ceea35a12b28
7
+ data.tar.gz: daaee31a1f10ec4c74ffc59131196f040ce33eee787ea0381643737ade568615d1b52c78964a392f8e41a476de940d5b0a215102537514783273dd79da0329f1
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- u-attributes (1.1.1)
4
+ u-attributes (1.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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
@@ -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)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Micro
4
4
  module Attributes
5
- VERSION = '1.1.1'.freeze
5
+ VERSION = '1.2.0'.freeze
6
6
  end
7
7
  end
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.1.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-05 00:00:00.000000000 Z
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.1
78
+ rubygems_version: 3.0.3
79
79
  signing_key:
80
80
  specification_version: 4
81
81
  summary: Define read-only attributes