map_chain 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 33b4c88e2afa4c9aec50f9caf2f0554837e4b5f5
4
+ data.tar.gz: bc0c2baa13d563985a897d910662c938fcf2299e
5
+ SHA512:
6
+ metadata.gz: a3399315e40805ed411466dc5255f0f2fa5193d367952fa88c94d7ce0eea8a8d34d2e02bea4af0c1ec80b924972283ffa2ca7fbf73dcf90c0b306e446cae1844
7
+ data.tar.gz: f22d61901619836120703bfbfd09cbd3109265067c9accf7007aec1275961b937f538ace352e45e7865c2c70c72ca6ed14ec988d81bb88d380db83f8b161d17c
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2015 Koichi ITO
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
11
+ all 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
19
+ THE SOFTWARE.
@@ -0,0 +1,47 @@
1
+ # map_chain
2
+
3
+ ```ruby
4
+ %i(foo bar).map_chain('to_s.to_sym') #=> %i(foo bar).map(&:to_s).map(&:to_sym)
5
+ ```
6
+
7
+ ## CAUTION
8
+
9
+ If you use with ORM, ODM and so on, please be careful to N+1 query problem.
10
+
11
+ ## INSTALL
12
+
13
+ Add these lines to your application's Gemfile:
14
+
15
+ ```
16
+ gem 'map_chain'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ ```
22
+ $ bundle
23
+ ```
24
+
25
+ Or install it yourself as:
26
+
27
+ ```
28
+ $ gem install map_chain
29
+ ```
30
+
31
+ And require it as:
32
+
33
+ ```
34
+ require 'map_chain'
35
+ ```
36
+
37
+ ## Contributing
38
+
39
+ 1. Fork it
40
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
41
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
42
+ 4. Push to the branch (`git push origin my-new-feature`)
43
+ 5. Create new Pull Request
44
+
45
+ ## License
46
+
47
+ map_chain is released under the [MIT License](http://www.opensource.org/licenses/MIT).
@@ -0,0 +1 @@
1
+ require 'map_chain/core_ext/array'
@@ -0,0 +1,24 @@
1
+ class Array
2
+ def map_chain(method_names)
3
+ raise ArgumentError unless method_names.is_a? String
4
+
5
+ _map_chain(method_names)
6
+ end
7
+
8
+ alias collect_chain map_chain
9
+
10
+ private
11
+
12
+ def _map_chain(method_names)
13
+ case method_names
14
+ when String
15
+ _map_chain(method_names.split('.').map(&:strip))
16
+ when Array
17
+ method_names.inject(self) {|result, method_name|
18
+ result.map {|elem| elem.method(method_name).call }
19
+ }
20
+ else
21
+ raise ArgumentError
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,4 @@
1
+ module MapChain
2
+ VERSION = '0.0.1'
3
+ end
4
+
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: map_chain
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Koichi ITO
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-10-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.0.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.0.0
27
+ description: "%i(foo bar).map_chain('to_s.to_sym') #=> %i(foo bar).map(&:to_s).map(&:to_sym)"
28
+ email: koic.ito@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - LICENSE
34
+ - README.md
35
+ - lib/map_chain.rb
36
+ - lib/map_chain/core_ext/array.rb
37
+ - lib/map_chain/version.rb
38
+ homepage: http://github.com/koic/map_chain
39
+ licenses:
40
+ - MIT
41
+ metadata: {}
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 2.0.0
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubyforge_project:
58
+ rubygems_version: 2.5.0
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: "%i(foo bar).map_chain('to_s.to_sym') #=> %i(foo bar).map(&:to_s).map(&:to_sym)"
62
+ test_files: []