coercible-hash_to_array 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +63 -0
- data/Rakefile +1 -0
- data/coercible-hash_to_array.gemspec +25 -0
- data/lib/coercible/hash_to_array.rb +10 -0
- data/lib/coercible/hash_to_array/railtie.rb +9 -0
- data/lib/coercible/hash_to_array/version.rb +5 -0
- metadata +69 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e9ef3a44c83f6b819d4613477f29ba6fc4973e4b
|
4
|
+
data.tar.gz: 9a229b3b2600b76e313898cdbb752da4912d17c5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5404518a24ff4ebdbc708d96ca2f43819e33286b43ac85f29f04d80d084b14550309813e948fa98a9b4be31d9996058a67f8089ba51cf663a7f14a9778f56d52
|
7
|
+
data.tar.gz: 3c84cce98a7fbea69f988d394aec11ae2d12607ef83484db524ce8953f2ea62e46e0db75076933a974ccf0de23ff5cbb7e270403313efc7cf6cf2916be904d91
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Krzysztof Buszewicz
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# Coercible::HashToArray
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'coercible-hash_to_array'
|
9
|
+
```
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
## Description
|
16
|
+
|
17
|
+
Use this gem if you're using Virtus (https://github.com/solnic/virtus) and
|
18
|
+
want to be able to enforce collection attribute passing hash to initializer.
|
19
|
+
|
20
|
+
## Examples:
|
21
|
+
|
22
|
+
Let's assume, that you have 2 classes in your system:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
class Something
|
26
|
+
include Virtus.model
|
27
|
+
attribute :feature, String
|
28
|
+
end
|
29
|
+
|
30
|
+
class SomethingElse
|
31
|
+
include Virtus.model
|
32
|
+
|
33
|
+
attribute :strings, [String]
|
34
|
+
attribute :hashes, [Hash]
|
35
|
+
attribute :somethings, [Something]
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
### a) Without `coercible-hash_to_array` gem
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
# > SomethingElse.new(strings: "abc")
|
43
|
+
# => #<SomethingElse:0x007fd64b5e1e50 @strings=["abc"], @hashes=[], @somethings=[]>
|
44
|
+
|
45
|
+
# > SomethingElse.new(hashes: {key: 'value', key2: 'another value' })
|
46
|
+
# => #<SomethingElse:0x007fd649f263a0 @strings=[], @hashes=[{:key=>nil, "value"=>nil}, {:key2=>nil, "another value"=>nil}], @somethings=[]>
|
47
|
+
|
48
|
+
# > SomethingElse.new(somethings: { feature: 'wings' })
|
49
|
+
# => NoMethodError: Expected [:feature, "wings"] to respond to #to_hash
|
50
|
+
```
|
51
|
+
|
52
|
+
### b) With `coercible-hash_to_array` gem
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
# > SomethingElse.new(strings: "abc")
|
56
|
+
# => #<SomethingElse:0x007fd64b5e1e50 @strings=["abc"], @hashes=[], @somethings=[]>
|
57
|
+
|
58
|
+
# > SomethingElse.new(hashes: {key: 'value', key2: 'another value' })
|
59
|
+
# => #<SomethingElse:0x007fd650a3d800 @strings=[], @hashes=[{:key=>"value", :key2=>"another value"}], @somethings=[]>
|
60
|
+
|
61
|
+
# > SomethingElse.new(somethings: { feature: 'wings' })
|
62
|
+
# => #<SomethingElse:0x007fd650a2edc8 @strings=[], @hashes=[], @somethings=[#<Something:0x007fd650a2ecd8 @feature="wings">]>
|
63
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'coercible/hash_to_array/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = 'coercible-hash_to_array'
|
8
|
+
s.version = Coercible::HashToArray::VERSION
|
9
|
+
s.authors = ['Krzysztof Buszewicz']
|
10
|
+
s.email = ['kbuszewicz@grupainteger.pl']
|
11
|
+
s.summary = 'Custom Coercible::Coercer::Hash to_array method'
|
12
|
+
s.description = 'Use this gem if you\'re using Virtus' \
|
13
|
+
' (https://github.com/solnic/virtus)' \
|
14
|
+
' and want to be able to enforce collection attribute' \
|
15
|
+
' passing hash to initializer.'
|
16
|
+
s.homepage = 'https://github.com/Inittec/coercible-hash_to_array'
|
17
|
+
s.license = 'MIT'
|
18
|
+
|
19
|
+
s.files = `git ls-files -z`.split("\x0")
|
20
|
+
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
21
|
+
s.test_files = s.files.grep(%r{^(test|s|features)/})
|
22
|
+
s.require_paths = ['lib']
|
23
|
+
|
24
|
+
s.add_dependency 'railties', '>= 3.1'
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: coercible-hash_to_array
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Krzysztof Buszewicz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: railties
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.1'
|
27
|
+
description: Use this gem if you're using Virtus (https://github.com/solnic/virtus)
|
28
|
+
and want to be able to enforce collection attribute passing hash to initializer.
|
29
|
+
email:
|
30
|
+
- kbuszewicz@grupainteger.pl
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- ".gitignore"
|
36
|
+
- Gemfile
|
37
|
+
- LICENSE.txt
|
38
|
+
- README.md
|
39
|
+
- Rakefile
|
40
|
+
- coercible-hash_to_array.gemspec
|
41
|
+
- lib/coercible/hash_to_array.rb
|
42
|
+
- lib/coercible/hash_to_array/railtie.rb
|
43
|
+
- lib/coercible/hash_to_array/version.rb
|
44
|
+
homepage: https://github.com/Inittec/coercible-hash_to_array
|
45
|
+
licenses:
|
46
|
+
- MIT
|
47
|
+
metadata: {}
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
requirements: []
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 2.2.2
|
65
|
+
signing_key:
|
66
|
+
specification_version: 4
|
67
|
+
summary: Custom Coercible::Coercer::Hash to_array method
|
68
|
+
test_files: []
|
69
|
+
has_rdoc:
|