to_collection 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/LICENSE +0 -2
- data/README.md +18 -17
- data/VERSION +1 -0
- data/lib/to_collection.rb +31 -1
- data/to_collection.gemspec +48 -0
- metadata +10 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f47b3f3b4c1dac9e8a35181d9286a03ff0fc246179ec73eb842378f6e2b9da2
|
4
|
+
data.tar.gz: 6521e3dd2db1ca1ae61719842ac225253bbb54dc38b958765c759129d6495cb8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69bc9ff83efa0d7eafa084d3680020a0f8531e0856c80d4de524b40553812de76f82261609616b27cfb4f42653086e9b5145c148d0b3de056ef632cf04f20862
|
7
|
+
data.tar.gz: abb6bcf672a80e01768ef20da26e5485258042d814cab8eef0784a382b494f23d6e43cc021171d1ee014c144df044c7b522d350b15670b3b14bedbc57288db69
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
### v2.0.1
|
2
|
+
|
3
|
+
- Opal support via monkey-patching
|
4
|
+
|
5
|
+
### v2.0.0
|
6
|
+
|
7
|
+
- Revamped API using Ruby Refinements (safer than monkey-patching)
|
8
|
+
- Removed `super_module` gem dependency
|
9
|
+
- Dropped safety options since Ruby Refinements already handle things safely
|
10
|
+
|
11
|
+
### v1.0.1
|
12
|
+
|
13
|
+
- Updated `super_module` gem version to relax indirect `method_source` gem version dependency
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# ToCollection 2.0.
|
1
|
+
# ToCollection 2.0.1 Ruby Refinement
|
2
2
|
[![Gem Version](https://badge.fury.io/rb/to_collection.svg)](http://badge.fury.io/rb/to_collection)
|
3
3
|
[![Build Status](https://travis-ci.org/AndyObtiva/to_collection.svg?branch=master)](https://travis-ci.org/AndyObtiva/to_collection)
|
4
4
|
[![Coverage Status](https://coveralls.io/repos/github/AndyObtiva/to_collection/badge.svg?branch=master)](https://coveralls.io/github/AndyObtiva/to_collection?branch=master)
|
@@ -9,6 +9,8 @@ Especially useful in processing REST Web Service API JSON responses in a uniform
|
|
9
9
|
|
10
10
|
`ToCollection` is a Ruby Refinement, so it may be safely enabled via `using ToCollection` where needed only.
|
11
11
|
|
12
|
+
Now also supports [Opal Ruby](https://opalrb.com) by degrading gracefully to monkey-patching.
|
13
|
+
|
12
14
|
## Introduction
|
13
15
|
|
14
16
|
Canonicalize data to treat uniformly whether it comes in as a single object or an array of objects, dropping `nils` out automatically.
|
@@ -44,20 +46,26 @@ end
|
|
44
46
|
|
45
47
|
### Bundler
|
46
48
|
|
47
|
-
- Add `gem 'to_collection', '~> 2.0.
|
49
|
+
- Add `gem 'to_collection', '~> 2.0.1'` to Gemfile
|
48
50
|
- Run `bundle`
|
49
51
|
- Require `to_collection` ruby gem in code (e.g. via `Bundler.require(:default)` or `require 'bundler/setup'` & `require 'to_collection'`)
|
50
52
|
- Add `using ToCollection` to the top of the Ruby file you would like to refine `Object` in with `#to_collection` method.
|
51
53
|
|
52
54
|
### Manual Gem Install
|
53
55
|
|
54
|
-
- Run `gem install to_collection -v2.0.
|
56
|
+
- Run `gem install to_collection -v2.0.1`
|
55
57
|
- Add `require 'to_collection'` to code
|
56
58
|
- Add `using ToCollection` to the top of the Ruby file you would like to refine `Object` in with `#to_collection` method.
|
57
59
|
|
60
|
+
### Opal Ruby
|
61
|
+
|
62
|
+
- Follow the first step in [Bundler](#bundler) or [Manual Gem Install](#manual-gem-install) instructions to add the gem.
|
63
|
+
- Add Opal.use_gem 'to_collection' to "config/initializers/assets.rb" in Rails unless using as part of another gem.
|
64
|
+
- Add `require 'to_collection'` to code (this adds the functionality via monkey-patching not refinements in [Opal](https://opalrb.com))
|
65
|
+
|
58
66
|
### Note
|
59
67
|
|
60
|
-
If '#to_collection' was already defined on `Object` in a project, requiring the `to_collection` library will print a warning.
|
68
|
+
If '#to_collection' was already defined on `Object` in a project, requiring the `to_collection` library will print a warning.
|
61
69
|
|
62
70
|
It is still safe to require as it does not overwrite `Object#to_collection` except in Ruby files where `using ToCollection` is added.
|
63
71
|
|
@@ -261,20 +269,12 @@ You asked for "Elegant" didn't you? I hope that was what you were looking for.
|
|
261
269
|
|
262
270
|
## How It Works
|
263
271
|
|
264
|
-
A Ruby Refinement is activated via `using ToCollection` adding/overwriting the `#to_collection` method in `Object`, which
|
272
|
+
A Ruby Refinement is activated via `using ToCollection` adding/overwriting the `#to_collection` method in `Object`, which
|
265
273
|
is the ancestor of all Ruby objects.
|
266
274
|
|
267
|
-
##
|
268
|
-
|
269
|
-
### v2.0.0
|
275
|
+
## Change Log
|
270
276
|
|
271
|
-
|
272
|
-
- Removed `super_module` gem dependency
|
273
|
-
- Dropped safety options since Ruby Refinements already handle things safely
|
274
|
-
|
275
|
-
### v1.0.1
|
276
|
-
|
277
|
-
- Updated `super_module` gem version to relax indirect `method_source` gem version dependency
|
277
|
+
[CHANGELOG.md](CHANGELOG.md)
|
278
278
|
|
279
279
|
## Contributing
|
280
280
|
|
@@ -290,5 +290,6 @@ is the ancestor of all Ruby objects.
|
|
290
290
|
|
291
291
|
## Copyright
|
292
292
|
|
293
|
-
|
294
|
-
|
293
|
+
[MIT](LICENSE.txt)
|
294
|
+
|
295
|
+
Copyright (c) 2017-2020 Andy Maleh.
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0.1
|
data/lib/to_collection.rb
CHANGED
@@ -1,6 +1,29 @@
|
|
1
|
-
#
|
1
|
+
# Copyright (c) 2017-2020 Andy Maleh
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in all
|
11
|
+
# copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
# SOFTWARE.
|
2
20
|
|
3
21
|
module ToCollection
|
22
|
+
if RUBY_PLATFORM == 'opal'
|
23
|
+
def self.refine(class_or_module, &refinement)
|
24
|
+
class_or_module.class_eval(&refinement)
|
25
|
+
end
|
26
|
+
end
|
4
27
|
refine Object do
|
5
28
|
begin
|
6
29
|
method(:to_collection)
|
@@ -15,3 +38,10 @@ module ToCollection
|
|
15
38
|
end
|
16
39
|
end
|
17
40
|
end
|
41
|
+
|
42
|
+
if RUBY_PLATFORM == 'opal'
|
43
|
+
# Create a shim `using` method that does nothing since we monkey-patch in Opal earlier in the `refine` method
|
44
|
+
def self.using(refinement)
|
45
|
+
# NO OP
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: to_collection 2.0.1 ruby lib
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "to_collection".freeze
|
9
|
+
s.version = "2.0.1"
|
10
|
+
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib".freeze]
|
13
|
+
s.authors = ["Andy Maleh".freeze]
|
14
|
+
s.date = "2020-12-09"
|
15
|
+
s.description = "ToCollection Ruby Refinement - Treat an array of objects and a singular object uniformly as a collection of objects".freeze
|
16
|
+
s.email = "andy.am@gmail.com".freeze
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"CHANGELOG.md",
|
19
|
+
"LICENSE",
|
20
|
+
"README.md"
|
21
|
+
]
|
22
|
+
s.files = [
|
23
|
+
"CHANGELOG.md",
|
24
|
+
"README.md",
|
25
|
+
"VERSION",
|
26
|
+
"lib/to_collection.rb",
|
27
|
+
"to_collection.gemspec"
|
28
|
+
]
|
29
|
+
s.homepage = "http://github.com/AndyObtiva/to_collection".freeze
|
30
|
+
s.licenses = ["MIT".freeze]
|
31
|
+
s.rubygems_version = "3.1.4".freeze
|
32
|
+
s.summary = "ToCollection Ruby Refinement - Treat an array of objects and a singular object uniformly as a collection of objects".freeze
|
33
|
+
|
34
|
+
if s.respond_to? :specification_version then
|
35
|
+
s.specification_version = 4
|
36
|
+
end
|
37
|
+
|
38
|
+
if s.respond_to? :add_runtime_dependency then
|
39
|
+
s.add_development_dependency(%q<jeweler>.freeze, ["~> 2.3.3"])
|
40
|
+
s.add_development_dependency(%q<coveralls>.freeze, ["~> 0.8.19"])
|
41
|
+
s.add_development_dependency(%q<rspec>.freeze, ["~> 3.5.0"])
|
42
|
+
else
|
43
|
+
s.add_dependency(%q<jeweler>.freeze, ["~> 2.3.3"])
|
44
|
+
s.add_dependency(%q<coveralls>.freeze, ["~> 0.8.19"])
|
45
|
+
s.add_dependency(%q<rspec>.freeze, ["~> 3.5.0"])
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: to_collection
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Maleh
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jeweler
|
@@ -58,17 +58,21 @@ email: andy.am@gmail.com
|
|
58
58
|
executables: []
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files:
|
61
|
+
- CHANGELOG.md
|
61
62
|
- LICENSE
|
62
63
|
- README.md
|
63
64
|
files:
|
65
|
+
- CHANGELOG.md
|
64
66
|
- LICENSE
|
65
67
|
- README.md
|
68
|
+
- VERSION
|
66
69
|
- lib/to_collection.rb
|
70
|
+
- to_collection.gemspec
|
67
71
|
homepage: http://github.com/AndyObtiva/to_collection
|
68
72
|
licenses:
|
69
73
|
- MIT
|
70
74
|
metadata: {}
|
71
|
-
post_install_message:
|
75
|
+
post_install_message:
|
72
76
|
rdoc_options: []
|
73
77
|
require_paths:
|
74
78
|
- lib
|
@@ -83,8 +87,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
87
|
- !ruby/object:Gem::Version
|
84
88
|
version: '0'
|
85
89
|
requirements: []
|
86
|
-
rubygems_version: 3.1.
|
87
|
-
signing_key:
|
90
|
+
rubygems_version: 3.1.4
|
91
|
+
signing_key:
|
88
92
|
specification_version: 4
|
89
93
|
summary: ToCollection Ruby Refinement - Treat an array of objects and a singular object
|
90
94
|
uniformly as a collection of objects
|