array_to_proc 0.0.1
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 +7 -0
- data/.gitignore +18 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +39 -0
- data/Rakefile +1 -0
- data/array_to_proc.gemspec +24 -0
- data/lib/array/to_proc.rb +15 -0
- data/lib/array/to_proc/version.rb +3 -0
- data/spec/array/to_proc_spec.rb +17 -0
- data/spec/spec_helper.rb +8 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f6ccfb0515ed6710c51fafb3d8566feb96e900ba
|
4
|
+
data.tar.gz: 6f97740c2cc00a7cf4fe94e2b6dd4e73806f7051
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ded6697a1daddda73ae9b9fd7dbd5aa4339db6136501fc8cb2695067955d9b29aba3fb822388302fab3d8256b99d7c8e913d5e7bd709122527460daf965bfc09
|
7
|
+
data.tar.gz: 9e526b04426eb575c91a3c9c1e47b1a1308ed90751540e48886243551e4854059380b01ff123c5be583dae6ab0fc383416de6626f591f06d934ba9fc951df2f9
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Daniel Vartanov
|
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,39 @@
|
|
1
|
+
# Array#to_proc
|
2
|
+
|
3
|
+
Technically this gem adds `#to_proc` method to `Array`, which works similarly to [Symbol#to_proc](http://www.ruby-doc.org/core-2.1.0/Symbol.html#method-i-to_proc), but calls provided methods in sequence.
|
4
|
+
|
5
|
+
Effectively it allows one to pass an array of sequentially called method symbols as a block, like this:
|
6
|
+
|
7
|
+
users.map &[:created_at, :utc]
|
8
|
+
|
9
|
+
instead of
|
10
|
+
|
11
|
+
users.map(&:created_at).map(&:utc)
|
12
|
+
|
13
|
+
or
|
14
|
+
|
15
|
+
users.map { |user| user.created_at.utc }
|
16
|
+
|
17
|
+
|
18
|
+
## Installation
|
19
|
+
|
20
|
+
Add this line to your application's Gemfile:
|
21
|
+
|
22
|
+
gem 'array_to_proc', require: 'array/to_proc'
|
23
|
+
|
24
|
+
And then execute:
|
25
|
+
|
26
|
+
$ bundle
|
27
|
+
|
28
|
+
Or install it yourself as:
|
29
|
+
|
30
|
+
$ gem install array_to_proc
|
31
|
+
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
1. Fork it
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'array/to_proc/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "array_to_proc"
|
8
|
+
spec.version = ArrayToProc::VERSION
|
9
|
+
spec.authors = ["Daniel Vartanov"]
|
10
|
+
spec.email = ["dan@vartanov.net"]
|
11
|
+
spec.summary = %q{`users.map &[:created_at, :utc]` instead of `users.map(&:created_at).map(&:utc)` or `users.map { |user| user.created_at.utc }`}
|
12
|
+
spec.description = %q{This gem adds `#to_proc` method to Array, which works similarly to Symbol#to_proc, but calls provided methods in sequence.}
|
13
|
+
spec.homepage = "https://github.com/DanielVartanov/array_to_proc"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.0.beta"
|
24
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "array/to_proc/version"
|
2
|
+
|
3
|
+
module Array::ToProc
|
4
|
+
def to_proc
|
5
|
+
Proc.new do |object|
|
6
|
+
self.inject(object) do |chain_element, method_name|
|
7
|
+
chain_element.__send__ method_name
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
Array.class_eval do
|
14
|
+
include Array::ToProc
|
15
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Array, '#to_proc' do
|
4
|
+
let(:expected_values) { [rand, rand, rand, rand] }
|
5
|
+
|
6
|
+
let(:users) do
|
7
|
+
expected_values.map do |value|
|
8
|
+
double.tap do |user|
|
9
|
+
allow(user).to receive_message_chain(:created_at, :utc).and_return(value)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'runs methods sequentially, in an order of array' do
|
15
|
+
expect(users.map(&[:created_at, :utc])).to eq expected_values
|
16
|
+
end
|
17
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: array_to_proc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel Vartanov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.0.beta
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.0.beta
|
55
|
+
description: This gem adds `#to_proc` method to Array, which works similarly to Symbol#to_proc,
|
56
|
+
but calls provided methods in sequence.
|
57
|
+
email:
|
58
|
+
- dan@vartanov.net
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- array_to_proc.gemspec
|
69
|
+
- lib/array/to_proc.rb
|
70
|
+
- lib/array/to_proc/version.rb
|
71
|
+
- spec/array/to_proc_spec.rb
|
72
|
+
- spec/spec_helper.rb
|
73
|
+
homepage: https://github.com/DanielVartanov/array_to_proc
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.2.1
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: '`users.map &[:created_at, :utc]` instead of `users.map(&:created_at).map(&:utc)`
|
97
|
+
or `users.map { |user| user.created_at.utc }`'
|
98
|
+
test_files:
|
99
|
+
- spec/array/to_proc_spec.rb
|
100
|
+
- spec/spec_helper.rb
|