hash_map 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -0
- data/lib/hash_map/base.rb +5 -4
- data/lib/hash_map/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c57bc95e7052c0c47f51335a0ba7b4d155234666
|
4
|
+
data.tar.gz: 6bfb54eb1d57266248d651a42bb55a495195c287
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3bb511c4e06c8ce12fc1420238006d0e36a16971bab43cf249b887252a8963e6a300f3b93bfd85e34dc83528c8064ec4ddd95a318ee045efd9b442e250d68640
|
7
|
+
data.tar.gz: 84296666688feac7b1227b8aa9e9ba0ea97d11f53f4caedc4ce1d5fbf18d4b3d09fe09a435ca0dff0a36a407e05a5cb67917ef0aa3a9d6b274276e4adce5ae0c
|
data/README.md
CHANGED
@@ -144,6 +144,22 @@ Collections.map({ numbers: '1'})
|
|
144
144
|
numbers: [1]
|
145
145
|
}
|
146
146
|
```
|
147
|
+
**Options**
|
148
|
+
Adding a second argument will make it available with the name `options`
|
149
|
+
|
150
|
+
```ruby
|
151
|
+
class UserMapper < HashMap::Base
|
152
|
+
properties :name, :lastname
|
153
|
+
property :company_name do
|
154
|
+
options[:company_name]
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
user = {name: :name, lastname: :lastname}
|
159
|
+
|
160
|
+
UserMapper.map(user, company_name: :foo)
|
161
|
+
#=> {"name"=>:name, "lastname"=>:lastname, "company_name"=>:foo}
|
162
|
+
```
|
147
163
|
|
148
164
|
**Inheritance**
|
149
165
|
When inheriting from a Mapper child will inherit the properties
|
data/lib/hash_map/base.rb
CHANGED
@@ -2,8 +2,8 @@ module HashMap
|
|
2
2
|
class Base
|
3
3
|
delegate :[], to: :output
|
4
4
|
|
5
|
-
def self.map(
|
6
|
-
new(
|
5
|
+
def self.map(*args)
|
6
|
+
new(*args).output
|
7
7
|
end
|
8
8
|
singleton_class.send(:alias_method, :call, :map)
|
9
9
|
|
@@ -15,9 +15,10 @@ module HashMap
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
attr_reader :original
|
19
|
-
def initialize(original)
|
18
|
+
attr_reader :original, :options
|
19
|
+
def initialize(original, options = {})
|
20
20
|
@original = _transforms_input(prepare_input(original))
|
21
|
+
@options = options
|
21
22
|
end
|
22
23
|
|
23
24
|
def mapper
|
data/lib/hash_map/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hash_map
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Artur Pañach
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
117
|
version: '0'
|
118
118
|
requirements: []
|
119
119
|
rubyforge_project:
|
120
|
-
rubygems_version: 2.
|
120
|
+
rubygems_version: 2.4.5
|
121
121
|
signing_key:
|
122
122
|
specification_version: 4
|
123
123
|
summary: Library to map easily hashes.
|